Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support of placing properties at root in af #3082

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/v0/destinations/af/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,15 @@ function getEventValueForUnIdentifiedTrackEvent(message) {
return { eventValue };
}

function getEventValueMapFromMappingJson(message, mappingJson, isMultiSupport) {
function getEventValueMapFromMappingJson(message, mappingJson, isMultiSupport, addPropertiesAtRoot) {
let eventValue = {};
set(eventValue, 'properties', message.properties);

if (addPropertiesAtRoot) {
eventValue = message.properties;
} else {
set(eventValue, 'properties', message.properties);
}

const sourceKeys = Object.keys(mappingJson);
sourceKeys.forEach((sourceKey) => {
set(eventValue, mappingJson[sourceKey], get(message, sourceKey));
Expand Down Expand Up @@ -160,7 +166,7 @@ function processNonTrackEvents(message, eventName) {
return payload;
}

function processEventTypeTrack(message) {
function processEventTypeTrack(message, addPropertiesAtRoot) {
let isMultiSupport = true;
const evType = message.event && message.event.toLowerCase();
let category = ConfigCategory.DEFAULT;
Expand All @@ -184,6 +190,7 @@ function processEventTypeTrack(message) {
message,
mappingConfig[category.name],
isMultiSupport,
addPropertiesAtRoot,
);
payload.eventName = message.event;
payload.eventCurrency = message?.properties?.currency;
Expand All @@ -196,7 +203,7 @@ function processSingleMessage(message, destination) {
let payload;
switch (messageType) {
case EventType.TRACK: {
payload = processEventTypeTrack(message);
payload = processEventTypeTrack(message, destination.Config.addPropertiesAtRoot);
break;
}
case EventType.SCREEN: {
Expand Down
305 changes: 305 additions & 0 deletions test/integrations/destinations/af/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const data = [
destination: {
Config: { devKey: 'ef1d42390426e3f7c90ac78272e74344', androidAppId: 'appId' },
Enabled: true,
addPropertiesAtRoot: false,
},
},
],
Expand Down Expand Up @@ -118,6 +119,7 @@ export const data = [
Config: {
devKey: 'ef1d42390426e3f7c90ac78272e74344',
androidAppId: 'com.rudderlabs.javascript',
addPropertiesAtRoot: false,
},
Enabled: true,
},
Expand Down Expand Up @@ -305,6 +307,7 @@ export const data = [
Config: {
devKey: 'ef1d42390426e3f7c90ac78272e74344',
androidAppId: 'com.rudderlabs.javascript',
addPropertiesAtRoot: false,
},
Enabled: true,
},
Expand Down Expand Up @@ -1532,4 +1535,306 @@ export const data = [
},
},
},
{
name: 'af',
description: 'Place Properties at root level Page Call',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
message: {
channel: 'web',
context: {
externalId: [{ type: 'appsflyerExternalId', id: 'afUid' }],
app: {
build: '1.0.0',
name: 'RudderLabs JavaScript SDK',
namespace: 'com.rudderlabs.javascript',
version: '1.0.0',
},
traits: {
email: '[email protected]',
name: 'Test Hubspot',
anonymousId: '12345',
},
library: { name: 'RudderLabs JavaScript SDK', version: '1.0.0' },
userAgent:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
locale: 'en-GB',
ip: '0.0.0.0',
os: { name: 'android', version: '' },
screen: { density: 2 },
},
type: 'page',
messageId: 'e8585d9a-7137-4223-b295-68ab1b17dad7',
originalTimestamp: '2019-10-15T09:35:31.289Z',
anonymousId: '00000000000000000000000000',
userId: '12345',
properties: { path: '', referrer: '', search: '', title: '', url: '' },
name: 'ApplicationLoaded',
sentAt: '2019-10-14T11:15:53.296Z',
integrations: { AF: { af_uid: 'afUid' } },
},
destination: {
Config: {
devKey: 'ef1d42390426e3f7c90ac78272e74344',
androidAppId: 'com.rudderlabs.javascript',
sharingFilter: 'all',
addPropertiesAtRoot: true,
},
Enabled: true,
},
},
],
method: 'POST',
},
},
output: {
response: {
status: 200,
body: [
{
output: {
version: '1',
type: 'REST',
endpoint: 'https://api2.appsflyer.com/inappevent/com.rudderlabs.javascript',
headers: {
'Content-Type': 'application/json',
authentication: 'ef1d42390426e3f7c90ac78272e74344',
},
method: 'POST',
params: {},
body: {
JSON: {
app_version_name: '1.0.0',
bundleIdentifier: 'com.rudderlabs.javascript',
customer_user_id: '12345',
eventValue: '{"path":"","referrer":"","search":"","title":"","url":""}',
eventName: 'page',
appsflyer_id: 'afUid',
os: '',
ip: '0.0.0.0',
sharing_filter: 'all',
},
XML: {},
JSON_ARRAY: {},
FORM: {},
},
files: {},
userId: '',
},
statusCode: 200,
},
],
},
},
},
{
name: 'af',
description: 'Place properties at root level track call',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
message: {
channel: 'web',
context: {
externalId: [{ type: 'appsflyerExternalId', id: 'afUid' }],
app: {
build: '1.0.0',
name: 'RudderLabs JavaScript SDK',
namespace: 'com.rudderlabs.javascript',
version: '1.0.0',
},
traits: { email: '[email protected]', name: 'Test Hubspot' },
library: { name: 'RudderLabs JavaScript SDK', version: '1.0.0' },
userAgent:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
locale: 'en-GB',
ip: '0.0.0.0',
os: { name: 'android', version: '' },
screen: { density: 2 },
},
type: 'track',
messageId: '08829772-d991-427c-b976-b4c4f4430b4e',
originalTimestamp: '2019-10-15T09:35:31.291Z',
anonymousId: '00000000000000000000000000',
userId: '12345',
event: 'test track event HS',
properties: { user_actual_role: 'system_admin, system_user', user_actual_id: 12345 },
sentAt: '2019-10-14T11:15:53.296Z',
integrations: { AF: { af_uid: 'afUid' } },
},
destination: {
Config: {
devKey: 'ef1d42390426e3f7c90ac78272e74344',
androidAppId: 'com.rudderlabs.javascript',
addPropertiesAtRoot: true,
},
Enabled: true,
},
},
],
method: 'POST',
},
},
output: {
response: {
status: 200,
body: [
{
output: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://api2.appsflyer.com/inappevent/com.rudderlabs.javascript',
headers: {
'Content-Type': 'application/json',
authentication: 'ef1d42390426e3f7c90ac78272e74344',
},
params: {},
body: {
JSON: {
eventValue:
'{"user_actual_role":"system_admin, system_user","user_actual_id":12345}',
eventName: 'test track event HS',
customer_user_id: '12345',
ip: '0.0.0.0',
os: '',
appsflyer_id: 'afUid',
app_version_name: '1.0.0',
bundleIdentifier: 'com.rudderlabs.javascript',
},
JSON_ARRAY: {},
XML: {},
FORM: {},
},
files: {},
userId: '',
},
statusCode: 200,
},
],
},
},
},
{
name: 'af',
description: 'Place properties at root track call with af data',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
message: {
type: 'track',
event: 'Order Completed',
sentAt: '2020-08-14T05:30:30.118Z',
context: {
externalId: [{ type: 'appsflyerExternalId', id: 'afUid' }],
source: 'test',
app: { namespace: 'com.rudderlabs.javascript' },
os: { name: 'android' },
traits: { anonymousId: '50be5c78-6c3f-4b60-be84-97805a316fb1' },
library: { name: 'rudder-sdk-ruby-sync', version: '1.0.6' },
},
messageId: '7208bbb6-2c4e-45bb-bf5b-ad426f3593e9',
timestamp: '2020-08-14T05:30:30.118Z',
properties: {
tax: 2,
total: 27.5,
coupon: 'hasbros',
revenue: 48,
price: 25,
quantity: 2,
currency: 'ZAR',
discount: 2.5,
order_id: '50314b8e9bcf000000000000',
products: [
{
sku: '45790-32',
url: 'https://www.example.com/product/path',
name: 'Monopoly: 3rd Edition',
price: 19,
category: 'Games',
quantity: 1,
image_url: 'https:///www.example.com/product/path.jpg',
product_id: '507f1f77bcf86cd799439011',
},
{
sku: '46493-32',
name: 'Uno Card Game',
price: 3,
category: 'Games',
quantity: 2,
product_id: '505bd76785ebb509fc183733',
},
],
shipping: 3,
subtotal: 22.5,
affiliation: 'Google Store',
checkout_id: 'fksdjfsdjfisjf9sdfjsd9f',
},
anonymousId: '50be5c78-6c3f-4b60-be84-97805a316fb1',
integrations: { AF: { af_uid: 'afUid' } },
},
destination: {
Config: {
devKey: 'abcde',
androidAppId: 'com.rudderlabs.javascript',
groupTypeTrait: 'email',
groupValueTrait: 'age',
trackProductsOnce: false,
trackRevenuePerProduct: false,
addPropertiesAtRoot: true,
},
},
},
],
method: 'POST',
},
},
output: {
response: {
status: 200,
body: [
{
output: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://api2.appsflyer.com/inappevent/com.rudderlabs.javascript',
headers: { 'Content-Type': 'application/json', authentication: 'abcde' },
params: {},
body: {
JSON: {
bundleIdentifier: 'com.rudderlabs.javascript',
eventValue:
'{"tax":2,"total":27.5,"coupon":"hasbros","revenue":48,"price":25,"quantity":2,"currency":"ZAR","discount":2.5,"order_id":"50314b8e9bcf000000000000","products":[{"sku":"45790-32","url":"https://www.example.com/product/path","name":"Monopoly: 3rd Edition","price":19,"category":"Games","quantity":1,"image_url":"https:///www.example.com/product/path.jpg","product_id":"507f1f77bcf86cd799439011"},{"sku":"46493-32","name":"Uno Card Game","price":3,"category":"Games","quantity":2,"product_id":"505bd76785ebb509fc183733"}],"shipping":3,"subtotal":22.5,"affiliation":"Google Store","checkout_id":"fksdjfsdjfisjf9sdfjsd9f","af_revenue":48,"af_price":[19,3],"af_quantity":[1,2],"af_order_id":"50314b8e9bcf000000000000","af_content_id":["507f1f77bcf86cd799439011","505bd76785ebb509fc183733"]}',
eventName: 'Order Completed',
eventCurrency: 'ZAR',
eventTime: '2020-08-14T05:30:30.118Z',
appsflyer_id: 'afUid',
},
XML: {},
JSON_ARRAY: {},
FORM: {},
},
files: {},
userId: '',
},
statusCode: 200,
},
],
},
},
},
];
Loading