From 3ce6ec5320a6763dde0b806585995d4a961dac0a Mon Sep 17 00:00:00 2001 From: Gauravudia Date: Sat, 28 Oct 2023 14:44:28 +0530 Subject: [PATCH] feat: add custom event name support in pinterest v5 --- .../pinterest_tag/procWorkflow.yaml | 6 +- src/v0/destinations/pinterest_tag/utils.js | 18 ++--- test/__tests__/data/pinterest_tag_output.json | 65 +++++++++++++++++-- .../pinterest_tag/processor/data.ts | 60 ++++++++++++++--- .../destinations/pinterest_tag/step/data.ts | 61 ++++++++++++++--- 5 files changed, 169 insertions(+), 41 deletions(-) diff --git a/src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml b/src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml index 6854573cfa..e0b81e0afe 100644 --- a/src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml +++ b/src/cdk/v2/destinations/pinterest_tag/procWorkflow.yaml @@ -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: | diff --git a/src/v0/destinations/pinterest_tag/utils.js b/src/v0/destinations/pinterest_tag/utils.js index c8ca8dabad..c6822636dc 100644 --- a/src/v0/destinations/pinterest_tag/utils.js +++ b/src/v0/destinations/pinterest_tag/utils.js @@ -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'); @@ -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]; }; /** diff --git a/test/__tests__/data/pinterest_tag_output.json b/test/__tests__/data/pinterest_tag_output.json index d09e534f4b..9fb809d112 100644 --- a/test/__tests__/data/pinterest_tag_output.json +++ b/test/__tests__/data/pinterest_tag_output.json @@ -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", @@ -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", @@ -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": {} + } + ] ] diff --git a/test/integrations/destinations/pinterest_tag/processor/data.ts b/test/integrations/destinations/pinterest_tag/processor/data.ts index 344d4ff507..c7f482aadd 100644 --- a/test/integrations/destinations/pinterest_tag/processor/data.ts +++ b/test/integrations/destinations/pinterest_tag/processor/data.ts @@ -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, }, ], }, diff --git a/test/integrations/destinations/pinterest_tag/step/data.ts b/test/integrations/destinations/pinterest_tag/step/data.ts index b5d6f5186f..cbd0b243bb 100644 --- a/test/integrations/destinations/pinterest_tag/step/data.ts +++ b/test/integrations/destinations/pinterest_tag/step/data.ts @@ -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, }, ], },