diff --git a/src/v0/destinations/pinterest_tag/utils.js b/src/v0/destinations/pinterest_tag/utils.js index 28ad27183c..7156b71af4 100644 --- a/src/v0/destinations/pinterest_tag/utils.js +++ b/src/v0/destinations/pinterest_tag/utils.js @@ -6,6 +6,7 @@ const { isDefinedAndNotNull, isDefined, getHashFromArrayWithDuplicate, + removeUndefinedAndNullValues } = require('../../util'); const { InstrumentationError } = require('../../util/errorTypes'); const { COMMON_CONFIGS, CUSTOM_CONFIGS } = require('./config'); @@ -286,7 +287,9 @@ const postProcessEcomFields = (message, mandatoryPayload) => { const { products, quantity } = properties; products.forEach((product) => { const prodParams = setIdPriceQuantity(product, message); - contentIds.push(prodParams.contentId); + if(prodParams.contentId) { + contentIds.push(prodParams.contentId); + } contentArray.push(prodParams.content); if (!product.quantity) { quantityInconsistent = true; @@ -307,7 +310,9 @@ const postProcessEcomFields = (message, mandatoryPayload) => { quantity are taken into consideration */ const prodParams = setIdPriceQuantity(properties, message); - contentIds.push(prodParams.contentId); + if(prodParams.contentId) { + contentIds.push(prodParams.contentId); + } contentArray.push(prodParams.content); totalQuantity = properties.quantity ? totalQuantity + properties.quantity : totalQuantity; } @@ -320,13 +325,13 @@ const postProcessEcomFields = (message, mandatoryPayload) => { } customPayload = { ...customPayload, - content_ids: contentIds, + content_ids: contentIds.length > 0 ? contentIds : null, contents: contentArray, }; return { ...mandatoryPayload, - custom_data: { ...customPayload }, + custom_data: { ...removeUndefinedAndNullValues(customPayload)}, }; }; diff --git a/test/__tests__/data/pinterest_tag_input.json b/test/__tests__/data/pinterest_tag_input.json index c6d88306b5..f84391ef55 100644 --- a/test/__tests__/data/pinterest_tag_input.json +++ b/test/__tests__/data/pinterest_tag_input.json @@ -1727,6 +1727,89 @@ "Enabled": true, "Transformations": [] } +}, +{ + "message": { + "type": "track", + "event": "custom event", + "channel": "web", + "sentAt": "2020-08-14T05:30:30.118Z", + "context": { + "source": "test", + "userAgent": "chrome", + "traits": { + "anonymousId": "50be5c78-6c3f-4b60-be84-97805a316fb1", + "email": "abc@gmail.com", + "phone": "+1234589947", + "ge": "male", + "db": "19950715", + "lastname": "Ganguly", + "firstName": "Shrouti", + "address": { + "city": "Kolkata", + "state": "WB", + "zip": "700114", + "country": "IN" + } + }, + "device": { + "advertisingId": "abc123" + }, + "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, + "currency": "USD", + "discount": 2.5, + "order_id": "50314b8e9bcf000000000000", + "requestIP": "123.0.0.0", + "shipping": 3, + "subtotal": 22.5, + "affiliation": "Google Store", + "checkout_id": "fksdjfsdjfisjf9sdfjsd9f" + }, + "anonymousId": "50be5c78-6c3f-4b60-be84-97805a316fb1", + "integrations": { + "All": true + } + }, + "destination": { + "ID": "1pYpzzvcn7AQ2W9GGIAZSsN6Mfq", + "Name": "PINTEREST_TAG", + "Config": { + "tagId": "123456789", + "advertiserId": "123456", + "appId": "429047995", + "sendingUnHashedData": true, + "enableDeduplication": true, + "deduplicationKey": "messageId", + "enhancedMatch": true, + "customProperties": [ + { + "properties": "presentclass" + }, + { + "properties": "presentgrade" + } + ], + "eventsMapping": [ + { + "from": "ABC Searched", + "to": "Watch Video" + } + ] + }, + "Enabled": true, + "Transformations": [] + } } ] diff --git a/test/__tests__/data/pinterest_tag_output.json b/test/__tests__/data/pinterest_tag_output.json index 5ceaebba96..2d8badf24f 100644 --- a/test/__tests__/data/pinterest_tag_output.json +++ b/test/__tests__/data/pinterest_tag_output.json @@ -853,5 +853,73 @@ }, "files": {} } + ], + [ + { + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://ct.pinterest.com/events/v3", + "headers": { + "Content-Type": "application/json" + }, + "params": {}, + "body": { + "JSON": { + "event_name": "custom event", + "event_time": 1597383030, + "action_source": "web", + "event_id": "7208bbb6-2c4e-45bb-bf5b-ad426f3593e9", + "app_id": "429047995", + "advertiser_id": "123456", + "user_data": { + "em": [ + "48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08" + ], + "ph": [ + "d164bbe036663cb5c96835e9ccc6501e9a521127ea62f6359744928ba932413b" + ], + "ln": [ + "bdfdee6414a89d72bfbf5ee90b1f85924467bae1e3980d83c2cd348dc31d5819" + ], + "fn": [ + "ee5db3fe0253b651aca3676692e0c59b25909304f5c51d223a02a215d104144b" + ], + "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": {} + } ] ]