Skip to content

Commit

Permalink
feat: support page call in snapchat conversion (#2688)
Browse files Browse the repository at this point in the history
* feat: support page call in snapchat conversion

* chore:comment addresed
  • Loading branch information
anantjain45823 authored Oct 11, 2023
1 parent eca3be1 commit d681d5e
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/v0/destinations/snapchat_conversion/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const eventNameMapping = {
custom_event_4: 'CUSTOM_EVENT_4',
custom_event_5: 'CUSTOM_EVENT_5',
};

const pageTypeToTrackEvent = 'page_view';
const mappingConfig = getMappingConfig(ConfigCategory, __dirname);

module.exports = {
Expand All @@ -82,4 +82,5 @@ module.exports = {
mappingConfig,
trackCommonConfig: mappingConfig[ConfigCategory.COMMON.name],
MAX_BATCH_SIZE,
pageTypeToTrackEvent
};
7 changes: 5 additions & 2 deletions src/v0/destinations/snapchat_conversion/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const {
mappingConfig,
ConfigCategory,
MAX_BATCH_SIZE,
pageTypeToTrackEvent,
} = require('./config');
const {
msUnixTimestamp,
Expand Down Expand Up @@ -279,14 +280,16 @@ function eventMappingHandler(message, destination) {

function process(event) {
const { message, destination } = event;

// const message = { ...incomingMessage };
if (!message.type) {
throw new InstrumentationError('Event type is required');
}

const messageType = message.type.toLowerCase();
let response;
if (messageType === EventType.TRACK) {
if (messageType === EventType.PAGE) {
response = trackResponseBuilder(message, destination, pageTypeToTrackEvent);
} else if (messageType === EventType.TRACK) {
const mappedEvents = eventMappingHandler(message, destination);
if (mappedEvents.length > 0) {
response = [];
Expand Down
102 changes: 96 additions & 6 deletions test/__tests__/data/snapchat_conversion.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,100 @@
[
{
"description": "Test case for Page event-> PAGE_VIEW ",
"input": {
"message": {
"messageId": "ec5481b6-a926-4d2e-b293-0b3a77c4d3be",
"originalTimestamp": "2022-04-22T10:57:58Z",
"channel": "web",
"anonymousId": "ea5cfab2-3961-4d8a-8187-3d1858c99090",
"context": {
"traits": {
"email": "[email protected]",
"phone": "+91 2111111 "
},
"app": {
"build": "1.0.0",
"name": "RudderLabs JavaScript SDK",
"namespace": "com.rudderlabs.javascript",
"version": "1.0.0"
},
"device": {
"advertisingId": "T0T0T072-5e28-45a1-9eda-ce22a3e36d1a",
"id": "3f034872-5e28-45a1-9eda-ce22a3e36d1a",
"manufacturer": "Google",
"model": "AOSP on IA Emulator",
"name": "generic_x86_arm",
"type": "ios",
"attTrackingStatus": 3
},
"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.0.0"
},
"locale": "en-US",
"os": {
"name": "iOS",
"version": "14.4.1"
},
"screen": {
"density": 2
},
"externalId": [
{
"type": "ga4AppInstanceId",
"id": "f0dd99v4f979fb997ce453373900f891"
}
],
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36"
},
"type": "page",
"name": "Home Page Viewed",
"properties": {
"title": "Home | RudderStack",
"url": "http://www.rudderstack.com"
},
"integrations": {
"All": true
},
"sentAt": "2022-04-22T10:57:58Z"
},
"destination": {
"Config": {
"apiKey": "dummyApiKey",
"pixelId": "dummyPixelId"
}
}
},
"output": {
"version": "1",
"type": "REST",
"method": "POST",
"endpoint": "https://tr.snapchat.com/v2/conversion",
"headers": {
"Authorization": "Bearer dummyApiKey",
"Content-Type": "application/json"
},
"params": {},
"body": {
"JSON": {
"event_type": "PAGE_VIEW",
"hashed_email": "73062d872926c2a556f17b36f50e328ddf9bff9d403939bd14b6c3b7f5a33fc2",
"hashed_phone_number": "bc77d64d7045fe44795ed926df37231a0cfb6ec6b74588c512790e9f143cc492",
"hashed_mobile_ad_id": "f9779d734aaee50f16ee0011260bae7048f1d9a128c62b6a661077875701edd2",
"hashed_idfv": "54bd0b26a3d39dad90f5149db49b9fd9ba885f8e35d1d94cae69273f5e657b9f",
"user_agent": "mozilla/5.0 (macintosh; intel mac os x 10_15_2) applewebkit/537.36 (khtml, like gecko) chrome/79.0.3945.88 safari/537.36",
"timestamp": "1650625078",
"event_conversion_type": "WEB",
"page_url": "http://www.rudderstack.com",
"pixel_id": "dummyPixelId"
},
"JSON_ARRAY": {},
"XML": {},
"FORM": {}
},
"files": {}
}
},
{
"description": "Test case for Prodcuts Searched event for conversion type offline",
"input": {
Expand Down Expand Up @@ -26,7 +122,6 @@
"type": "ios",
"attTrackingStatus": 3
},

"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.0.0"
Expand Down Expand Up @@ -2025,7 +2120,6 @@
"type": "ios",
"attTrackingStatus": 3
},

"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.0.0"
Expand Down Expand Up @@ -2227,7 +2321,6 @@
"type": "ios",
"attTrackingStatus": 3
},

"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.0.0"
Expand Down Expand Up @@ -2331,7 +2424,6 @@
"type": "ios",
"attTrackingStatus": 3
},

"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.0.0"
Expand Down Expand Up @@ -2403,7 +2495,6 @@
"type": "ios",
"attTrackingStatus": 3
},

"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.0.0"
Expand Down Expand Up @@ -2501,7 +2592,6 @@
"type": "ios",
"attTrackingStatus": 3
},

"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.0.0"
Expand Down

0 comments on commit d681d5e

Please sign in to comment.