Skip to content

Commit

Permalink
fix: reddit revenue mapping for floating point values (#3118)
Browse files Browse the repository at this point in the history
* fix: reddit revenue mapping for floating point values

* fix: reddit revenue mapping for floating point values
  • Loading branch information
koladilip authored Feb 23, 2024
1 parent 69e43b6 commit 41f4078
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/cdk/v2/destinations/reddit/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ steps:
- name: customFields
condition: $.outputs.prepareTrackPayload.eventType.tracking_type === "Purchase"
reference: "https://ads-api.reddit.com/docs/v2/#tag/Conversions/paths/~1api~1v2.0~1conversions~1events~1%7Baccount_id%7D/post"
template: |
const revenue_in_cents = .message.properties.revenue ? Math.round(Number(.message.properties.revenue)*100)
const customFields = .message.().({
"currency": .properties.currency,
"value_decimal": .properties.revenue !== undefined ? Number(.properties.revenue) : undefined,
"value_decimal": revenue_in_cents ? revenue_in_cents / 100,
"item_count": (Array.isArray(.properties.products) && .properties.products.length) || (.properties.itemCount && Number(.properties.itemCount)),
"value": .properties.revenue !== undefined ? Number(.properties.revenue)*100 : undefined,
"value": revenue_in_cents,
"conversion_id": .properties.conversionId || .messageId,
});
$.removeUndefinedAndNullValues(customFields)
Expand Down
167 changes: 167 additions & 0 deletions test/integrations/destinations/reddit/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,173 @@ export const data = [
},
},
},
{
name: 'reddit',
description: 'Track call with order completed event with floating point values for revenue',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
message: {
context: {
traits: {
email: '[email protected]',
},
userAgent:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
ip: '54.100.200.255',
device: {
advertisingId: 'asfds7fdsihf734b34j43f',
},
os: {
name: 'android',
},
},
type: 'track',
session_id: '16733896350494',
originalTimestamp: '2019-10-14T09:03:17.562Z',
anonymousId: '123456',
event: 'Order Completed',
userId: 'testuserId1',
properties: {
checkout_id: '12345',
order_id: '1234',
affiliation: 'Apple Store',
total: 20,
revenue: 14.985,
shipping: 4,
tax: 1,
discount: 1.5,
coupon: 'ImagePro',
currency: 'USD',
products: [
{
product_id: '123',
sku: 'G-32',
name: 'Monopoly',
price: 14,
quantity: 1,
category: 'Games',
url: 'https://www.website.com/product/path',
image_url: 'https://www.website.com/product/path.jpg',
},
{
product_id: '345',
sku: 'F-32',
name: 'UNO',
price: 3.45,
quantity: 2,
category: 'Games',
},
],
},
integrations: {
All: true,
},
sentAt: '2019-10-14T09:03:22.563Z',
},
destination: {
Config: {
accountId: 'a2_fsddXXXfsfd',
hashData: true,
eventsMapping: [
{
from: 'Order Completed',
to: 'Purchase',
},
],
},
DestinationDefinition: { Config: { cdkV2Enabled: true } },
},
metadata: {
destinationId: 'destId',
workspaceId: 'wspId',
secret: {
accessToken: 'dummyAccessToken',
},
},
},
],
},
},
output: {
response: {
status: 200,
body: [
{
output: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://ads-api.reddit.com/api/v2.0/conversions/events/a2_fsddXXXfsfd',
headers: {
Authorization: 'Bearer dummyAccessToken',
'Content-Type': 'application/json',
},
params: {},
body: {
JSON: {
events: [
{
event_at: '2019-10-14T09:03:17.562Z',
event_type: {
tracking_type: 'Purchase',
},
user: {
aaid: 'c12d34889302d3c656b5699fa9190b51c50d6f62fce57e13bd56b503d66c487a',
email: 'ac144532d9e4efeab19475d9253a879173ea12a3d2238d1cb8a332a7b3a105f2',
external_id:
'7b023241a3132b792a5a33915a5afb3133cbb1e13d72879689bf6504de3b036d',
ip_address:
'e80bd55a3834b7c2a34ade23c7ecb54d2a49838227080f50716151e765a619db',
user_agent:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
screen_dimensions: {},
},
event_metadata: {
item_count: 2,
currency: 'USD',
value: 1499,
value_decimal: 14.99,
products: [
{
id: '123',
name: 'Monopoly',
category: 'Games',
},
{
id: '345',
name: 'UNO',
category: 'Games',
},
],
},
},
],
},
JSON_ARRAY: {},
XML: {},
FORM: {},
},
files: {},
userId: '',
},
metadata: {
destinationId: 'destId',
workspaceId: 'wspId',
secret: {
accessToken: 'dummyAccessToken',
},
},
statusCode: 200,
},
],
},
},
},
{
name: 'reddit',
description: 'Track call with product list viewed event',
Expand Down

0 comments on commit 41f4078

Please sign in to comment.