From 0953dadd64c098748f72435676e27e837db655c8 Mon Sep 17 00:00:00 2001 From: "Shivam@RS" Date: Mon, 21 Dec 2020 17:26:10 +0530 Subject: [PATCH] Fixed extra param getting added in payload --- integrations/GA4/ECommerceEventConfig.js | 103 +++++++++++++++++------ integrations/GA4/browser.js | 7 +- integrations/GA4/test/input.js | 10 +-- integrations/GA4/test/output.js | 7 -- 4 files changed, 86 insertions(+), 41 deletions(-) diff --git a/integrations/GA4/ECommerceEventConfig.js b/integrations/GA4/ECommerceEventConfig.js index 9b43d41ce2..038b7cd43a 100644 --- a/integrations/GA4/ECommerceEventConfig.js +++ b/integrations/GA4/ECommerceEventConfig.js @@ -47,6 +47,32 @@ const includeParams = { }, }; +const eventParametersConfigArray = { + ListId: { src: "list_id", dest: "item_list_id", inItems: true }, + Category: { src: "category", dest: "item_list_name", inItems: true }, + Price: { src: "price", dest: "value" }, + Currency: { src: "currency", dest: "currency", inItems: true }, + Coupon: { src: "coupon", dest: "coupon", inItems: true }, + Affiliation: { src: "affiliation", dest: "affiliation", inItems: true }, + Shipping: { src: "shipping", dest: "shipping" }, + Tax: { src: "tax", dest: "tax" }, + Total: { src: "total", dest: "value" }, + CheckoutId: { src: "checkout_id", dest: "transaction_id" }, +}; + +const itemParametersConfigArray = [ + { src: "product_id", dest: "item_id" }, + { src: "order_id", dest: "item_id" }, + { src: "name", dest: "item_name" }, + { src: "coupon", dest: "coupon" }, + { src: "category", dest: "item_category" }, + { src: "brand", dest: "item_brand" }, + { src: "variant", dest: "item_variant" }, + { src: "price", dest: "price" }, + { src: "quantity", dest: "quantity" }, + { src: "position", dest: "index" }, +]; + const eventNamesConfigArray = [ // Browsing Section { @@ -63,6 +89,10 @@ const eventNamesConfigArray = [ requiredEventParameters.ProductName, ], hasItem: true, + includeList: [ + eventParametersConfigArray.ListId, + eventParametersConfigArray.Category, + ], }, // Promotion Section @@ -86,6 +116,10 @@ const eventNamesConfigArray = [ requiredEventParameters.ProductName, ], hasItem: true, + includeList: [ + eventParametersConfigArray.ListId, + eventParametersConfigArray.Category, + ], }, { src: ["product viewed"], @@ -95,6 +129,10 @@ const eventNamesConfigArray = [ requiredEventParameters.ProductName, ], hasItem: true, + includeList: [ + eventParametersConfigArray.Currency, + eventParametersConfigArray.Total, + ], }, { src: ["product added"], @@ -104,6 +142,10 @@ const eventNamesConfigArray = [ requiredEventParameters.ProductName, ], hasItem: true, + includeList: [ + eventParametersConfigArray.Currency, + eventParametersConfigArray.Total, + ], }, { src: ["product removed"], @@ -113,6 +155,10 @@ const eventNamesConfigArray = [ requiredEventParameters.ProductName, ], hasItem: true, + includeList: [ + eventParametersConfigArray.Currency, + eventParametersConfigArray.Total, + ], }, { src: ["cart viewed"], @@ -122,6 +168,10 @@ const eventNamesConfigArray = [ requiredEventParameters.ProductName, ], hasItem: true, + includeList: [ + eventParametersConfigArray.Currency, + eventParametersConfigArray.Total, + ], }, { src: ["checkout started"], @@ -131,6 +181,11 @@ const eventNamesConfigArray = [ requiredEventParameters.ProductName, ], hasItem: true, + includeList: [ + eventParametersConfigArray.Coupon, + eventParametersConfigArray.Currency, + eventParametersConfigArray.Total, + ], }, // To handle sending multiple payload for single event use approach as below { @@ -157,11 +212,29 @@ const eventNamesConfigArray = [ requiredEventParameters.ProductName, ], hasItem: true, + includeList: [ + eventParametersConfigArray.Affiliation, + eventParametersConfigArray.Coupon, + eventParametersConfigArray.Currency, + eventParametersConfigArray.CheckoutId, + eventParametersConfigArray.Shipping, + eventParametersConfigArray.Tax, + eventParametersConfigArray.Total, + ], }, { src: ["order refunded"], dest: "refund", hasItem: true, + includeList: [ + eventParametersConfigArray.Affiliation, + eventParametersConfigArray.Coupon, + eventParametersConfigArray.Currency, + eventParametersConfigArray.CheckoutId, + eventParametersConfigArray.Shipping, + eventParametersConfigArray.Tax, + eventParametersConfigArray.Total, + ], }, /* Coupon Section @@ -177,6 +250,10 @@ const eventNamesConfigArray = [ requiredEventParameters.ProductName, ], hasItem: true, + includeList: [ + eventParametersConfigArray.Currency, + eventParametersConfigArray.Total, + ], }, //------- @@ -197,32 +274,6 @@ const eventNamesConfigArray = [ //--------- ]; -const eventParametersConfigArray = [ - { src: "list_id", dest: "item_list_id", inItems: true }, - { src: "category", dest: "item_list_name", inItems: true }, - { src: "price", dest: "value" }, - { src: "currency", dest: "currency", inItems: true }, - { src: "coupon", dest: "coupon", inItems: true }, - { src: "affiliation", dest: "affiliation", inItems: true }, - { src: "shipping", dest: "shipping" }, - { src: "tax", dest: "tax" }, - { src: "total", dest: "value" }, -]; - -const itemParametersConfigArray = [ - { src: "product_id", dest: "item_id" }, - { src: "order_id", dest: "item_id" }, - { src: "checkout_id", dest: "item_name" }, - { src: "name", dest: "item_name" }, - { src: "coupon", dest: "coupon" }, - { src: "category", dest: "item_category" }, - { src: "brand", dest: "item_brand" }, - { src: "variant", dest: "item_variant" }, - { src: "price", dest: "price" }, - { src: "quantity", dest: "quantity" }, - { src: "position", dest: "index" }, -]; - export { eventNamesConfigArray, eventParametersConfigArray, diff --git a/integrations/GA4/browser.js b/integrations/GA4/browser.js index 2f62861ec1..a6db68da61 100644 --- a/integrations/GA4/browser.js +++ b/integrations/GA4/browser.js @@ -72,11 +72,11 @@ export default class GA4 { * @param {*} hasItem * @param {*} products */ - getdestinationProperties(properties, hasItem, products) { + getdestinationProperties(properties, hasItem, products, includeList) { let destinationProperties = {}; destinationProperties = getDestinationEventProperties( properties, - eventParametersConfigArray, + includeList, hasItem ); @@ -148,7 +148,8 @@ export default class GA4 { destinationProperties = this.getdestinationProperties( properties, eventMappingObj.hasItem, - products + products, + eventMappingObj.includeList ); } this.sendGAEvent(event, destinationProperties, true, eventMappingObj); diff --git a/integrations/GA4/test/input.js b/integrations/GA4/test/input.js index cb1b87c6c9..3aec6bb030 100644 --- a/integrations/GA4/test/input.js +++ b/integrations/GA4/test/input.js @@ -3,7 +3,7 @@ const rudderanalytics = []; rudderanalytics.track("Products Searched", { query: "HDMI cable", }); -// 1 + rudderanalytics.track("Product List Viewed", { list_id: "list1", category: "What's New", @@ -82,7 +82,7 @@ rudderanalytics.track("Promotion Clicked", { name: "sale", position: "home_top", }); -// same 1 + rudderanalytics.track("Product Clicked", { product_id: "123", sku: "F15", @@ -97,7 +97,7 @@ rudderanalytics.track("Product Clicked", { url: "https://www.website.com/product/path", image_url: "https://www.website.com/product/path.png", }); -// same 1 - but only coupon + rudderanalytics.track("Product Viewed", { product_id: "123", sku: "F15", @@ -113,7 +113,7 @@ rudderanalytics.track("Product Viewed", { url: "https://www.website.com/product/path", image_url: "https://www.website.com/product/path.png", }); -// same 1 + rudderanalytics.track("Product Added", { product_id: "123", sku: "F15", @@ -128,7 +128,7 @@ rudderanalytics.track("Product Added", { url: "https://www.website.com/product/path", image_url: "https://www.website.com/product/path.png", }); -// + rudderanalytics.track("Product Removed", { product_id: "123", sku: "F15", diff --git a/integrations/GA4/test/output.js b/integrations/GA4/test/output.js index 04b5985245..ae217f0266 100644 --- a/integrations/GA4/test/output.js +++ b/integrations/GA4/test/output.js @@ -71,7 +71,6 @@ gtag("event", "view_promotion", { location_id: "home_top" }); gtag("event", "select_promotion", { location_id: "home_top" }); -// extra params/ gtag("event", "select_item", { items: [ { @@ -92,7 +91,6 @@ gtag("event", "select_item", { coupon: "DISC21", // extra }); -// extra params/ gtag("event", "view_item", { items: [ { @@ -117,7 +115,6 @@ gtag("event", "view_item", { currency: "USD", }); -// extra params/ window.gtag("event", "add_to_cart", { content_id: "123", items: [ @@ -142,7 +139,6 @@ window.gtag("event", "add_to_cart", { location_id: 1, }); -// extra params/ window.gtag("event", "remove_from_cart", { content_id: "123", items: [ @@ -167,7 +163,6 @@ window.gtag("event", "remove_from_cart", { location_id: 1, }); -// extra params/ window.gtag("event", "view_cart", { items: [ { @@ -187,7 +182,6 @@ window.gtag("event", "view_cart", { ], }); -// extra params/ window.gtag("event", "begin_checkout", { items: [ { @@ -229,7 +223,6 @@ const multiplePayloadExample = [ }), ]; -// extra params/ window.gtag("event", "purchase", { items: [ {