@shopgate/tracking-core 7.30.0-alpha.6 → 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
package/core/AppHandler.js
CHANGED
|
@@ -1,89 +1,191 @@
|
|
|
1
|
-
|
|
1
|
+
import { SGAction } from "../helpers/helper";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Handler for the communication between the tracking plugins and the app.
|
|
3
|
-
*/
|
|
5
|
+
*/
|
|
6
|
+
class AppHandler {
|
|
7
|
+
/**
|
|
4
8
|
* Log a pageview
|
|
5
9
|
*
|
|
6
10
|
* @param {UnifiedPageview} data Tracking data for this event
|
|
7
11
|
* @param {UnifiedRestrictions} [restrictions] Info about the restrictions
|
|
8
12
|
* @returns {AppHandler} Instance of SgTrackingAppHandler
|
|
9
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
viewContent(data, restrictions) {
|
|
15
|
+
SGAction.analyticsLogPageview(AppHandler.prepareTrackingData(data, restrictions));
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
10
20
|
* AnalyticsLogEvent
|
|
11
21
|
* @param {UnifiedPageview} data Tracking data for this event
|
|
12
22
|
* @param {UnifiedRestrictions} [restrictions] Info about the restrictions
|
|
13
23
|
* @returns {AppHandler} Instance of SgTrackingAppHandler
|
|
14
|
-
*/
|
|
24
|
+
*/
|
|
25
|
+
logEvent(data, restrictions) {
|
|
26
|
+
SGAction.analyticsLogEvent(AppHandler.prepareTrackingData(data, restrictions));
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
15
31
|
* Log a purchase
|
|
16
32
|
*
|
|
17
33
|
* @param {UnifiedPurchase} data Tracking data for this event
|
|
18
34
|
* @param {UnifiedRestrictions} [restrictions] Info about the restrictions
|
|
19
35
|
* @returns {AppHandler} Instance of SgTrackingAppHandler
|
|
20
|
-
*/
|
|
36
|
+
*/
|
|
37
|
+
purchase(data, restrictions) {
|
|
38
|
+
SGAction.analyticsLogPurchase(AppHandler.prepareTrackingData(data, restrictions));
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
21
43
|
* Log when a product was added to the cart
|
|
22
44
|
*
|
|
23
45
|
* @param {UnifiedAddToCart} data Tracking data for this event
|
|
24
46
|
* @param {UnifiedRestrictions} [restrictions] Info about the restrictions
|
|
25
47
|
* @returns {AppHandler} Instance of SgTrackingAppHandler
|
|
26
|
-
*/
|
|
48
|
+
*/
|
|
49
|
+
addToCart(data, restrictions) {
|
|
50
|
+
SGAction.analyticsLogAddToCart(AppHandler.prepareTrackingData(data, restrictions));
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
27
55
|
* Log when a payment info was added
|
|
28
56
|
*
|
|
29
57
|
* @param {UnifiedPaymentInfo} data Tracking data for this event
|
|
30
58
|
* @param {UnifiedRestrictions} [restrictions] Info about the restrictions
|
|
31
59
|
* @returns {AppHandler} Instance of SgTrackingAppHandler
|
|
32
|
-
*/
|
|
60
|
+
*/
|
|
61
|
+
addedPaymentInfo(data, restrictions) {
|
|
62
|
+
SGAction.analyticsLogAddedPaymentInfo(AppHandler.prepareTrackingData(data, restrictions));
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
33
67
|
* Log when a payment info was selected
|
|
34
68
|
*
|
|
35
69
|
* @param {UnifiedPaymentInfo} data Tracking data for this event
|
|
36
70
|
* @param {UnifiedRestrictions} [restrictions] Info about the restrictions
|
|
37
71
|
* @returns {AppHandler} Instance of SgTrackingAppHandler
|
|
38
|
-
*/
|
|
72
|
+
*/
|
|
73
|
+
selectedPaymentInfo(data, restrictions) {
|
|
74
|
+
SGAction.analyticsLogAddedPaymentInfo(AppHandler.prepareTrackingData(data, restrictions));
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
39
79
|
* Log when a checkout is initiated
|
|
40
80
|
*
|
|
41
81
|
* @param {UnifiedInitiatedCheckout} data Tracking data for this event
|
|
42
82
|
* @param {UnifiedRestrictions} [restrictions] Info about the restrictions
|
|
43
83
|
* @returns {AppHandler} Instance of SgTrackingAppHandler
|
|
44
|
-
*/
|
|
84
|
+
*/
|
|
85
|
+
initiatedCheckout(data, restrictions) {
|
|
86
|
+
SGAction.analyticsLogInitiatedCheckout(AppHandler.prepareTrackingData(data, restrictions));
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
45
91
|
* Log if a registration was completed
|
|
46
92
|
*
|
|
47
93
|
* @param {UnifiedCompletedRegistration} data Tracking data for this event
|
|
48
94
|
* @param {UnifiedRestrictions} [restrictions] Info about the restrictions
|
|
49
95
|
* @returns {AppHandler} Instance of SgTrackingAppHandler
|
|
50
|
-
*/
|
|
96
|
+
*/
|
|
97
|
+
completedRegistration(data, restrictions) {
|
|
98
|
+
SGAction.analyticsLogCompletedRegistration(AppHandler.prepareTrackingData(data, restrictions));
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
51
103
|
* Log when a product was added to the wishlist
|
|
52
104
|
*
|
|
53
105
|
* @param {UnifiedAddToWishlist} data Tracking data for this event
|
|
54
106
|
* @param {UnifiedRestrictions} [restrictions] Info about the restrictions
|
|
55
107
|
* @returns {AppHandler} Instance of SgTrackingAppHandler
|
|
56
|
-
*/
|
|
108
|
+
*/
|
|
109
|
+
addToWishlist(data, restrictions) {
|
|
110
|
+
SGAction.analyticsLogAddToWishlist(AppHandler.prepareTrackingData(data, restrictions));
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
57
115
|
* Log when a search happened
|
|
58
116
|
*
|
|
59
117
|
* @param {UnifiedSearched} data Tracking data for this event
|
|
60
118
|
* @param {UnifiedRestrictions} [restrictions] Info about the restrictions
|
|
61
119
|
* @returns {AppHandler} Instance of SgTrackingAppHandler
|
|
62
|
-
*/
|
|
120
|
+
*/
|
|
121
|
+
search(data, restrictions) {
|
|
122
|
+
SGAction.analyticsLogSearch(AppHandler.prepareTrackingData(data, restrictions));
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
63
127
|
* Log when Deeplink and etc opened
|
|
64
128
|
* @param {Object} data Tracking data for this event
|
|
65
129
|
* @param {UnifiedRestrictions} [restrictions] Info about the restrictions
|
|
66
130
|
* @returns {AppHandler} Instance of SgTrackingAppHandler
|
|
67
|
-
*/
|
|
131
|
+
*/
|
|
132
|
+
setCampaignWithUrl(data, restrictions) {
|
|
133
|
+
SGAction.analyticsSetCampaignWithUrl(AppHandler.prepareTrackingData(data, restrictions));
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
68
138
|
* Log an itemview
|
|
69
139
|
*
|
|
70
140
|
* @param {UnifiedItemView} data Tracking data for this event
|
|
71
141
|
* @param {UnifiedRestrictions} [restrictions] Info about the restrictions
|
|
72
142
|
* @returns {AppHandler} Instance of SgTrackingAppHandler
|
|
73
|
-
*/
|
|
143
|
+
*/
|
|
144
|
+
itemView(data, restrictions) {
|
|
145
|
+
SGAction.analyticsLogItemView(AppHandler.prepareTrackingData(data, restrictions));
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
74
150
|
* Log a login
|
|
75
151
|
*
|
|
76
152
|
* @param {UnifiedLogin} data Tracking data for this event
|
|
77
153
|
* @param {UnifiedRestrictions} [restrictions] Info about the restrictions
|
|
78
154
|
* @returns {AppHandler} Instance of SgTrackingAppHandler
|
|
79
|
-
*/
|
|
155
|
+
*/
|
|
156
|
+
login(data, restrictions) {
|
|
157
|
+
SGAction.analyticsLogLogin(AppHandler.prepareTrackingData(data, restrictions));
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
80
162
|
* Add the properties restriction, blacklist and trackers to the tracking event data if needed
|
|
81
163
|
*
|
|
82
164
|
* @param {Object} data The tracking event data
|
|
83
165
|
* @param {UnifiedRestrictions} [restrictions] Info about the restrictions
|
|
84
166
|
* @returns {Object} Tracking data with restrictions
|
|
85
167
|
* @private
|
|
86
|
-
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
168
|
+
*/
|
|
169
|
+
static prepareTrackingData(data, restrictions) {
|
|
170
|
+
// Clone the data to avoid issues with references.
|
|
171
|
+
const clonedData = {
|
|
172
|
+
...data
|
|
173
|
+
};
|
|
174
|
+
if (restrictions && restrictions.trackers) {
|
|
175
|
+
let trackerParamName = 'trackers';
|
|
176
|
+
|
|
177
|
+
// There is a Bug in the iOS app. Lib Version <= 9.0 expects "tracker" as the param name.
|
|
178
|
+
if (window.LibShopgateClient && window.LibShopgateClient.isIos() && window.LibShopgateVersion && window.LibShopgateVersion.isLibVersionAtMost(9)) {
|
|
179
|
+
trackerParamName = 'tracker';
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Add the restrictions to the tracking event data.
|
|
183
|
+
clonedData.restrictions = {
|
|
184
|
+
blacklist: restrictions.blacklist,
|
|
185
|
+
[trackerParamName]: restrictions.trackers
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
return clonedData;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
export default new AppHandler();
|