Skip to content

Commit

Permalink
Fixed extra param getting added in payload
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivam4415 committed Dec 21, 2020
1 parent 2d2d9c5 commit 0953dad
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 41 deletions.
103 changes: 77 additions & 26 deletions integrations/GA4/ECommerceEventConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -63,6 +89,10 @@ const eventNamesConfigArray = [
requiredEventParameters.ProductName,
],
hasItem: true,
includeList: [
eventParametersConfigArray.ListId,
eventParametersConfigArray.Category,
],
},

// Promotion Section
Expand All @@ -86,6 +116,10 @@ const eventNamesConfigArray = [
requiredEventParameters.ProductName,
],
hasItem: true,
includeList: [
eventParametersConfigArray.ListId,
eventParametersConfigArray.Category,
],
},
{
src: ["product viewed"],
Expand All @@ -95,6 +129,10 @@ const eventNamesConfigArray = [
requiredEventParameters.ProductName,
],
hasItem: true,
includeList: [
eventParametersConfigArray.Currency,
eventParametersConfigArray.Total,
],
},
{
src: ["product added"],
Expand All @@ -104,6 +142,10 @@ const eventNamesConfigArray = [
requiredEventParameters.ProductName,
],
hasItem: true,
includeList: [
eventParametersConfigArray.Currency,
eventParametersConfigArray.Total,
],
},
{
src: ["product removed"],
Expand All @@ -113,6 +155,10 @@ const eventNamesConfigArray = [
requiredEventParameters.ProductName,
],
hasItem: true,
includeList: [
eventParametersConfigArray.Currency,
eventParametersConfigArray.Total,
],
},
{
src: ["cart viewed"],
Expand All @@ -122,6 +168,10 @@ const eventNamesConfigArray = [
requiredEventParameters.ProductName,
],
hasItem: true,
includeList: [
eventParametersConfigArray.Currency,
eventParametersConfigArray.Total,
],
},
{
src: ["checkout started"],
Expand All @@ -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
{
Expand All @@ -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
Expand All @@ -177,6 +250,10 @@ const eventNamesConfigArray = [
requiredEventParameters.ProductName,
],
hasItem: true,
includeList: [
eventParametersConfigArray.Currency,
eventParametersConfigArray.Total,
],
},
//-------

Expand All @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions integrations/GA4/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down Expand Up @@ -148,7 +148,8 @@ export default class GA4 {
destinationProperties = this.getdestinationProperties(
properties,
eventMappingObj.hasItem,
products
products,
eventMappingObj.includeList
);
}
this.sendGAEvent(event, destinationProperties, true, eventMappingObj);
Expand Down
10 changes: 5 additions & 5 deletions integrations/GA4/test/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -82,7 +82,7 @@ rudderanalytics.track("Promotion Clicked", {
name: "sale",
position: "home_top",
});
// same 1

rudderanalytics.track("Product Clicked", {
product_id: "123",
sku: "F15",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
7 changes: 0 additions & 7 deletions integrations/GA4/test/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand All @@ -92,7 +91,6 @@ gtag("event", "select_item", {
coupon: "DISC21", // extra
});

// extra params/
gtag("event", "view_item", {
items: [
{
Expand All @@ -117,7 +115,6 @@ gtag("event", "view_item", {
currency: "USD",
});

// extra params/
window.gtag("event", "add_to_cart", {
content_id: "123",
items: [
Expand All @@ -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: [
Expand All @@ -167,7 +163,6 @@ window.gtag("event", "remove_from_cart", {
location_id: 1,
});

// extra params/
window.gtag("event", "view_cart", {
items: [
{
Expand All @@ -187,7 +182,6 @@ window.gtag("event", "view_cart", {
],
});

// extra params/
window.gtag("event", "begin_checkout", {
items: [
{
Expand Down Expand Up @@ -229,7 +223,6 @@ const multiplePayloadExample = [
}),
];

// extra params/
window.gtag("event", "purchase", {
items: [
{
Expand Down

0 comments on commit 0953dad

Please sign in to comment.