From ca76297147f0a2c12d68d97dda95b9a44efe4020 Mon Sep 17 00:00:00 2001 From: Anant Jain <62471433+anantjain45823@users.noreply.github.com> Date: Fri, 22 Dec 2023 13:27:53 +0530 Subject: [PATCH 1/2] fix: tiktok add missing field brand (#2942) --- src/v0/destinations/tiktok_ads/util.js | 1 + test/integrations/destinations/tiktok_ads/processor/data.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/v0/destinations/tiktok_ads/util.js b/src/v0/destinations/tiktok_ads/util.js index 4050a9fe34..dbc8b344fc 100644 --- a/src/v0/destinations/tiktok_ads/util.js +++ b/src/v0/destinations/tiktok_ads/util.js @@ -21,6 +21,7 @@ const getContents = (message) => { price: product.price, quantity: product.quantity, description: product.description, + brand: product.brand }; contents.push(removeUndefinedAndNullValues(singleProduct)); }); diff --git a/test/integrations/destinations/tiktok_ads/processor/data.ts b/test/integrations/destinations/tiktok_ads/processor/data.ts index 4a6a4bd812..76a4a1ca89 100644 --- a/test/integrations/destinations/tiktok_ads/processor/data.ts +++ b/test/integrations/destinations/tiktok_ads/processor/data.ts @@ -4541,6 +4541,7 @@ export const data = [ category: 'Games', url: 'https://www.website.com/product/path', image_url: 'https://www.website.com/product/path.jpg', + brand:"brand_name" }, { product_id: '345', @@ -4618,6 +4619,7 @@ export const data = [ content_name: 'Monopoly', price: 14, quantity: 1, + brand:"brand_name" }, { content_type: 'product_group', From 429ca719952e5b8a4b6bad2ef1a087575613e861 Mon Sep 17 00:00:00 2001 From: Anant Jain <62471433+anantjain45823@users.noreply.github.com> Date: Tue, 26 Dec 2023 11:24:55 +0530 Subject: [PATCH 2/2] feat: amplitude add support for unset (#2941) * feat: amplitude add support for unset * Update src/v0/destinations/am/transform.js Co-authored-by: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com> * Update src/v0/destinations/am/transform.js Co-authored-by: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com> * chore:comment addresed * Update transform.js * chore:comment addresed * chore: added docs * Update utils.js --------- Co-authored-by: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com> --- src/v0/destinations/am/transform.js | 11 +++- src/v0/destinations/am/util.test.js | 66 +++++++++++++++++++ src/v0/destinations/am/utils.js | 27 ++++++++ .../destinations/am/processor/data.ts | 14 +++- 4 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 src/v0/destinations/am/util.test.js diff --git a/src/v0/destinations/am/transform.js b/src/v0/destinations/am/transform.js index 05a130d6e0..911ec51be0 100644 --- a/src/v0/destinations/am/transform.js +++ b/src/v0/destinations/am/transform.js @@ -297,6 +297,15 @@ const identifyBuilder = (message, destination, rawPayload) => { } }); } + // update identify call request with unset fields + // AM docs https://www.docs.developers.amplitude.com/analytics/apis/http-v2-api/#keys-for-the-event-argument:~:text=exceed%2040%20layers.-,user_properties,-Optional.%20Object.%20A + const unsetObject = AMUtils.getUnsetObj(message); + if (unsetObject) { + // Example unsetObject = { + // "testObj.del1": "-" + // } + set(rawPayload, `user_properties.$unset`, unsetObject); + } return rawPayload; }; @@ -334,7 +343,7 @@ const getResponseData = (evType, destination, rawPayload, message, groupInfo) => case EventType.IDENTIFY: // event_type for identify event is $identify rawPayload.event_type = IDENTIFY_AM; - identifyBuilder(message, destination, rawPayload); + rawPayload = identifyBuilder(message, destination, rawPayload); break; case EventType.GROUP: // event_type for identify event is $identify diff --git a/src/v0/destinations/am/util.test.js b/src/v0/destinations/am/util.test.js new file mode 100644 index 0000000000..faaa9170f0 --- /dev/null +++ b/src/v0/destinations/am/util.test.js @@ -0,0 +1,66 @@ +const { getUnsetObj } = require('./utils'); + +describe('getUnsetObj', () => { + it("should return undefined when 'message.integrations.Amplitude.fieldsToUnset' is not array", () => { + const message = { + integrations: { + Amplitude: { fieldsToUnset: 'field_name' }, + }, + }; + const result = getUnsetObj(message); + expect(result).toBeUndefined(); + }); + it("should return undefined when 'message.integrations.Amplitude.fieldsToUnset' is undefined", () => { + const message = { + integrations: { + Amplitude: {}, + }, + }; + const result = getUnsetObj(message); + expect(result).toBeUndefined(); + }); + + it("should return an empty objecty when 'message.integrations.Amplitude.fieldsToUnset' is an empty array", () => { + const message = { + integrations: { + Amplitude: { fieldsToUnset: [] }, + }, + }; + const result = getUnsetObj(message); + expect(result).toEqual({}); + }); + + it("should return an object with keys and values set to '-' when 'message.integrations.Amplitude.fieldsToUnset' is an array of strings", () => { + const message = { + integrations: { + Amplitude: { fieldsToUnset: ['Unset1', 'Unset2'] }, + }, + }; + const result = getUnsetObj(message); + expect(result).toEqual({ + Unset1: '-', + Unset2: '-', + }); + }); + + it("should handle missing 'message' parameter", () => { + const result = getUnsetObj(); + expect(result).toBeUndefined(); + }); + + // Should handle missing 'integrations' property in 'message' parameter + it("should handle missing 'integrations' property in 'message' parameter", () => { + const message = {}; + const result = getUnsetObj(message); + expect(result).toBeUndefined(); + }); + + // Should handle missing 'Amplitude' property in 'message.integrations' parameter + it("should handle missing 'Amplitude' property in 'message.integrations' parameter", () => { + const message = { + integrations: {}, + }; + const result = getUnsetObj(message); + expect(result).toBeUndefined(); + }); +}); diff --git a/src/v0/destinations/am/utils.js b/src/v0/destinations/am/utils.js index b9925c20d8..71fe0ab459 100644 --- a/src/v0/destinations/am/utils.js +++ b/src/v0/destinations/am/utils.js @@ -82,6 +82,32 @@ const getEventId = (payload, sourceKey) => { return undefined; }; +/** + * generates the unsetObject and returns it + * @param {*} message + * @returns + * + * Example message = { + integrations: { + Amplitude: { fieldsToUnset: ['Unset1', 'Unset2'] }, + All: true, + }, + }; + return unsetObj = { + "Unset1": "-", + "Unset2": "-" + } + AM docs: https://www.docs.developers.amplitude.com/analytics/apis/http-v2-api/#keys-for-the-event-argument:~:text=exceed%2040%20layers.-,user_properties,-Optional.%20Object.%20A + */ +const getUnsetObj = (message) => { + const fieldsToUnset = get(message, 'integrations.Amplitude.fieldsToUnset'); + let unsetObject; + if (Array.isArray(fieldsToUnset)) { + unsetObject = Object.fromEntries(fieldsToUnset.map((field) => [field, '-'])); + } + + return unsetObject; +}; module.exports = { getOSName, getOSVersion, @@ -90,4 +116,5 @@ module.exports = { getPlatform, getBrand, getEventId, + getUnsetObj, }; diff --git a/test/integrations/destinations/am/processor/data.ts b/test/integrations/destinations/am/processor/data.ts index 5e941e07f8..f28606da0c 100644 --- a/test/integrations/destinations/am/processor/data.ts +++ b/test/integrations/destinations/am/processor/data.ts @@ -488,6 +488,10 @@ export const data = [ { message: { channel: 'web', + integrations: { + Amplitude: { fieldsToUnset: ['email'] }, + All: true, + }, context: { externalId: [ { @@ -562,9 +566,6 @@ export const data = [ originalTimestamp: '2019-10-14T09:03:17.562Z', anonymousId: '123456', userId: '123456', - integrations: { - All: true, - }, sentAt: '2019-10-14T09:03:22.563Z', }, metadata: { @@ -616,6 +617,9 @@ export const data = [ insert_id: '84e26acc-56a5-4835-8233-591137fca468', ip: '0.0.0.0', user_properties: { + $unset: { + email: '-', + }, initial_referrer: 'https://docs.rudderstack.com', initial_referring_domain: 'docs.rudderstack.com', anonymousId: '123456', @@ -743,6 +747,7 @@ export const data = [ anonymousId: '123456', userId: '123456', integrations: { + Amplitude: { fieldsToUnset: ['testObj.unsetField1'] }, All: true, }, sentAt: '2019-10-14T09:03:22.563Z', @@ -791,6 +796,9 @@ export const data = [ insert_id: '84e26acc-56a5-4835-8233-591137fca468', ip: '0.0.0.0', user_properties: { + $unset: { + 'testObj.unsetField1': '-', + }, initial_referrer: 'https://docs.rudderstack.com', initial_referring_domain: 'docs.rudderstack.com', anonymousId: '123456',