@shopgate/tracking-core 7.30.0-alpha.7 → 7.30.0-alpha.9

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.
@@ -1,11 +1,44 @@
1
- function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _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);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}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 _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}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}});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);}import{sendDataRequest}from"../../helpers/helper";import BasePlugin from"../Base";/**
1
+ import { sendDataRequest } from "../../helpers/helper";
2
+ import BasePlugin from "../Base";
3
+
4
+ /**
2
5
  * Tracking Plugin for our unified tracking system
3
- */var Unified=/*#__PURE__*/function(_BasePlugin){/**
6
+ */
7
+ class Unified extends BasePlugin {
8
+ /**
4
9
  * @param {Object} [options] configuration
5
- */function Unified(){var _this2;var options=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};_classCallCheck(this,Unified);var trackerName=options.trackerName||'unified';// Invoke the parent constructor
6
- _this2=_callSuper(this,Unified,[trackerName,options]);_this2.register.viewContent(function(data){return data;});_this2.register.setCampaignWithUrl(function(data){return data;});_this2.register.purchase(function(data){return data;});_this2.register.addToCart(function(data){return data;});_this2.register.initiatedCheckout(function(data){return data;});_this2.register.completedRegistration(function(data){return data;});_this2.register.addToWishlist(function(data){return data;});_this2.register.search(function(data){return data;});_this2.register.addedPaymentInfo(function(data){return data;});_this2.trackingCore.register.removeTracker(function(){// Send request to server to remove the tracker
7
- sendDataRequest('remove_unified_trackers');},{trackerName:_this2.trackerName,options:_this2.options});_this2.trackingCore.register.addTracker(function(){// Send request to server to add the tracker again
8
- sendDataRequest('add_unified_trackers');},{trackerName:_this2.trackerName,options:_this2.options});return _this2;}/**
10
+ */
11
+ constructor(options = {}) {
12
+ const trackerName = options.trackerName || 'unified';
13
+
14
+ // Invoke the parent constructor
15
+ super(trackerName, options);
16
+ this.register.viewContent(data => data);
17
+ this.register.setCampaignWithUrl(data => data);
18
+ this.register.purchase(data => data);
19
+ this.register.addToCart(data => data);
20
+ this.register.initiatedCheckout(data => data);
21
+ this.register.completedRegistration(data => data);
22
+ this.register.addToWishlist(data => data);
23
+ this.register.search(data => data);
24
+ this.register.addedPaymentInfo(data => data);
25
+ this.trackingCore.register.removeTracker(() => {
26
+ // Send request to server to remove the tracker
27
+ sendDataRequest('remove_unified_trackers');
28
+ }, {
29
+ trackerName: this.trackerName,
30
+ options: this.options
31
+ });
32
+ this.trackingCore.register.addTracker(() => {
33
+ // Send request to server to add the tracker again
34
+ sendDataRequest('add_unified_trackers');
35
+ }, {
36
+ trackerName: this.trackerName,
37
+ options: this.options
38
+ });
39
+ }
40
+
41
+ /**
9
42
  * Helper function to register a plugin for a specific event. Overwrites the parent function with
10
43
  * special logic for the blacklist system.
11
44
  *
@@ -13,8 +46,31 @@ sendDataRequest('add_unified_trackers');},{trackerName:_this2.trackerName,option
13
46
  * @param {Function} callback Callback from the plugin, to modify the data
14
47
  * @returns {RemoveListener} Function to remove the listener
15
48
  * @private
16
- */_inherits(Unified,_BasePlugin);return _createClass(Unified,[{key:"registerHelper",value:function registerHelper(eventName,callback){var _this3=this;// Register the tracking event of the plugin at the core
17
- return this.trackingCore.register[eventName](function(data,scope,blacklist,state){if(typeof _this3.appHandler[eventName]!=='function'){console.warn("this.appHandler[".concat(eventName,"] is not a function"));return;}// Convert the tracking data into the unified format
18
- var unifiedData=BasePlugin.formatData(eventName,data);// Invoke the event callback of the plugin to enable it to extend the data
19
- var finalData=callback(unifiedData,data,scope,state);// Send command to the app via the appHandler
20
- _this3.appHandler[eventName](finalData,{blacklist:true,trackers:blacklist});},{trackerName:this.trackerName,options:this.options});}}]);}(BasePlugin);window.SgUnifiedTracking=Unified;export default Unified;
49
+ */
50
+ registerHelper(eventName, callback) {
51
+ // Register the tracking event of the plugin at the core
52
+ return this.trackingCore.register[eventName]((data, scope, blacklist, state) => {
53
+ if (typeof this.appHandler[eventName] !== 'function') {
54
+ console.warn(`this.appHandler[${eventName}] is not a function`);
55
+ return;
56
+ }
57
+
58
+ // Convert the tracking data into the unified format
59
+ const unifiedData = BasePlugin.formatData(eventName, data);
60
+
61
+ // Invoke the event callback of the plugin to enable it to extend the data
62
+ const finalData = callback(unifiedData, data, scope, state);
63
+
64
+ // Send command to the app via the appHandler
65
+ this.appHandler[eventName](finalData, {
66
+ blacklist: true,
67
+ trackers: blacklist
68
+ });
69
+ }, {
70
+ trackerName: this.trackerName,
71
+ options: this.options
72
+ });
73
+ }
74
+ }
75
+ window.SgUnifiedTracking = Unified;
76
+ export default Unified;
package/typedef.js CHANGED
@@ -1,13 +1,17 @@
1
1
  /**
2
2
  * Data definitions of the multiple tracking events
3
- */ /**
3
+ */
4
+
5
+ /**
4
6
  * Data definition for a pageview event within the unified tracking system
5
7
  * @typedef {Object} UnifiedPageview
6
8
  * @property {string} type The type of the current page. Something like "Product" or "Checkout"
7
9
  * @property {string} id A unique identifier for the current page, like an item number or page title
8
10
  * @property {string} name A name to easier distinguish this item in the tracking tool
9
11
  * @property {UnifiedRestrictions} [restrictions] Restrictions for the command
10
- */ /**
12
+ */
13
+
14
+ /**
11
15
  * Data definition for a search event within the unified tracking system
12
16
  * @typedef {Object} UnifiedSearch
13
17
  * @property {string} [query] The query string that has been used for the string
@@ -15,7 +19,9 @@
15
19
  * @property {string} [type] The type of the content that has been searched
16
20
  * @property {number} [hits] Amount of hits, the search brought
17
21
  * @property {UnifiedRestrictions} [restrictions] Restrictions for the command
18
- */ /**
22
+ */
23
+
24
+ /**
19
25
  * Data definition for a purchase event within the unified tracking system
20
26
  * @typedef {Object} UnifiedPurchase
21
27
  * @property {string} id A unique ID representing the transaction.
@@ -34,7 +40,9 @@
34
40
  * @property {string} [type] Type of checkout
35
41
  * @property {boolean} [success] Whether the Purchase was successful, or not
36
42
  * @property {UnifiedRestrictions} [restrictions] Restrictions for the command
37
- */ /**
43
+ */
44
+
45
+ /**
38
46
  * Data definition for a custom event within the unified tracking system
39
47
  * @typedef {Object} UnifiedCustomEvent
40
48
  * @property {string} eventCategory The event category
@@ -42,24 +50,32 @@
42
50
  * @property {string} [eventLabel] The event label
43
51
  * @property {number} [eventValue] The event value
44
52
  * @property {boolean} [nonInteraction] If the event was triggered by a user interaction
45
- */ /**
53
+ */
54
+
55
+ /**
46
56
  * Data definition for an addToCart event within the unified tracking system
47
57
  * @typedef {Object} UnifiedAddToCart
48
58
  * @property {UnifiedAddToCartItem[]} items Array of unified items
49
59
  * @property {string} position Position where the add to cart took place
50
60
  * @property {UnifiedRestrictions} [restrictions] Restrictions for the command
51
- */ /**
61
+ */
62
+
63
+ /**
52
64
  * Data definition for an addToWishlist event within the unified tracking system
53
65
  * @typedef {Object} UnifiedAddToWishlist
54
66
  * @property {UnifiedAddToWishlistItem[]} items Array of unified wishlist items
55
67
  * @property {UnifiedRestrictions} [restrictions] Restrictions for the command
56
- */ /**
68
+ */
69
+
70
+ /**
57
71
  * Data definition for an addedPaymentInfo event within the unified tracking system
58
72
  * @typedef {Object} UnifiedPaymentInfo
59
73
  * @property {bool} success If it was success or not
60
74
  * @property {string} name Name of the payment method
61
75
  * @property {UnifiedRestrictions} [restrictions] Restrictions for the command
62
- */ /**
76
+ */
77
+
78
+ /**
63
79
  * Data definition for an InitiatedCheckout event within the unified tracking system
64
80
  * @typedef {Object} UnifiedInitiatedCheckout
65
81
  * @property {number} valueNet The net value of the items in the cart
@@ -69,9 +85,13 @@
69
85
  * @property {boolean} [paymentInfoAvailable] Whether the paymentInfo is available
70
86
  * @property {string} [currency] The currency code as ISO 4217 string.
71
87
  * @property {UnifiedRestrictions} [restrictions] Restrictions for the command
72
- */ /**
88
+ */
89
+
90
+ /**
73
91
  * Data definitions of item data for the multiple tracking events
74
- */ /**
92
+ */
93
+
94
+ /**
75
95
  * Data definition for a purchase item within the unified tracking system
76
96
  * @typedef {Object} UnifiedPurchaseItem
77
97
  * @property {string} type The type of the item, eg "product"
@@ -84,7 +104,9 @@
84
104
  * @property {number} [quantity] The quantity of the product. If not set, the value is set to 1
85
105
  * @property {string} [categoryId] The unique identifier of the category the product belongs
86
106
  * @property {string} [categoryName] Human readable name of the category the product belongs
87
- */ /**
107
+ */
108
+
109
+ /**
88
110
  * Data definition for an addToCart item within the unified tracking system
89
111
  * @typedef {Object} UnifiedAddToCartItem
90
112
  * @property {string} type The type of the item, eg "product"
@@ -98,13 +120,17 @@
98
120
  * @property {string} [categoryName] Human readable name of the category the product belongs
99
121
  * @property {string} [brand] The brand of the product
100
122
  * @property {string} [couponCode] Position where the add to cart took place
101
- */ /**
123
+ */
124
+
125
+ /**
102
126
  * Data definition for a completedRegistration within the unified tracking system
103
127
  * @typedef {Object} UnifiedCompletedRegistration
104
128
  * @property {string} registrationMethod The type of the registration
105
129
  * (default_account, guest_account, facebook, 'connect_register')
106
130
  * @property {UnifiedRestrictions} [restrictions] Restrictions for the command
107
- */ /**
131
+ */
132
+
133
+ /**
108
134
  * Data definition for an addToWishlist item within the unified tracking system
109
135
  * @typedef {Object} UnifiedAddToWishlistItem
110
136
  * @property {number} priceNet The net price of the product
@@ -116,7 +142,9 @@
116
142
  * @property {string} type The type of the item, eg "product"
117
143
  * @property {string} name The name of the item
118
144
  * @property {string} [brand] The brand of the product
119
- */ /**
145
+ */
146
+
147
+ /**
120
148
  * Data definition for an search event within the unified tracking system
121
149
  * @typedef {Object} UnifiedSearched
122
150
  * @property {string} [query] The query string that has been used for the search
@@ -124,12 +152,18 @@
124
152
  * @property {string} [type] The type of the content that has been searched
125
153
  * @property {number} [hits] Amount of hits, the search brought.
126
154
  * @property {UnifiedRestrictions} [restrictions] Restrictions for the command
127
- */ /**
155
+ */
156
+
157
+ /**
128
158
  * @typedef {Object} RemoveListener
129
159
  * @property {Function} remove Function to remove the listener for a tracking event
130
- */ /**
160
+ */
161
+
162
+ /**
131
163
  * Additional definitions of data for the multiple tracking events
132
- */ /**
164
+ */
165
+
166
+ /**
133
167
  * Restrictions for a unified tracking command
134
168
  * @typedef {Object} UnifiedRestrictions
135
169
  * @property {boolean} blacklist If set to TRUE, this event is not sent to the trackers named