Skip to content

Commit

Permalink
feat: add custom event name support in pinterest v5
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravudia committed Oct 28, 2023
1 parent c8baf5b commit 3ce6ec5
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 41 deletions.
6 changes: 2 additions & 4 deletions src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,8 @@ steps:
eventNames = $.convertToSnakeCase(eventNames);
eventNames.length === 0 ? eventNames = $.ecomEventMaps.(){eventInLowerCase in .src}.dest[] ?? [];
(eventNames.length === 0 && .destination.Config.sendAsCustomEvent) ? eventNames = ["custom"];
(eventNames.length === 0 && $.outputs.apiVersion === {{$.API_VERSION.v3}}) ? eventNames = [event];
$.assertConfig(eventNames.length > 0,
event + " is not mapped in UI. Make sure to map the event in UI or enable the 'send as custom event' setting")
eventNames
eventNames.length === 0 ? eventNames = [event];
eventNames;
- name: payload
template: |
Expand Down
18 changes: 6 additions & 12 deletions src/v0/destinations/pinterest_tag/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const convertToSnakeCase = (eventName) =>
const deduceTrackScreenEventName = (message, Config) => {
let eventName;
const { event, name } = message;
const { apiVersion = API_VERSION.v3, eventsMapping, sendAsCustomEvent } = Config;
const { eventsMapping, sendAsCustomEvent } = Config;
const trackEventOrScreenName = event || name;
if (!trackEventOrScreenName) {
throw new InstrumentationError('event_name could not be mapped. Aborting');
Expand Down Expand Up @@ -209,17 +209,11 @@ const deduceTrackScreenEventName = (message, Config) => {
return ['custom'];
}

if (apiVersion === API_VERSION.v3) {
/*
Step 4: In case both of the above stated cases fail, will send the event name as it is.
This is going to be reflected as "unknown" event in conversion API dashboard.
*/
return [trackEventOrScreenName];
}

throw new ConfigurationError(
`${event} is not mapped in UI. Make sure to map the event in UI or enable the 'send as custom event' setting`,
);
/*
Step 4: In case all of the above stated cases failed, will send the event name as it is.
This is going to be reflected as "unknown" event in conversion API dashboard.
*/
return [trackEventOrScreenName];
};

/**
Expand Down
65 changes: 59 additions & 6 deletions test/__tests__/data/pinterest_tag_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,12 @@
"advertiser_id": "123456",
"app_id": "429047995",
"custom_data": {
"contents": [{ "item_price": "undefined", "quantity": 1 }],
"contents": [
{
"item_price": "undefined",
"quantity": 1
}
],
"currency": "USD",
"num_items": 0,
"order_id": "50314b8e9bcf000000000000",
Expand All @@ -698,7 +703,9 @@
},
"endpoint": "https://ct.pinterest.com/events/v3",
"files": {},
"headers": { "Content-Type": "application/json" },
"headers": {
"Content-Type": "application/json"
},
"method": "POST",
"params": {},
"type": "REST",
Expand Down Expand Up @@ -906,8 +913,54 @@
"statusCode": 400,
"error": "Conversion Token not found. Aborting"
},
{
"statusCode": 400,
"error": "custom event is not mapped in UI. Make sure to map the event in UI or enable the 'send as custom event' setting"
}
[
{
"version": "1",
"type": "REST",
"method": "POST",
"endpoint": "https://api.pinterest.com/v5/ad_accounts/accountId123/events",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer conversionToken123"
},
"params": {},
"body": {
"JSON": {
"event_name": "custom event",
"event_time": 1597383030,
"action_source": "web",
"event_id": "7208bbb6-2c4e-45bb-bf5b-ad426f3593e9",
"app_id": "429047995",
"user_data": {
"em": ["48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08"],
"ph": ["d164bbe036663cb5c96835e9ccc6501e9a521127ea62f6359744928ba932413b"],
"ln": ["dcf000c2386fb76d22cefc0d118a8511bb75999019cd373df52044bccd1bd251"],
"fn": ["9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"],
"ct": ["6689106ca7922c30b2fd2c175c85bc7fc2d52cc4941bdd7bb622c6cdc6284a85"],
"st": ["3b45022ab36728cdae12e709e945bba267c50ee8a91e6e4388539a8e03a3fdcd"],
"zp": ["1a4292e00780e18d00e76fde9850aee5344e939ba593333cd5e4b4aa2cd33b0c"],
"country": ["582967534d0f909d196b97f9e6921342777aea87b46fa52df165389db1fb8ccf"],
"hashed_maids": ["6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090"],
"client_user_agent": "chrome"
},
"custom_data": {
"currency": "USD",
"value": "27.5",
"order_id": "50314b8e9bcf000000000000",
"num_items": 0,
"contents": [
{
"quantity": 1,
"item_price": "undefined"
}
]
}
},
"JSON_ARRAY": {},
"XML": {},
"FORM": {}
},
"files": {}
}
]
]
60 changes: 51 additions & 9 deletions test/integrations/destinations/pinterest_tag/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3417,16 +3417,58 @@ export const data = [
body: [
{
metadata: { destintionId: '1pYpzzvcn7AQ2W9GGIAZSsN6Mfq' },
error:
"custom event is not mapped in UI. Make sure to map the event in UI or enable the 'send as custom event' setting: Workflow: procWorkflow, Step: eventNames, ChildStep: undefined, OriginalError: custom event is not mapped in UI. Make sure to map the event in UI or enable the 'send as custom event' setting",
statTags: {
destType: 'PINTEREST_TAG',
errorCategory: 'platform',
feature: 'processor',
implementation: 'cdkV2',
module: 'destination',
output: {
body: {
JSON: {
event_time: 1597383030,
action_source: 'web',
event_id: '7208bbb6-2c4e-45bb-bf5b-ad426f3593e9',
app_id: '429047995',
user_data: {
em: ['48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08'],
ph: ['d164bbe036663cb5c96835e9ccc6501e9a521127ea62f6359744928ba932413b'],
ln: ['dcf000c2386fb76d22cefc0d118a8511bb75999019cd373df52044bccd1bd251'],
fn: ['9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'],
ct: ['6689106ca7922c30b2fd2c175c85bc7fc2d52cc4941bdd7bb622c6cdc6284a85'],
st: ['3b45022ab36728cdae12e709e945bba267c50ee8a91e6e4388539a8e03a3fdcd'],
zp: ['1a4292e00780e18d00e76fde9850aee5344e939ba593333cd5e4b4aa2cd33b0c'],
country: ['582967534d0f909d196b97f9e6921342777aea87b46fa52df165389db1fb8ccf'],
hashed_maids: [
'6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090',
],
client_user_agent: 'chrome',
},
custom_data: {
num_items: 0,
contents: [
{
quantity: 1,
item_price: 'undefined',
},
],
currency: 'USD',
value: '27.5',
order_id: '50314b8e9bcf000000000000',
},
event_name: 'custom event',
},
JSON_ARRAY: {},
XML: {},
FORM: {},
},
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://api.pinterest.com/v5/ad_accounts/accountId123/events',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer conversionToken123',
},
params: {},
files: {},
userId: '',
},
statusCode: 400,
statusCode: 200,
},
],
},
Expand Down
61 changes: 51 additions & 10 deletions test/integrations/destinations/pinterest_tag/step/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3339,17 +3339,58 @@ export const data = [
status: 200,
body: [
{
error:
"custom event is not mapped in UI. Make sure to map the event in UI or enable the 'send as custom event' setting",
statTags: {
destType: 'PINTEREST_TAG',
errorCategory: 'dataValidation',
errorType: 'configuration',
feature: 'processor',
implementation: 'native',
module: 'destination',
output: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://api.pinterest.com/v5/ad_accounts/accountId123/events',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer conversionToken123',
},
params: {},
body: {
JSON: {
event_name: 'custom event',
event_time: 1597383030,
action_source: 'web',
event_id: '7208bbb6-2c4e-45bb-bf5b-ad426f3593e9',
app_id: '429047995',
user_data: {
em: ['48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08'],
ph: ['d164bbe036663cb5c96835e9ccc6501e9a521127ea62f6359744928ba932413b'],
ln: ['dcf000c2386fb76d22cefc0d118a8511bb75999019cd373df52044bccd1bd251'],
fn: ['9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'],
ct: ['6689106ca7922c30b2fd2c175c85bc7fc2d52cc4941bdd7bb622c6cdc6284a85'],
st: ['3b45022ab36728cdae12e709e945bba267c50ee8a91e6e4388539a8e03a3fdcd'],
zp: ['1a4292e00780e18d00e76fde9850aee5344e939ba593333cd5e4b4aa2cd33b0c'],
country: ['582967534d0f909d196b97f9e6921342777aea87b46fa52df165389db1fb8ccf'],
hashed_maids: [
'6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090',
],
client_user_agent: 'chrome',
},
custom_data: {
currency: 'USD',
value: '27.5',
order_id: '50314b8e9bcf000000000000',
num_items: 0,
contents: [
{
quantity: 1,
item_price: 'undefined',
},
],
},
},
JSON_ARRAY: {},
XML: {},
FORM: {},
},
files: {},
userId: '',
},
statusCode: 400,
statusCode: 200,
},
],
},
Expand Down

0 comments on commit 3ce6ec5

Please sign in to comment.