From 9ef61ec09532fd20740fbcfc2f9509d298dbefe7 Mon Sep 17 00:00:00 2001 From: sayan-mitra Date: Wed, 16 Sep 2020 11:09:39 +0530 Subject: [PATCH 1/2] copy changes from dev --- integrations/GA/browser.js | 86 +++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 33 deletions(-) diff --git a/integrations/GA/browser.js b/integrations/GA/browser.js index 1cfcef0bf0..4d14b3c357 100644 --- a/integrations/GA/browser.js +++ b/integrations/GA/browser.js @@ -30,6 +30,7 @@ export default class GA { this.optimizeContainerId = config.optimize || ""; this.resetCustomDimensionsOnPage = config.resetCustomDimensionsOnPage || []; this.enhancedEcommerceLoaded = 0; + this.namedTracker = config.namedTracker || false; this.name = "GA"; this.eventWithCategoryFieldProductScoped = [ "product clicked", @@ -92,31 +93,38 @@ export default class GA { useAmpClientId: this.useGoogleAmpClientId, }; + // set tracker name to rudderGATracker if on + if (this.namedTracker) { + config.name = "rudderGATracker"; + this.trackerName = "rudderGATracker."; + } else { + this.trackerName = ""; + } window.ga("create", this.trackingID, config); if (this.optimizeContainerId) { - window.ga("require", this.optimizeContainerId); + window.ga(`${this.trackerName}require`, this.optimizeContainerId); } // ecommerce is required if (!this.ecommerce) { - window.ga("require", "ecommerce"); + window.ga(`${this.trackerName}require`, "ecommerce"); this.ecommerce = true; } // this is to display advertising if (this.doubleClick) { - window.ga("require", "displayfeatures"); + window.ga(`${this.trackerName}require`, "displayfeatures"); } // https://support.google.com/analytics/answer/2558867?hl=en if (this.enhancedLinkAttribution) { - window.ga("require", "linkid"); + window.ga(`${this.trackerName}require`, "linkid"); } // a warning is in ga debugger if anonymize is false after initialization if (this.anonymizeIp) { - window.ga("set", "anonymizeIp", true); + window.ga(`${this.trackerName}set`, "anonymizeIp", true); } logger.debug("===in init GA==="); @@ -125,7 +133,11 @@ export default class GA { identify(rudderElement) { // send global id if (this.sendUserId && rudderElement.message.userId) { - window.ga("set", "userId", rudderElement.message.userId); + window.ga( + `${this.trackerName}set`, + "userId", + rudderElement.message.userId + ); } // custom dimensions and metrics @@ -137,7 +149,7 @@ export default class GA { ); if (Object.keys(custom).length) { - window.ga("set", custom); + window.ga(`${this.trackerName}set`, custom); } logger.debug("in GoogleAnalyticsManager identify"); @@ -170,7 +182,7 @@ export default class GA { } // add transaction - window.ga("ecommerce:addTransaction", { + window.ga(`${this.trackerName}ecommerce:addTransaction`, { affiliation: properties.affiliation, shipping: properties.shipping, revenue: total, @@ -183,7 +195,7 @@ export default class GA { products.forEach((product) => { const productTrack = self.createProductTrack(rudderElement, product); - window.ga("ecommerce:addItem", { + window.ga(`${this.trackerName}ecommerce:addItem`, { category: productTrack.properties.category, quantity: productTrack.properties.quantity, price: productTrack.properties.price, @@ -194,7 +206,7 @@ export default class GA { }); }); - window.ga("ecommerce:send"); + window.ga(`${this.trackerName}ecommerce:send`); } // enhanced ecommerce events @@ -211,7 +223,7 @@ export default class GA { self.enhancedEcommerceTrackProduct(productTrack); }); - window.ga("ec:setAction", "checkout", { + window.ga(`${this.trackerName}ec:setAction`, "checkout", { step: properties.step || 1, option: options || undefined, }); @@ -230,8 +242,12 @@ export default class GA { this.loadEnhancedEcommerce(rudderElement); - window.ga("ec:setAction", "checkout_option", params); - window.ga("send", "event", "Checkout", "Option"); + window.ga( + `${this.trackerName}ec:setAction`, + "checkout_option", + params + ); + window.ga(`${this.trackerName}send`, "event", "Checkout", "Option"); break; case "Order Completed": total = @@ -250,7 +266,7 @@ export default class GA { productTrack = { message: productTrack }; self.enhancedEcommerceTrackProduct(productTrack); }); - window.ga("ec:setAction", "purchase", { + window.ga(`${this.trackerName}ec:setAction`, "purchase", { id: orderId, affiliation: props.affiliation, revenue: total, @@ -270,7 +286,7 @@ export default class GA { each(products, (product) => { const track = { properties: product }; - window.ga("ec:addProduct", { + window.ga(`${this.trackerName}ec:addProduct`, { id: track.properties.product_id || track.properties.id || @@ -279,7 +295,7 @@ export default class GA { }); }); - window.ga("ec:setAction", "refund", { + window.ga(`${this.trackerName}ec:setAction`, "refund", { id: orderId, }); @@ -323,7 +339,7 @@ export default class GA { break; case "Promotion Viewed": this.loadEnhancedEcommerce(rudderElement); - window.ga("ec:addPromo", { + window.ga(`${this.trackerName}ec:addPromo`, { id: props.promotion_id || props.id, name: props.name, creative: props.creative, @@ -334,13 +350,13 @@ export default class GA { case "Promotion Clicked": this.loadEnhancedEcommerce(rudderElement); - window.ga("ec:addPromo", { + window.ga(`${this.trackerName}ec:addPromo`, { id: props.promotion_id || props.id, name: props.name, creative: props.creative, position: props.position, }); - window.ga("ec:setAction", "promo_click", {}); + window.ga(`${this.trackerName}ec:setAction`, "promo_click", {}); this.pushEnhancedEcommerce(rudderElement); break; case "Product List Viewed": @@ -379,13 +395,13 @@ export default class GA { Object.keys(impressionObj).forEach((key) => { if (impressionObj[key] === undefined) delete impressionObj[key]; }); - window.ga("ec:addImpression", impressionObj); + window.ga(`${this.trackerName}ec:addImpression`, impressionObj); }); this.pushEnhancedEcommerce(rudderElement); break; case "Product List Filtered": props.filters = props.filters || []; - props.sorters = props.sorters || []; + props.sorts = props.sorts || []; filters = props.filters .map((obj) => { return `${obj.type}:${obj.value}`; @@ -435,7 +451,7 @@ export default class GA { Object.keys(impressionObj).forEach((key) => { if (impressionObj[key] === undefined) delete impressionObj[key]; }); - window.ga("ec:addImpression", impressionObj); + window.ga(`${this.trackerName}ec:addImpression`, impressionObj); }); this.pushEnhancedEcommerce(rudderElement); break; @@ -473,7 +489,7 @@ export default class GA { ), }; - window.ga("send", "event", payload.payload); + window.ga(`${this.trackerName}send`, "event", payload.payload); logger.debug("in GoogleAnalyticsManager track"); } } else { @@ -508,7 +524,7 @@ export default class GA { ...this.setCustomDimenionsAndMetrics(rudderElement.message.properties), }; - window.ga("send", "event", payload.payload); + window.ga(`${this.trackerName}send`, "event", payload.payload); logger.debug("in GoogleAnalyticsManager track"); } } @@ -570,7 +586,7 @@ export default class GA { resetCustomDimensions[this.dimensionsArray[property]] = null; } } - window.ga("set", resetCustomDimensions); + window.ga(`${this.trackerName}set`, resetCustomDimensions); // adds more properties to pageview which will be sent pageview = { @@ -585,11 +601,11 @@ export default class GA { logger.debug(document.referrer); if (pageReferrer !== document.referrer) payload.referrer = pageReferrer; - window.ga("set", payload); + window.ga(`${this.trackerName}set`, payload); if (this.pageCalled) delete pageview.location; - window.ga("send", "pageview", pageview); + window.ga(`${this.trackerName}send`, "pageview", pageview); // categorized pages if (category && this.trackCategorizedPages) { @@ -664,7 +680,7 @@ export default class GA { ); if (Object.keys(custom).length) { if (this.setAllMappedProps) { - window.ga("set", custom); + window.ga(`${this.trackerName}set`, custom); } else { Object.keys(custom).forEach((key) => { ret[key] = custom[key]; @@ -712,11 +728,15 @@ export default class GA { */ loadEnhancedEcommerce(rudderElement) { if (this.enhancedEcommerceLoaded === 0) { - window.ga("require", "ec"); + window.ga(`${this.trackerName}require`, "ec"); this.enhancedEcommerceLoaded = 1; } - window.ga("set", "&cu", rudderElement.message.properties.currency); + window.ga( + `${this.trackerName}set`, + "&cu", + rudderElement.message.properties.currency + ); } /** @@ -754,7 +774,7 @@ export default class GA { ), }; - window.ga("ec:addProduct", product); + window.ga(`${this.trackerName}ec:addProduct`, product); } /** @@ -766,7 +786,7 @@ export default class GA { */ enhancedEcommerceTrackProductAction(rudderElement, action, data) { this.enhancedEcommerceTrackProduct(rudderElement); - window.ga("ec:setAction", action, data || {}); + window.ga(`${this.trackerName}ec:setAction`, action, data || {}); } /** @@ -833,4 +853,4 @@ export default class GA { const valid = rejectArr(options); return valid.length > 0 ? valid.join(", ") : null; } -} +} \ No newline at end of file From f0435b6d562e0824cc607ceeec97eeaf313d98cb Mon Sep 17 00:00:00 2001 From: sayan-mitra Date: Wed, 16 Sep 2020 11:10:52 +0530 Subject: [PATCH 2/2] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0bb81461b0..b46904a006 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rudder-analytics", - "version": "1.1.5", + "version": "1.1.6", "description": "", "main": "./dist/browser.min.js", "size-limit": [