@shopgate/tracking-core 7.30.0-alpha.7 → 7.30.0-alpha.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 +121 -19
- package/core/Core.js +337 -82
- package/helpers/events.js +46 -7
- package/helpers/formatHelpers.js +324 -49
- package/helpers/helper.js +247 -36
- package/helpers/optOut.js +114 -13
- package/helpers/urlMapping.js +110 -14
- package/package.json +3 -3
- package/plugins/Base.js +94 -17
- package/plugins/trackers/FbPixel.js +186 -17
- package/plugins/trackers/GaBase.js +250 -31
- package/plugins/trackers/GaClassic.js +93 -13
- package/plugins/trackers/GaUniversal.js +162 -16
- package/plugins/trackers/Unified.js +67 -11
- package/typedef.js +51 -17
|
@@ -1,11 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
import { sendDataRequest } from "../../helpers/helper";
|
|
2
|
+
import BasePlugin from "../Base";
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* Tracking Plugin for our unified tracking system
|
|
3
|
-
*/
|
|
6
|
+
*/
|
|
7
|
+
class Unified extends BasePlugin {
|
|
8
|
+
/**
|
|
4
9
|
* @param {Object} [options] configuration
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|