@shopgate/tracking-core 6.20.0-beta.2 → 6.20.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/AppHandler.js +3 -3
- package/core/Core.js +6 -6
- package/helpers/formatHelpers.js +1 -1
- package/helpers/formatHelpers.spec.js +1 -1
- package/helpers/helper.js +5 -5
- package/package.json +4 -4
- package/plugins/Base.js +4 -4
- package/plugins/trackers/FbPixel.js +5 -5
- package/plugins/trackers/GaBase.js +5 -5
- package/plugins/trackers/GaClassic.js +3 -3
- package/plugins/trackers/GaUniversal.js +2 -2
- package/plugins/trackers/Unified.js +3 -3
package/core/AppHandler.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}import{SGAction}from"../helpers/helper";/**
|
|
1
|
+
function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}import{SGAction}from"../helpers/helper";/**
|
|
2
2
|
* Handler for the communication between the tracking plugins and the app.
|
|
3
|
-
*/var AppHandler=/*#__PURE__*/function(){function AppHandler(){_classCallCheck(this,AppHandler);}_createClass(AppHandler,[{key:"viewContent"
|
|
3
|
+
*/var AppHandler=/*#__PURE__*/function(){function AppHandler(){_classCallCheck(this,AppHandler);}_createClass(AppHandler,[{key:"viewContent",value:/**
|
|
4
4
|
* Log a pageview
|
|
5
5
|
*
|
|
6
6
|
* @param {UnifiedPageview} data Tracking data for this event
|
|
7
7
|
* @param {UnifiedRestrictions} [restrictions] Info about the restrictions
|
|
8
8
|
* @returns {AppHandler} Instance of SgTrackingAppHandler
|
|
9
|
-
*/
|
|
9
|
+
*/function viewContent(data,restrictions){SGAction.analyticsLogPageview(AppHandler.prepareTrackingData(data,restrictions));return this;}/**
|
|
10
10
|
* AnalyticsLogEvent
|
|
11
11
|
* @param {UnifiedPageview} data Tracking data for this event
|
|
12
12
|
* @param {UnifiedRestrictions} [restrictions] Info about the restrictions
|
package/core/Core.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import{logger}from'@shopgate/pwa-core/helpers';import errorManager from'@shopgate/pwa-core/classes/ErrorManager';import{SOURCE_TRACKING,CODE_TRACKING}from'@shopgate/pwa-core/constants/ErrorManager';import{optOut as _optOut,isOptOut}from"../helpers/optOut";import trackingEvents,{REMOVE_TRACKER,ADD_TRACKER,scannerEvents}from"../helpers/events";/**
|
|
1
|
+
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import{logger}from'@shopgate/pwa-core/helpers';import errorManager from'@shopgate/pwa-core/classes/ErrorManager';import{SOURCE_TRACKING,CODE_TRACKING}from'@shopgate/pwa-core/constants/ErrorManager';import{optOut as _optOut,isOptOut}from"../helpers/optOut";import trackingEvents,{REMOVE_TRACKER,ADD_TRACKER,scannerEvents}from"../helpers/events";/**
|
|
2
2
|
* Core for our tracking system. Plugins can use the core to register for events. Pub/sub pattern.
|
|
3
3
|
*/var Core=/*#__PURE__*/function(){/**
|
|
4
4
|
* Constructor
|
|
@@ -6,8 +6,8 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
|
|
|
6
6
|
if(typeof window.getEmosCrossUrlParams==='function'){newUrl+=(!newUrl.includes('?')?'?':'&')+window.getEmosCrossUrlParams();}// If there is no sgData, we are in sg cloud app and have to return the new url
|
|
7
7
|
if(!window.sgData){return newUrl;}// Universal
|
|
8
8
|
try{window.ga(function(){var tracker=window.ga.getByName('shopgate');var linker=new window.gaplugins.Linker(tracker);// Add ?_ga parameter to the url
|
|
9
|
-
newUrl=linker.decorate(newUrl);});}catch(e){
|
|
10
|
-
// Check if there is the classic sdk
|
|
9
|
+
newUrl=linker.decorate(newUrl);});}catch(e){// Ignore errors
|
|
10
|
+
}// Check if there is the classic sdk
|
|
11
11
|
if(typeof _gaq==='undefined'){// No classic sdk
|
|
12
12
|
if(formElement){/**
|
|
13
13
|
* The no-param-reassign rule is deactivated on purpose,
|
|
@@ -58,7 +58,7 @@ eventStore=eventStore[page];}return eventStore;}/**
|
|
|
58
58
|
* @param {string} eventName Name of the event
|
|
59
59
|
* @param {Object} options Additional options
|
|
60
60
|
* @returns {RemoveListener} Function to remove the listener
|
|
61
|
-
*/},{key:"registerHelper",value:function registerHelper(callback,eventName){var options=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};var defaults={trackerName:'',page:null,merchant:true,shopgate:true,options:{}};var pluginOptions=_extends({},defaults,
|
|
61
|
+
*/},{key:"registerHelper",value:function registerHelper(callback,eventName){var options=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};var defaults={trackerName:'',page:null,merchant:true,shopgate:true,options:{}};var pluginOptions=_extends({},defaults,options);if(!pluginOptions.trackerName){logger.warn("'SgTrackingCore': Attempt to register for event \"".concat(eventName,"\" by a nameless tracker"));}// Get the correct store
|
|
62
62
|
var store=this.getEventStore(eventName,pluginOptions.page);// Add the callback to queue
|
|
63
63
|
var index=store.push({callback:callback,trackerName:pluginOptions.trackerName,useNativeSdk:pluginOptions.options.useNativeSdk,overrideUnified:pluginOptions.options.overrideUnified,merchant:pluginOptions.merchant,shopgate:pluginOptions.shopgate})-1;// Provide handle back for removal of event
|
|
64
64
|
return{remove:function remove(){delete store[index];}};}/**
|
|
@@ -109,10 +109,10 @@ this.notifyPlugins(null,ADD_TRACKER);}return _optOut(out);}/**
|
|
|
109
109
|
* Check if the opt-out state is set
|
|
110
110
|
*
|
|
111
111
|
* @returns {boolean} Information about the opt out state
|
|
112
|
-
*/},{key:"registerFinished"
|
|
112
|
+
*/},{key:"registerFinished",value:/**
|
|
113
113
|
* Called from the outside when all plugins are registered
|
|
114
114
|
* @return {Core}
|
|
115
|
-
*/
|
|
115
|
+
*/function registerFinished(){var _this3=this;if(this.registerFinish){return this;}// Trigger all events that happened till now
|
|
116
116
|
this.triggeredEvents.forEach(function(entry){entry["function"].apply(_this3,entry.params);});this.registerFinish=true;// Reset the event store
|
|
117
117
|
this.triggeredEvents=[];return this;}/**
|
|
118
118
|
* Remove all registered callbacks. Only used and needed for unit tests
|
package/helpers/formatHelpers.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _typeof(obj){
|
|
1
|
+
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}import{hex2bin,SGLink}from"./helper";import sgTrackingUrlMapper from"./urlMapping";import{customEvents}from"./events";/**
|
|
2
2
|
* Gets the value at path of object. If the resolved value is undefined,
|
|
3
3
|
* the defaultValue is used in its place.
|
|
4
4
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{sgDataProduct,sgDataSearch,sgDataCategoryAll}from"../tests/data/tracking.testData";import helpers from"./formatHelpers";var smartbanner=helpers.smartbanner,purchase=helpers.purchase,pageview=helpers.pageview,viewContent=helpers.viewContent,addToCart=helpers.addToCart,addToWishlist=helpers.addToWishlist,initiatedCheckout=helpers.initiatedCheckout,completedRegistration=helpers.completedRegistration,search=helpers.search,addedPaymentInfo=helpers.addedPaymentInfo,selectedPaymentInfo=helpers.selectedPaymentInfo,itemView=helpers.itemView;var mockBaseProduct={uid:'base-product',name:'Product name',manufacturer:'Product manufacturer',quantity:3,tags:[],amount:{currency:'EUR',gross:'100.99',net:'90.99',striked:'0.00'}};var mockMockVariantProduct=_extends({},mockBaseProduct,{uid:'variant-product'});var expectedProduct={id:mockBaseProduct.uid,name:mockBaseProduct.name,brand:mockBaseProduct.manufacturer,type:'product',priceNet:parseFloat(mockBaseProduct.amount.net),priceGross:parseFloat(mockBaseProduct.amount.gross),quantity:mockBaseProduct.quantity,currency:mockBaseProduct.amount.currency};describe('Format helpers',function(){describe('custom events',function(){it('should format event data for the smartbanner event',function(){var raw={eventCategory:'',eventAction:'',eventLabel:null,eventValue:null,nonInteraction:false};expect(smartbanner(raw)).toEqual(raw);});});describe('purchase()',function(){it('should format event data',function(){var raw={order:{number:'123',amount:{gross:'10.00',net:'11.05',tax:'6.50',currency:'EUR'},shipping:{amount:{gross:'1.00',net:'0.87'}},products:[mockBaseProduct]},shop:{name:'testshop'}};expect(purchase(raw)).toEqual({id:raw.order.number,type:'product',affiliation:raw.shop.name,revenueGross:parseFloat(raw.order.amount.gross),revenueNet:parseFloat(raw.order.amount.net),tax:parseFloat(raw.order.amount.tax),shippingGross:parseFloat(raw.order.shipping.amount.gross),shippingNet:parseFloat(raw.order.shipping.amount.net),currency:raw.order.amount.currency,items:[expectedProduct]});});});describe('pageview()',function(){it('should format event data',function(){var raw={page:{link:'http://m.atu.de/item/1234'}};expect(pageview(raw)).toEqual({page:{merchantUrl:'item/1234',shopgateUrl:'item'}});});});describe('viewContent()',function(){it('should format event data for an item route',function(){var raw=_extends({},sgDataProduct);var expected={id:sgDataProduct.product.productNumber,name:sgDataProduct.product.name,type:'product'};expect(viewContent(raw)).toEqual(expected);raw.page.link="https://rapid.shopgate.com/sg_app_resources/10006/item/".concat(sgDataProduct.product.productNumber);expect(viewContent(raw)).toEqual(expected);});it('should format event data for an category/all route',function(){expect(viewContent(sgDataCategoryAll)).toEqual({id:"".concat(sgDataCategoryAll.category.uid,"/all"),name:sgDataCategoryAll.category.name,type:'category'});});it('should format event data for a search route',function(){expect(viewContent(sgDataSearch)).toEqual({id:sgDataSearch.search.query,name:sgDataSearch.page.title.substring(0,sgDataSearch.page.title.indexOf(':')).trim(),type:sgDataSearch.page.name});});it('should format event data for a reviews route',function(){var raw={page:{referrer:'http://testshop.schneider.localdev.cc/php/shopgate/item/5347313134',name:'reviews',link:'http://testshop.schneider.localdev.cc/php/shopgate/reviews/5347313134',title:'Reviews - Product with manufacturer - Shopgate Testshop'}};expect(viewContent(raw)).toEqual({id:'SG114',name:'Reviews - Product with manufacturer - Shopgate Testshop',type:'reviews'});});it('should format event data for a payment_success route',function(){var raw={page:{referrer:'',name:'success',link:'http://testshop.schneider.localdev.cc/php/shopgate/payment_success/5347313134',title:'Checkout success'}};expect(viewContent(raw)).toEqual({id:'5347313134',name:'Checkout success',type:'checkout_success'});});});describe('addToCart',function(){it('should format event data',function(){var raw={products:[mockBaseProduct]};expect(addToCart(raw)).toEqual({type:'product',items:[expectedProduct]});});});describe('addToWishlist()',function(){it('should format event data',function(){var raw={favouriteListProducts:[_extends({},mockBaseProduct,{currency_id:'EUR',unit_amount_net:(mockBaseProduct.amount.net*100).toString(),unit_amount_with_tax:(mockBaseProduct.amount.gross*100).toString()})]};var quantity=expectedProduct.quantity,brand=expectedProduct.brand,expectedItems=_objectWithoutProperties(expectedProduct,
|
|
1
|
+
var _excluded=["quantity","brand"];function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{sgDataProduct,sgDataSearch,sgDataCategoryAll}from"../tests/data/tracking.testData";import helpers from"./formatHelpers";var smartbanner=helpers.smartbanner,purchase=helpers.purchase,pageview=helpers.pageview,viewContent=helpers.viewContent,addToCart=helpers.addToCart,addToWishlist=helpers.addToWishlist,initiatedCheckout=helpers.initiatedCheckout,completedRegistration=helpers.completedRegistration,search=helpers.search,addedPaymentInfo=helpers.addedPaymentInfo,selectedPaymentInfo=helpers.selectedPaymentInfo,itemView=helpers.itemView;var mockBaseProduct={uid:'base-product',name:'Product name',manufacturer:'Product manufacturer',quantity:3,tags:[],amount:{currency:'EUR',gross:'100.99',net:'90.99',striked:'0.00'}};var mockMockVariantProduct=_extends({},mockBaseProduct,{uid:'variant-product'});var expectedProduct={id:mockBaseProduct.uid,name:mockBaseProduct.name,brand:mockBaseProduct.manufacturer,type:'product',priceNet:parseFloat(mockBaseProduct.amount.net),priceGross:parseFloat(mockBaseProduct.amount.gross),quantity:mockBaseProduct.quantity,currency:mockBaseProduct.amount.currency};describe('Format helpers',function(){describe('custom events',function(){it('should format event data for the smartbanner event',function(){var raw={eventCategory:'',eventAction:'',eventLabel:null,eventValue:null,nonInteraction:false};expect(smartbanner(raw)).toEqual(raw);});});describe('purchase()',function(){it('should format event data',function(){var raw={order:{number:'123',amount:{gross:'10.00',net:'11.05',tax:'6.50',currency:'EUR'},shipping:{amount:{gross:'1.00',net:'0.87'}},products:[mockBaseProduct]},shop:{name:'testshop'}};expect(purchase(raw)).toEqual({id:raw.order.number,type:'product',affiliation:raw.shop.name,revenueGross:parseFloat(raw.order.amount.gross),revenueNet:parseFloat(raw.order.amount.net),tax:parseFloat(raw.order.amount.tax),shippingGross:parseFloat(raw.order.shipping.amount.gross),shippingNet:parseFloat(raw.order.shipping.amount.net),currency:raw.order.amount.currency,items:[expectedProduct]});});});describe('pageview()',function(){it('should format event data',function(){var raw={page:{link:'http://m.atu.de/item/1234'}};expect(pageview(raw)).toEqual({page:{merchantUrl:'item/1234',shopgateUrl:'item'}});});});describe('viewContent()',function(){it('should format event data for an item route',function(){var raw=_extends({},sgDataProduct);var expected={id:sgDataProduct.product.productNumber,name:sgDataProduct.product.name,type:'product'};expect(viewContent(raw)).toEqual(expected);raw.page.link="https://rapid.shopgate.com/sg_app_resources/10006/item/".concat(sgDataProduct.product.productNumber);expect(viewContent(raw)).toEqual(expected);});it('should format event data for an category/all route',function(){expect(viewContent(sgDataCategoryAll)).toEqual({id:"".concat(sgDataCategoryAll.category.uid,"/all"),name:sgDataCategoryAll.category.name,type:'category'});});it('should format event data for a search route',function(){expect(viewContent(sgDataSearch)).toEqual({id:sgDataSearch.search.query,name:sgDataSearch.page.title.substring(0,sgDataSearch.page.title.indexOf(':')).trim(),type:sgDataSearch.page.name});});it('should format event data for a reviews route',function(){var raw={page:{referrer:'http://testshop.schneider.localdev.cc/php/shopgate/item/5347313134',name:'reviews',link:'http://testshop.schneider.localdev.cc/php/shopgate/reviews/5347313134',title:'Reviews - Product with manufacturer - Shopgate Testshop'}};expect(viewContent(raw)).toEqual({id:'SG114',name:'Reviews - Product with manufacturer - Shopgate Testshop',type:'reviews'});});it('should format event data for a payment_success route',function(){var raw={page:{referrer:'',name:'success',link:'http://testshop.schneider.localdev.cc/php/shopgate/payment_success/5347313134',title:'Checkout success'}};expect(viewContent(raw)).toEqual({id:'5347313134',name:'Checkout success',type:'checkout_success'});});});describe('addToCart',function(){it('should format event data',function(){var raw={products:[mockBaseProduct]};expect(addToCart(raw)).toEqual({type:'product',items:[expectedProduct]});});});describe('addToWishlist()',function(){it('should format event data',function(){var raw={favouriteListProducts:[_extends({},mockBaseProduct,{currency_id:'EUR',unit_amount_net:(mockBaseProduct.amount.net*100).toString(),unit_amount_with_tax:(mockBaseProduct.amount.gross*100).toString()})]};var quantity=expectedProduct.quantity,brand=expectedProduct.brand,expectedItems=_objectWithoutProperties(expectedProduct,_excluded);expect(addToWishlist(raw)).toEqual({type:'product',items:[expectedItems]});});});describe('initiatedCheckout()',function(){it('should format event data',function(){var raw={checkoutType:'express',product:{amount:{net:'100.00',gross:'110.50',currency:'EUR'}},quantity:16};expect(initiatedCheckout(raw)).toEqual({type:raw.checkoutType,valueNet:parseFloat(raw.product.amount.net),valueGross:parseFloat(raw.product.amount.gross),numItems:raw.quantity,currency:raw.product.amount.currency,paymentInfoAvailable:raw.checkoutType!=='default'});});});describe('completedRegistration()',function(){it('should format event data',function(){var raw={registrationType:'guest'};expect(completedRegistration(raw)).toEqual({registrationMethod:raw.registrationType});});});describe('search()',function(){it('should format event data',function(){var raw={search:{resultCount:356,query:'black shoes'}};expect(search(raw)).toEqual({type:'product',query:raw.search.query,hits:raw.search.resultCount,success:!!raw.search.resultCount});});});describe('itemView()',function(){it('should format raw base product data',function(){var raw={product:mockBaseProduct};expect(itemView(raw)).toEqual({id:'base-product',type:'',name:'Product name',priceNet:90.99,priceGross:100.99,currency:'EUR',brand:'Product manufacturer'});});it('should format raw variant product data',function(){var raw={baseProduct:mockBaseProduct,variant:mockMockVariantProduct};expect(itemView(raw)).toEqual({id:'variant-product',type:'',name:'Product name',priceNet:90.99,priceGross:100.99,currency:'EUR',brand:'Product manufacturer'});});});describe('addedPaymentInfo()',function(){it('should format event data',function(){var raw={paymentMethodAdded:{success:true,name:'credit card'}};expect(addedPaymentInfo(raw)).toEqual({success:raw.paymentMethodAdded.success,name:raw.paymentMethodAdded.name});});});describe('selectedPaymentInfo()',function(){it('should format tracking data',function(){var raw={paymentMethodSelected:{success:true,name:'Payment method'}};expect(selectedPaymentInfo(raw)).toEqual({success:raw.paymentMethodSelected.success,name:raw.paymentMethodSelected.name});});});});
|
package/helpers/helper.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import DataRequest from'@shopgate/pwa-core/classes/DataRequest';import{logger}from'@shopgate/pwa-core/helpers';import*as _SGAction from'@shopgate/pwa-core/commands/unifiedTracking';export{_SGAction as SGAction};/**
|
|
1
|
+
function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import DataRequest from'@shopgate/pwa-core/classes/DataRequest';import{logger}from'@shopgate/pwa-core/helpers';import*as _SGAction from'@shopgate/pwa-core/commands/unifiedTracking';export{_SGAction as SGAction};/**
|
|
2
2
|
* Decodes a hexadecimal encoded binary string
|
|
3
3
|
* @param {string} str The string that shall be decoded
|
|
4
4
|
* @see http://locutus.io/php/strings/hex2bin/
|
|
@@ -25,11 +25,11 @@ outputUrl+="?".concat(_this.query);}return outputUrl;});this.url=url;this.parseU
|
|
|
25
25
|
*
|
|
26
26
|
* @param {string} string - string to be encoded
|
|
27
27
|
* @return {string}
|
|
28
|
-
*/_createClass(SGLink,[{key:"parseUrl"
|
|
28
|
+
*/_createClass(SGLink,[{key:"parseUrl",value:/**
|
|
29
29
|
* Parses url and extracts path, query, action, splittedPath, ...
|
|
30
30
|
*
|
|
31
31
|
* @param {string} incomingUrl The url that shall be parsed.
|
|
32
|
-
*/
|
|
32
|
+
*/function parseUrl(incomingUrl){var urlToSanitize=incomingUrl;if(!urlToSanitize){urlToSanitize='';}var commonSchemas=['http','https','tel','mailto'];// Based on the regex in RFC2396 Appendix B.
|
|
33
33
|
var parser=/^(?:([^:/?#]+):)?(?:\/\/([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/;var result=urlToSanitize.match(parser);if(!this.isDeepLink&&result[1]&&commonSchemas.indexOf(result[1])===-1){this.isDeepLink=true;var scheme="".concat(result[1],"://");/**
|
|
34
34
|
* Add slash so that we can parse the attributes properly
|
|
35
35
|
* (for shopgate-standalone://cart we would get e.g. "authority: cart" which is wrong)
|
|
@@ -62,11 +62,11 @@ outputUrl+=':/';this.scheme=outputUrl;}if(!this.isDeepLink){outputUrl+='/';}}}el
|
|
|
62
62
|
* Converts the object to relative url
|
|
63
63
|
* @param {boolean} [leadingSlash=true] Tells if the url shall start with a leading slash
|
|
64
64
|
* @return {string}
|
|
65
|
-
*/},{key:"setUtmParams"
|
|
65
|
+
*/},{key:"setUtmParams",value:/**
|
|
66
66
|
* Sets utm param from event.
|
|
67
67
|
* @param {Object} data event data
|
|
68
68
|
* @param {Object} raw event raw data
|
|
69
|
-
*/
|
|
69
|
+
*/function setUtmParams(data,raw){// Add fake params, only if it didn't come from branch.io
|
|
70
70
|
if(raw.type!=='branchio'){this.setParam('utm_source','shopgate');this.setParam('utm_medium',raw.type);}if(raw.type==='push_message'){var campaigns=['cart_reminder','inactive_app_user'];var notificationId=raw.notificationId||'not-provided';var campaignName=this.getParam('utm_campaign');if(campaigns.indexOf(campaignName)!==-1){// Set utm_content to distinguish the cart reminders from "normal" push messages
|
|
71
71
|
this.setParam('utm_content',campaignName);}this.setParam('utm_campaign',"push-".concat(notificationId));}}}],[{key:"encodeURIComponentSafe",value:function encodeURIComponentSafe(string){var decoded=decodeURIComponent(string);if(decoded!==string){return string;}return encodeURIComponent(string);}/**
|
|
72
72
|
* Encode the url and takes care of double encoding
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/tracking-core",
|
|
3
|
-
"version": "6.20.0-beta.
|
|
3
|
+
"version": "6.20.0-beta.8",
|
|
4
4
|
"description": "Tracking core library for the Shopgate Connect PWA.",
|
|
5
5
|
"author": "Shopgate <support@shopgate.com>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"connect"
|
|
17
17
|
],
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@shopgate/eslint-config": "6.20.0-beta.
|
|
20
|
-
"@shopgate/pwa-core": "6.20.0-beta.
|
|
19
|
+
"@shopgate/eslint-config": "6.20.0-beta.8",
|
|
20
|
+
"@shopgate/pwa-core": "6.20.0-beta.8",
|
|
21
21
|
"chai": "^3.5.0",
|
|
22
|
-
"jsdom": "
|
|
22
|
+
"jsdom": "11.1.0",
|
|
23
23
|
"mocha": "^3.1.0",
|
|
24
24
|
"mocha-jsdom": "^1.1.0",
|
|
25
25
|
"nyc": "^11.2.1",
|
package/plugins/Base.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}import SgTrackingCore from"../core/Core";import SgTrackingAppHandler from"../core/AppHandler";import dataFormatHelpers from"../helpers/formatHelpers";import eventNames from"../helpers/events";/**
|
|
1
|
+
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}import SgTrackingCore from"../core/Core";import SgTrackingAppHandler from"../core/AppHandler";import dataFormatHelpers from"../helpers/formatHelpers";import eventNames from"../helpers/events";/**
|
|
2
2
|
* Parent class for all tracking plugins that contains common public functions
|
|
3
3
|
*/var Base=/*#__PURE__*/function(){/**
|
|
4
4
|
* Constructor
|
|
@@ -7,7 +7,7 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
|
|
|
7
7
|
* @param {Object} extendedDefaults Additional default options that are
|
|
8
8
|
* needed by the inherited class
|
|
9
9
|
*/function Base(trackerName){var _this=this;var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var extendedDefaults=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};_classCallCheck(this,Base);var defaults={overrideUnified:false,useNativeSdk:false,useNetPrices:false};// Create the options for the plugin
|
|
10
|
-
this.options=_extends({},defaults,
|
|
10
|
+
this.options=_extends({},defaults,extendedDefaults,options);this.trackingDisabled=false;this.trackerName=trackerName||'';this.trackingCore=SgTrackingCore;this.appHandler=SgTrackingAppHandler;/**
|
|
11
11
|
* Storage that contains functions to register callbacks for the different tracking events
|
|
12
12
|
* @type {Object}
|
|
13
13
|
*/this.register={};eventNames.forEach(function(eventName){/**
|
|
@@ -22,7 +22,7 @@ this.options=_extends({},defaults,{},extendedDefaults,{},options);this.trackingD
|
|
|
22
22
|
* @param {string} eventName Name of the tracking event
|
|
23
23
|
* @param {Object} rawData Raw data from the core
|
|
24
24
|
* @returns {*} The converted data
|
|
25
|
-
*/_createClass(Base,[{key:"registerHelper"
|
|
25
|
+
*/_createClass(Base,[{key:"registerHelper",value:/**
|
|
26
26
|
* Helper function to register a plugin for a specific event. Can be overwritten in the plugins.
|
|
27
27
|
*
|
|
28
28
|
* @param {string} eventName Name of the event
|
|
@@ -30,7 +30,7 @@ this.options=_extends({},defaults,{},extendedDefaults,{},options);this.trackingD
|
|
|
30
30
|
* @param {Object} options Additional options that will be passed to the core
|
|
31
31
|
* @returns {RemoveListener} Function to remove the listener
|
|
32
32
|
* @private
|
|
33
|
-
*/
|
|
33
|
+
*/function registerHelper(eventName,callback,options){var _this2=this;// Register the tracking event of the plugin at the core
|
|
34
34
|
return this.trackingCore.register[eventName](function(data,scope,blacklist,state){// Convert the tracking data into the unified format
|
|
35
35
|
var unifiedData=Base.formatData(eventName,data);// Invoke the event callback of the plugin to enable it to extend the data
|
|
36
36
|
var finalData=callback(unifiedData,data,scope,state);// If final data is explicitly false, it means further processing is up to the plugin only.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
function _typeof(obj){
|
|
1
|
+
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}/* global fbq */import{logger}from'@shopgate/pwa-core/helpers';import BasePlugin from"../Base";/**
|
|
2
2
|
* Tracking plugin for Facebook
|
|
3
|
-
*/var FbPixel=/*#__PURE__*/function(_BasePlugin){_inherits(FbPixel,_BasePlugin);/**
|
|
3
|
+
*/var FbPixel=/*#__PURE__*/function(_BasePlugin){_inherits(FbPixel,_BasePlugin);var _super=_createSuper(FbPixel);/**
|
|
4
4
|
* Constructor
|
|
5
5
|
*
|
|
6
6
|
* @param {Object} options Common Tracking Configuration
|
|
@@ -9,7 +9,7 @@ function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="s
|
|
|
9
9
|
* to the native sdk
|
|
10
10
|
* @param {Object} [options.config] Configuration for facebook pixel tracking
|
|
11
11
|
* @param {Array} [options.config.pixelIds] List of Facebook pixels
|
|
12
|
-
*/function FbPixel(options){var _this;_classCallCheck(this,FbPixel);var trackerName='facebookPixel';var extendedDefaults={config:{pixelIds:[]}};_this=
|
|
12
|
+
*/function FbPixel(options){var _this;_classCallCheck(this,FbPixel);var trackerName='facebookPixel';var extendedDefaults={config:{pixelIds:[]}};_this=_super.call(this,trackerName,options,extendedDefaults);if(_this.options.useNativeSdk){logger.warn('SgFbPixelTracking: no native SDK support for this plugin');return _possibleConstructorReturn(_this);}if(!_this.options.config.pixelIds.length){logger.warn('SgFbPixelTracking: pixels missing');return _possibleConstructorReturn(_this);}_this.initPlugin();return _this;}/**
|
|
13
13
|
* Initiate and setup the SDK
|
|
14
14
|
*/_createClass(FbPixel,[{key:"initPlugin",value:function initPlugin(){var _this2=this;// Load the fb pixel tracking sdk
|
|
15
15
|
/* eslint-disable eslint-comments/no-unlimited-disable */ /* eslint-disable */!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?n.callMethod.apply(n,arguments):n.queue.push(arguments);};if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s);}(window,document,'script','https://connect.facebook.net/en_US/fbevents.js');/* eslint-enable */var pixelsForInit=this.options.config.pixelIds.slice(0);var firstPixel=pixelsForInit.shift();FbPixel.sendToFb(firstPixel.toString(),undefined,'init');/*
|
|
@@ -25,12 +25,12 @@ this.register.completedRegistration(function(data){FbPixel.sendToFb('CompleteReg
|
|
|
25
25
|
* @param {Object} [params] Params for the event
|
|
26
26
|
* @param {string} [typeParam] Type of the tracker call
|
|
27
27
|
* @returns {void}
|
|
28
|
-
*/},{key:"getPrice"
|
|
28
|
+
*/},{key:"getPrice",value:/**
|
|
29
29
|
* Returns the correct price net or gross price. Depending on this.options.useNetPrices
|
|
30
30
|
*
|
|
31
31
|
* @param {Object} amount Price Object
|
|
32
32
|
* @returns {number|string} net or gross price
|
|
33
|
-
*/
|
|
33
|
+
*/function getPrice(amount){if(this.options.useNetPrices){return amount.priceNet||amount.valueNet||amount.net||amount.revenueNet;}return amount.priceGross||amount.valueGross||amount.gross||amount.revenueGross;}/**
|
|
34
34
|
* Returns the params for the AddToCart and AddToWishlist events
|
|
35
35
|
*
|
|
36
36
|
* @param {Object} data Converted data from the parent plugin
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
function _typeof(obj){
|
|
1
|
+
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}import BasePlugin from"../Base";import SgGAUniversalTracking from"./GaUniversal";import SgGAClassicTracking from"./GaClassic";import{SGLink}from"../../helpers/helper";var TRACK_PAGE_VIEW='pageView';var TRACK_EVENT='event';var TRACK_SET='set';var TRACK_REQUIRE='require';var TRACK_CONVERSION={ADDITEM:'addItem',CURRENCY:'currencyCode',END:'trackTrans',START:'addTrans',PAGE:'page'};var ACCOUNT_CLASSIC='classic';var ACCOUNT_UNIVERSAL='universal';var shopgateOnly={merchant:false,shopgate:true};var merchantOnly={merchant:true,shopgate:false};// Command mapping tuple, [classic, universal]
|
|
2
2
|
var commandMapping={};commandMapping[TRACK_PAGE_VIEW]=['trackPageview','pageview'];commandMapping[TRACK_EVENT]=['trackEvent','event'];commandMapping[TRACK_SET]=[undefined,'set'];commandMapping[TRACK_CONVERSION.ADDITEM]=['addItem','ecommerce:addItem'];commandMapping[TRACK_CONVERSION.CURRENCY]=['currencyCode'];commandMapping[TRACK_CONVERSION.END]=['trackTrans','ecommerce:send'];commandMapping[TRACK_CONVERSION.START]=['addTrans','ecommerce:addTransaction'];commandMapping[TRACK_REQUIRE]=[undefined,'require'];/**
|
|
3
3
|
* Parent Tracking plugin for Google Analytics
|
|
4
|
-
*/var GaBase=/*#__PURE__*/function(_BasePlugin){_inherits(GaBase,_BasePlugin);/**
|
|
4
|
+
*/var GaBase=/*#__PURE__*/function(_BasePlugin){_inherits(GaBase,_BasePlugin);var _super=_createSuper(GaBase);/**
|
|
5
5
|
* Constructor
|
|
6
|
-
*/function GaBase(){var _this;_classCallCheck(this,GaBase);_this=
|
|
6
|
+
*/function GaBase(){var _this;_classCallCheck(this,GaBase);_this=_super.call(this,'GAcore',{});// Universal and classic merchant and shopgate accounts
|
|
7
7
|
_this.accounts=[];_this.isRegistered=false;_this.universalPlugin=null;_this.classicPlugin=null;return _this;}/**
|
|
8
8
|
* Returns common data for a custom event
|
|
9
9
|
* @param {string} name Event category
|
|
@@ -16,7 +16,7 @@ _this.accounts=[];_this.isRegistered=false;_this.universalPlugin=null;_this.clas
|
|
|
16
16
|
* nonInteraction: (boolean)
|
|
17
17
|
* }}
|
|
18
18
|
* @private
|
|
19
|
-
*/_createClass(GaBase,[{key:"sendCommand"
|
|
19
|
+
*/_createClass(GaBase,[{key:"sendCommand",value:/**
|
|
20
20
|
* Send command to both universal and classic sdk
|
|
21
21
|
*
|
|
22
22
|
* @param {string} command Name of the command
|
|
@@ -25,7 +25,7 @@ _this.accounts=[];_this.isRegistered=false;_this.universalPlugin=null;_this.clas
|
|
|
25
25
|
* @param {Object} [scope] Scope (merchant or shopgate account)
|
|
26
26
|
* @param {string} [account] Which account to use, classic or universal
|
|
27
27
|
* @private
|
|
28
|
-
*/
|
|
28
|
+
*/function sendCommand(command,payload,scope,account){if(typeof commandMapping[command]==='undefined'){return;}// Evaluate which accounts to send to.
|
|
29
29
|
var isClassic=typeof account==='undefined'||account===ACCOUNT_CLASSIC;var isUniversal=typeof account==='undefined'||account===ACCOUNT_UNIVERSAL;if(isUniversal&&this.universalPlugin!==null){this.universalPlugin.send(commandMapping[command][1],payload,scope);}if(isClassic&&this.classicPlugin!==null){this.classicPlugin.send(commandMapping[command][0],payload,scope);}}/**
|
|
30
30
|
* Helper to register for some events
|
|
31
31
|
* @private
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}/* global _gaq */ /**
|
|
1
|
+
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}/* global _gaq */ /**
|
|
2
2
|
* Tracking plugin for google analytics classic accounts
|
|
3
3
|
*/var GaClassic=/*#__PURE__*/function(){/**
|
|
4
4
|
* Constructor
|
|
@@ -22,13 +22,13 @@ _gaq.push(['_gat._anonymizeIp',true],['_gat._forceSSL',true]);}/**
|
|
|
22
22
|
*
|
|
23
23
|
* @param {string} id Id of the account
|
|
24
24
|
* @returns {string} Prefix for the account
|
|
25
|
-
*/},{key:"send"
|
|
25
|
+
*/},{key:"send",value:/**
|
|
26
26
|
* Function that sends the given command with the payload to the GA SDK
|
|
27
27
|
* @param {string} command Name of the command
|
|
28
28
|
* @param {Object|Array|string|Function} payload Data for the command,
|
|
29
29
|
* or a function that returns data
|
|
30
30
|
* @param {Object} [scope={}] Info if the event is for merchant and/or shopgate account
|
|
31
|
-
*/
|
|
31
|
+
*/function send(command,payload){var _this=this;var scope=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};var defaults={merchant:true,shopgate:true};var mergedScope=_extends({},defaults,scope);/**
|
|
32
32
|
* Since we migrates all our classic account to universal,
|
|
33
33
|
* Only the merchant can have classic accounts
|
|
34
34
|
*/if(mergedScope.merchant){this.merchantAccounts.forEach(function(account,index){var data=typeof payload==='function'?payload(account):payload;data=typeof _this.filters[command]!=='undefined'?_this.filters[command](data):data;var cmd="".concat(GaClassic.buildMerchantPrefix(index?account.id:''),"._").concat(command);if(Array.isArray(data)){_gaq.push([cmd].concat(data));}else{_gaq.push([cmd,data]);}});}}}],[{key:"buildMerchantPrefix",value:function buildMerchantPrefix(id){return"merchant_".concat(id);}}]);return GaClassic;}();export default GaClassic;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}/* global ga */ // SgData access type constant for apps
|
|
1
|
+
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}/* global ga */ // SgData access type constant for apps
|
|
2
2
|
var ACCESS_TYPE_APP='App';/**
|
|
3
3
|
* Dimensions and metrics
|
|
4
4
|
* See: https://shopgate.atlassian.net/wiki/display/CONSUMER/Google+Analytics
|
|
@@ -41,6 +41,6 @@ ga('shopgate.set',DIMENSION_SHOP_NUMBER,this.options.shopNumber||window.sgData.s
|
|
|
41
41
|
* @param {Object|Array|string|Function} payload Data for the command,
|
|
42
42
|
* or a function that returns data
|
|
43
43
|
* @param {Object} [scope={}] Info if the event is for merchant and/or shopgate account
|
|
44
|
-
*/},{key:"send",value:function send(command,payload){var _this2=this;var scope=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};var defaults={merchant:true,shopgate:true};var useSendCmd=command!=='require'&&command!=='set'&&command.indexOf(':')===-1;var mergedScope=_extends({},defaults,
|
|
44
|
+
*/},{key:"send",value:function send(command,payload){var _this2=this;var scope=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};var defaults={merchant:true,shopgate:true};var useSendCmd=command!=='require'&&command!=='set'&&command.indexOf(':')===-1;var mergedScope=_extends({},defaults,scope);if(mergedScope.merchant){this.merchantAccounts.forEach(function(account){var data=typeof payload==='function'?payload(account):payload;data=typeof _this2.filters[command]!=='undefined'?_this2.filters[command](data):data;var merchantPrefix=_this2.buildMerchantPrefix(account.id);var cmd=[command];if(useSendCmd){cmd.unshift("".concat(merchantPrefix,".send"));}else{// We don't need the send command for example for ecommerce:addTransaction
|
|
45
45
|
cmd[0]="".concat(merchantPrefix,".").concat(cmd[0]);}if(typeof data==='undefined'){ga.apply(void 0,cmd.slice());}else if(Array.isArray(data)){ga.apply(void 0,cmd.slice().concat(data));}else{ga.apply(void 0,cmd.slice().concat([data]));}});}if(mergedScope.shopgate){var data=typeof payload==='function'?payload(this.shopgateAccount):payload;data=typeof this.filters[command]!=='undefined'?this.filters[command](data):data;var cmd=[command];if(useSendCmd){cmd.unshift('shopgate.send');}else{// We don't need the send command for example for ecommerce:addTransaction
|
|
46
46
|
cmd[0]="shopgate.".concat(cmd[0]);}if(typeof data==='undefined'){ga.apply(void 0,cmd.slice());}else if(Array.isArray(data)){ga.apply(void 0,cmd.slice().concat(data));}else{ga.apply(void 0,cmd.slice().concat([data]));}}}}]);return GaUniversal;}();export default GaUniversal;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
function _typeof(obj){
|
|
1
|
+
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}import{sendDataRequest}from"../../helpers/helper";import BasePlugin from"../Base";/**
|
|
2
2
|
* Tracking Plugin for our unified tracking system
|
|
3
|
-
*/var Unified=/*#__PURE__*/function(_BasePlugin){_inherits(Unified,_BasePlugin);/**
|
|
3
|
+
*/var Unified=/*#__PURE__*/function(_BasePlugin){_inherits(Unified,_BasePlugin);var _super=_createSuper(Unified);/**
|
|
4
4
|
* @param {Object} [options] configuration
|
|
5
5
|
*/function Unified(){var _this;var options=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};_classCallCheck(this,Unified);var trackerName=options.trackerName||'unified';// Invoke the parent constructor
|
|
6
|
-
_this=
|
|
6
|
+
_this=_super.call(this,trackerName,options);_this.register.viewContent(function(data){return data;});_this.register.setCampaignWithUrl(function(data){return data;});_this.register.purchase(function(data){return data;});_this.register.addToCart(function(data){return data;});_this.register.initiatedCheckout(function(data){return data;});_this.register.completedRegistration(function(data){return data;});_this.register.addToWishlist(function(data){return data;});_this.register.search(function(data){return data;});_this.register.addedPaymentInfo(function(data){return data;});_this.trackingCore.register.removeTracker(function(){// Send request to server to remove the tracker
|
|
7
7
|
sendDataRequest('remove_unified_trackers');},{trackerName:_this.trackerName,options:_this.options});_this.trackingCore.register.addTracker(function(){// Send request to server to add the tracker again
|
|
8
8
|
sendDataRequest('add_unified_trackers');},{trackerName:_this.trackerName,options:_this.options});return _this;}/**
|
|
9
9
|
* Helper function to register a plugin for a specific event. Overwrites the parent function with
|