Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:rudderlabs/rudder-transformer in…
Browse files Browse the repository at this point in the history
…to feat.emersys
  • Loading branch information
shrouti1507 committed Apr 30, 2024
2 parents 3522abf + 7b1d11b commit ed9e0cf
Show file tree
Hide file tree
Showing 12 changed files with 1,611 additions and 667 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const YANDEX_METRICA_OFFLINE_EVENTS = 'yandex_metrica_offline_events';

module.exports = {
YANDEX_METRICA_OFFLINE_EVENTS,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
bindings:
- name: EventType
path: ../../../../constants
- path: ../../bindings/jsontemplate
exportAll: true
- path: ./config
- name: removeUndefinedAndNullValues
path: ../../../../v0/util
- name: defaultRequestConfig
path: ../../../../v0/util
- path: ./utils

steps:
- name: validateInput
template: |
let messageType = .message.type;
$.assert(messageType, "message Type is not present. Aborting message.");
$.assert(.message.type.toLowerCase() ==='identify', "Event type " + .message.type.toLowerCase() + " is not supported. Aborting message.");
$.assert(.message.traits || .message.properties, "Message traits/properties not present. Aborting message.");
- name: prepareData
template: |
let data = .message.traits
let identifierType = .message.context.externalId[0].identifierType;
let identifierValue = .message.context.externalId[0].id;
identifierValue = String(identifierValue);
data = $.setIdentifier(data, identifierType, identifierValue)
data = $.validateData(data)
data
- name: buildResponseForProcessTransformation
description: build response
template: |
const response = $.defaultRequestConfig();
response.body.JSON = $.outputs.prepareData
response
51 changes: 51 additions & 0 deletions src/cdk/v2/destinations/yandex_metrica_offline_events/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* eslint-disable no-param-reassign */
const { InstrumentationError, isDefinedNotNullNotEmpty } = require('@rudderstack/integrations-lib');
const moment = require('moment');

const setIdentifier = (data, identifierType, identifierValue) => {
const updatedData = data;
if (identifierType === 'ClientId') {
updatedData.ClientId = identifierValue;
} else if (identifierType === 'YCLID') {
updatedData.Yclid = identifierValue;
} else if (identifierType === 'UserId') {
updatedData.UserId = identifierValue;
} else {
throw new InstrumentationError(
'Invalid identifier type passed in external Id. Valid types are ClientId, YCLID, UserId. Aborting!',
);
}
return updatedData;
};

function isUnixTimestamp(datetime) {
if (moment.unix(datetime).isValid()) {
return datetime;
}
const unixTimestamp = moment(datetime).unix();
if (moment.unix(unixTimestamp).isValid()) {
return unixTimestamp;
}
throw new InstrumentationError('Invalid timestamp. Aborting!');
}

const validateData = (data) => {
const { Price, DateTime } = data;
if (!isDefinedNotNullNotEmpty(data)) {
throw new InstrumentationError('No traits found in the payload. Aborting!');
}
if (Price && typeof Price !== 'number') {
throw new InstrumentationError('Price can only be a numerical value. Aborting!');
}
if (!isDefinedNotNullNotEmpty(DateTime)) {
throw new InstrumentationError('DateTime cannot be empty. Aborting!');
}
data.DateTime = String(isUnixTimestamp(DateTime));
return data;
};

module.exports = {
setIdentifier,
validateData,
isUnixTimestamp,
};
2 changes: 1 addition & 1 deletion src/v0/destinations/facebook_conversions/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const populateCustomDataBasedOnCategory = (customData, message, category, catego
const { contentIds, contents } = populateContentsAndContentIDs([message.properties]);
eventTypeCustomData = {
...eventTypeCustomData,
content_ids: contentIds,
content_ids: contentIds.length === 1 ? contentIds[0] : contentIds,
contents,
content_type: contentType,
content_category: getContentCategory(contentCategory),
Expand Down
121 changes: 121 additions & 0 deletions test/integrations/destinations/facebook_conversions/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1534,4 +1534,125 @@ export const data = [
},
mockFns: defaultMockFns,
},
{
name: 'facebook_conversions',
description: 'Track event with standard event product added with content_ids',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
message: {
anonymousId: 'c82cbdff-e5be-4009-ac78-cdeea09ab4b1',
channel: 'web',
context: {
device: {
id: 'df16bffa-5c3d-4fbb-9bce-3bab098129a7R',
manufacturer: 'Xiaomi',
model: 'Redmi 6',
name: 'xiaomi',
},
network: {
carrier: 'Banglalink',
},
os: {
name: 'android',
version: '8.1.0',
},
screen: {
height: '100',
density: 50,
},
traits: {
email: ' [email protected] ',
address: {
zip: 1234,
},
anonymousId: 'c82cbdff-e5be-4009-ac78-cdeea09ab4b1',
},
},
event: 'product added',
integrations: {
All: true,
},
message_id: 'a80f82be-9bdc-4a9f-b2a5-15621ee41df8',
properties: {
revenue: 400,
additional_bet_index: 0,
id: '452345234',
quantity: 5,
},
timestamp: '2023-11-12T15:46:51.693229+05:30',
type: 'track',
},
destination: {
Config: {
limitedDataUsage: true,
blacklistPiiProperties: [
{
blacklistPiiProperties: '',
blacklistPiiHash: false,
},
],
accessToken: '09876',
datasetId: 'dummyID',
eventsToEvents: [
{
from: '',
to: '',
},
],
eventCustomProperties: [
{
eventCustomProperties: '',
},
],
removeExternalId: true,
whitelistPiiProperties: [
{
whitelistPiiProperties: '',
},
],
actionSource: 'website',
},
Enabled: true,
},
},
],
},
},
output: {
response: {
status: 200,
body: [
{
output: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://graph.facebook.com/v18.0/dummyID/events?access_token=09876',
headers: {},
params: {},
body: {
JSON: {},
XML: {},
JSON_ARRAY: {},
FORM: {
data: [
'{"user_data":{"em":"48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08","zp":"03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4"},"event_name":"AddToCart","event_time":1699784211,"action_source":"website","custom_data":{"revenue":400,"additional_bet_index":0,"id":"452345234","quantity":5,"content_ids":"452345234","contents":[{"id":"452345234","quantity":5}],"content_type":"product","currency":"USD","value":400}}',
],
},
},
files: {},
userId: '',
},
statusCode: 200,
},
],
},
},
mockFns: defaultMockFns,
},
];
Loading

0 comments on commit ed9e0cf

Please sign in to comment.