@mparticle/web-taplytics-kit 2.0.2 → 3.1.0
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/dist/TaplyticsKit.common.js +516 -447
- package/package.json +7 -3
- package/CHANGELOG.md +0 -9
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/*!
|
|
4
|
+
* isobject <https://github.com/jonschlinkert/isobject>
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
7
|
+
* Released under the MIT License.
|
|
8
|
+
*/
|
|
4
9
|
|
|
5
|
-
|
|
6
|
-
return
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
var isobject = function isObject(val) {
|
|
10
|
-
return val != null && typeof val === 'object' && isarray(val) === false;
|
|
11
|
-
};
|
|
10
|
+
function isObject(val) {
|
|
11
|
+
return val != null && typeof val === 'object' && Array.isArray(val) === false;
|
|
12
|
+
}
|
|
12
13
|
|
|
13
14
|
/* eslint-disable no-undef */
|
|
14
15
|
|
|
@@ -27,307 +28,298 @@ var isobject = function isObject(val) {
|
|
|
27
28
|
// See the License for the specific language governing permissions and
|
|
28
29
|
// limitations under the License.
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var name = 'Taplytics',
|
|
33
|
-
moduleId = 129,
|
|
34
|
-
MessageType = {
|
|
35
|
-
SessionStart: 1,
|
|
36
|
-
SessionEnd: 2,
|
|
37
|
-
PageView: 3,
|
|
38
|
-
PageEvent: 4,
|
|
39
|
-
CrashReport: 5,
|
|
40
|
-
OptOut: 6,
|
|
41
|
-
Commerce: 16
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
var constructor = function () {
|
|
45
|
-
var self = this,
|
|
46
|
-
isInitialized = false,
|
|
47
|
-
reportingService,
|
|
48
|
-
eventQueue = [],
|
|
49
|
-
settings = {},
|
|
50
|
-
initUserAttributes = {},
|
|
51
|
-
initUserIdentities = [];
|
|
52
31
|
|
|
53
|
-
self.name = name;
|
|
54
32
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
33
|
+
var name = 'Taplytics',
|
|
34
|
+
moduleId = 129,
|
|
35
|
+
MessageType = {
|
|
36
|
+
SessionStart: 1,
|
|
37
|
+
SessionEnd: 2,
|
|
38
|
+
PageView: 3,
|
|
39
|
+
PageEvent: 4,
|
|
40
|
+
CrashReport: 5,
|
|
41
|
+
OptOut: 6,
|
|
42
|
+
Commerce: 16,
|
|
43
|
+
};
|
|
60
44
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
45
|
+
var constructor = function() {
|
|
46
|
+
var self = this,
|
|
47
|
+
isInitialized = false,
|
|
48
|
+
reportingService,
|
|
49
|
+
eventQueue = [],
|
|
50
|
+
settings = {},
|
|
51
|
+
initUserAttributes = {},
|
|
52
|
+
initUserIdentities = [];
|
|
53
|
+
|
|
54
|
+
self.name = name;
|
|
55
|
+
|
|
56
|
+
function initForwarder(
|
|
57
|
+
forwarderSettings,
|
|
58
|
+
service,
|
|
59
|
+
testMode,
|
|
60
|
+
trackerId,
|
|
61
|
+
userAttributes,
|
|
62
|
+
userIdentities
|
|
63
|
+
) {
|
|
64
|
+
reportingService = service;
|
|
65
|
+
settings = forwarderSettings;
|
|
66
|
+
initUserAttributes = userAttributes;
|
|
67
|
+
initUserIdentities = userIdentities;
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
if (!testMode && !window.Taplytics) {
|
|
71
|
+
var taplyticsScript = document.createElement('script');
|
|
72
|
+
taplyticsScript.type = 'text/javascript';
|
|
73
|
+
taplyticsScript.async = true;
|
|
74
|
+
taplyticsScript.src = getTaplyticsSourceLink();
|
|
75
|
+
(
|
|
76
|
+
document.getElementsByTagName('head')[0] ||
|
|
77
|
+
document.getElementsByTagName('body')[0]
|
|
78
|
+
).appendChild(taplyticsScript);
|
|
79
|
+
taplyticsScript.onload = function() {
|
|
85
80
|
isInitialized = true;
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
|
|
82
|
+
// On load, if the clientsdk exists and there are events
|
|
83
|
+
// in the eventQueue, process each event
|
|
84
|
+
if (window.Taplytics && eventQueue.length > 0) {
|
|
85
|
+
// Process any events that may have been queued up
|
|
86
|
+
// while forwarder was being initialized.
|
|
87
|
+
eventQueue.forEach(function(event) {
|
|
88
|
+
processEvent(event);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
eventQueue = [];
|
|
88
92
|
}
|
|
93
|
+
};
|
|
94
|
+
} else {
|
|
95
|
+
isInitialized = true;
|
|
96
|
+
if (testMode) {
|
|
97
|
+
Taplytics.src = getTaplyticsSourceLink();
|
|
89
98
|
}
|
|
90
|
-
|
|
91
|
-
return 'Taplytics successfully loaded';
|
|
92
99
|
}
|
|
93
|
-
catch (e) {
|
|
94
|
-
return 'Failed to initialize: ' + e;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
100
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
function processEvent(event) {
|
|
104
|
-
var reportEvent = false;
|
|
105
|
-
if (isInitialized) {
|
|
106
|
-
try {
|
|
107
|
-
if (event.EventDataType === MessageType.PageView) {
|
|
108
|
-
reportEvent = logPageView(event);
|
|
109
|
-
} else if (event.EventDataType === MessageType.Commerce) {
|
|
110
|
-
if (event.EventCategory === mParticle.CommerceEventType.ProductPurchase) {
|
|
111
|
-
reportEvent = logPurchaseEvent(event);
|
|
112
|
-
} else {
|
|
113
|
-
reportEvent = logCommerceEvent(event);
|
|
114
|
-
}
|
|
115
|
-
} else if (event.EventDataType === MessageType.PageEvent) {
|
|
116
|
-
reportEvent = logEvent(event);
|
|
117
|
-
}
|
|
101
|
+
return 'Taplytics successfully loaded';
|
|
102
|
+
} catch (e) {
|
|
103
|
+
return 'Failed to initialize: ' + e;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
118
106
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Called whenever an event occurs. Used to log different types of events.
|
|
109
|
+
* @param event
|
|
110
|
+
* @returns {string}
|
|
111
|
+
*/
|
|
112
|
+
function processEvent(event) {
|
|
113
|
+
var reportEvent = false;
|
|
114
|
+
if (isInitialized) {
|
|
115
|
+
try {
|
|
116
|
+
if (event.EventDataType === MessageType.PageView) {
|
|
117
|
+
reportEvent = logPageView(event);
|
|
118
|
+
} else if (event.EventDataType === MessageType.Commerce) {
|
|
119
|
+
if (
|
|
120
|
+
event.EventCategory ===
|
|
121
|
+
mParticle.CommerceEventType.ProductPurchase
|
|
122
|
+
) {
|
|
123
|
+
reportEvent = logPurchaseEvent(event);
|
|
123
124
|
} else {
|
|
124
|
-
|
|
125
|
+
reportEvent = logCommerceEvent(event);
|
|
125
126
|
}
|
|
127
|
+
} else if (event.EventDataType === MessageType.PageEvent) {
|
|
128
|
+
reportEvent = logEvent(event);
|
|
126
129
|
}
|
|
127
|
-
|
|
128
|
-
|
|
130
|
+
|
|
131
|
+
// leave the below alone
|
|
132
|
+
if (reportEvent === true && reportingService) {
|
|
133
|
+
reportingService(self, event);
|
|
134
|
+
return 'Successfully sent to ' + name;
|
|
135
|
+
} else {
|
|
136
|
+
return (
|
|
137
|
+
'Error logging event or event type not supported - ' +
|
|
138
|
+
reportEvent.error
|
|
139
|
+
);
|
|
129
140
|
}
|
|
141
|
+
} catch (e) {
|
|
142
|
+
return 'Failed to send to: ' + name + ' ' + e;
|
|
130
143
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return 'Can\'t send to forwarder ' + name + ', not initialized. Event added to queue.';
|
|
144
|
+
} else {
|
|
145
|
+
eventQueue.push(event);
|
|
136
146
|
}
|
|
137
147
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
148
|
+
return (
|
|
149
|
+
"Can't send to forwarder " +
|
|
150
|
+
name +
|
|
151
|
+
', not initialized. Event added to queue.'
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Helper method to check if object is empty
|
|
157
|
+
* @param obj
|
|
158
|
+
* @returns {boolean}
|
|
159
|
+
*/
|
|
160
|
+
function isEmpty(obj) {
|
|
161
|
+
for (var prop in obj) {
|
|
162
|
+
return false;
|
|
146
163
|
}
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
147
166
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
167
|
+
/**
|
|
168
|
+
* Helper method to merge obj 2 into obj1
|
|
169
|
+
* @param obj1
|
|
170
|
+
* @param obj2
|
|
171
|
+
*/
|
|
172
|
+
function mergeObjects(obj1, obj2) {
|
|
173
|
+
var obj = {};
|
|
174
|
+
for (var key in obj1) {
|
|
175
|
+
if (obj1[key]) {
|
|
176
|
+
obj[key] = obj1[key];
|
|
159
177
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
178
|
+
}
|
|
179
|
+
for (var key in obj2) {
|
|
180
|
+
if (obj2[key]) {
|
|
181
|
+
obj[key] = obj2[key];
|
|
164
182
|
}
|
|
165
|
-
return obj;
|
|
166
183
|
}
|
|
184
|
+
return obj;
|
|
185
|
+
}
|
|
167
186
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Helper method to clone an object
|
|
189
|
+
* @param {*} obj
|
|
190
|
+
*/
|
|
191
|
+
function clone(obj) {
|
|
192
|
+
var copy = {};
|
|
193
|
+
for (var key in obj) {
|
|
194
|
+
if (obj.hasOwnProperty(key)) {
|
|
176
195
|
copy[key] = obj[key];
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return copy;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* tracks Taplytics events
|
|
184
|
-
* @param {*} event
|
|
185
|
-
* @param {*} revenue
|
|
186
|
-
* @param {*} attributes
|
|
187
|
-
*/
|
|
188
|
-
function trackEvent(event, revenue, attributes) {
|
|
189
|
-
if (revenue) {
|
|
190
|
-
if (attributes && !isEmpty(attributes)) {
|
|
191
|
-
Taplytics.track(event, revenue, attributes);
|
|
192
|
-
} else {
|
|
193
|
-
Taplytics.track(event, revenue);
|
|
194
|
-
}
|
|
195
|
-
} else {
|
|
196
|
-
if (attributes && !isEmpty(attributes)) {
|
|
197
|
-
Taplytics.track(event, null, attributes);
|
|
198
|
-
} else {
|
|
199
|
-
Taplytics.track(event);
|
|
200
|
-
}
|
|
201
196
|
}
|
|
202
197
|
}
|
|
198
|
+
return copy;
|
|
199
|
+
}
|
|
203
200
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (timeout) {
|
|
217
|
-
query = query + 'timeout=' + timeout;
|
|
201
|
+
/**
|
|
202
|
+
* tracks Taplytics events
|
|
203
|
+
* @param {*} event
|
|
204
|
+
* @param {*} revenue
|
|
205
|
+
* @param {*} attributes
|
|
206
|
+
*/
|
|
207
|
+
function trackEvent(event, revenue, attributes) {
|
|
208
|
+
if (revenue) {
|
|
209
|
+
if (attributes && !isEmpty(attributes)) {
|
|
210
|
+
Taplytics.track(event, revenue, attributes);
|
|
211
|
+
} else {
|
|
212
|
+
Taplytics.track(event, revenue);
|
|
218
213
|
}
|
|
219
|
-
|
|
220
|
-
if (
|
|
221
|
-
|
|
214
|
+
} else {
|
|
215
|
+
if (attributes && !isEmpty(attributes)) {
|
|
216
|
+
Taplytics.track(event, null, attributes);
|
|
217
|
+
} else {
|
|
218
|
+
Taplytics.track(event);
|
|
222
219
|
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
223
222
|
|
|
224
|
-
|
|
223
|
+
/**
|
|
224
|
+
* Construct Taplytics src link to load the SDK
|
|
225
|
+
* @returns {string}
|
|
226
|
+
*/
|
|
227
|
+
function getTaplyticsSourceLink() {
|
|
228
|
+
var token = settings.apiKey;
|
|
229
|
+
var cookieDomain = settings.taplyticsOptionCookieDomain;
|
|
230
|
+
var timeout = settings.taplyticsOptionTimeout;
|
|
225
231
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
232
|
+
var src = 'https://js.taplytics.com/jssdk/' + token + '.min.js';
|
|
233
|
+
var query = '';
|
|
229
234
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
var identity = initUserIdentities[0];
|
|
234
|
-
var type = identity.Type;
|
|
235
|
-
var id = identity.Identity;
|
|
236
|
-
switch (type) {
|
|
237
|
-
case 1:
|
|
238
|
-
user_attributes['user_id'] = id;
|
|
239
|
-
break;
|
|
240
|
-
case 7:
|
|
241
|
-
user_attributes['email'] = id;
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
235
|
+
if (timeout) {
|
|
236
|
+
query = query + 'timeout=' + timeout;
|
|
237
|
+
}
|
|
245
238
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
239
|
+
if (cookieDomain) {
|
|
240
|
+
query = query + (query ? '&' : '') + 'cookieDomain=' + cookieDomain;
|
|
241
|
+
}
|
|
250
242
|
|
|
251
|
-
|
|
252
|
-
src = src + '?' + query;
|
|
253
|
-
}
|
|
243
|
+
var userBucketing = settings.taplyticsOptionUserBucketing;
|
|
254
244
|
|
|
255
|
-
|
|
245
|
+
if (userBucketing === 'True') {
|
|
246
|
+
query = query + (query ? '&' : '') + 'user_bucketing=true';
|
|
256
247
|
}
|
|
257
248
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
return true;
|
|
273
|
-
}
|
|
274
|
-
catch (e) {
|
|
275
|
-
return { error: e };
|
|
249
|
+
var user_attributes = initUserAttributes || {};
|
|
250
|
+
|
|
251
|
+
if (initUserIdentities.length) {
|
|
252
|
+
var identity = initUserIdentities[0];
|
|
253
|
+
var type = identity.Type;
|
|
254
|
+
var id = identity.Identity;
|
|
255
|
+
switch (type) {
|
|
256
|
+
case 1:
|
|
257
|
+
user_attributes['user_id'] = id;
|
|
258
|
+
break;
|
|
259
|
+
case 7:
|
|
260
|
+
user_attributes['email'] = id;
|
|
261
|
+
break;
|
|
276
262
|
}
|
|
277
263
|
}
|
|
278
264
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
productList.forEach(function(product) {
|
|
290
|
-
var product = product;
|
|
291
|
-
var attributes = {};
|
|
292
|
-
var productAttributes = product;
|
|
293
|
-
if (product.Attributes) {
|
|
294
|
-
productAttributes = mergeObjects(product.Attributes, product);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
if (event.EventAttributes) {
|
|
298
|
-
attributes['EventAttributes'] = event.EventAttributes;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
if (event.CurrencyCode) {
|
|
302
|
-
attributes['CurrencyCode'] = event.CurrencyCode;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
attributes['ProductAttributes'] = productAttributes;
|
|
306
|
-
|
|
307
|
-
Taplytics.track(event.EventName, parseFloat(product.TotalAmount), attributes);
|
|
308
|
-
});
|
|
309
|
-
return true;
|
|
310
|
-
}
|
|
311
|
-
catch (e) {
|
|
312
|
-
return {error: e};
|
|
313
|
-
}
|
|
314
|
-
}
|
|
265
|
+
if (!isEmpty(user_attributes)) {
|
|
266
|
+
user_attributes = encodeURIComponent(
|
|
267
|
+
JSON.stringify(user_attributes)
|
|
268
|
+
);
|
|
269
|
+
query =
|
|
270
|
+
query +
|
|
271
|
+
(query ? '&' : '') +
|
|
272
|
+
'user_attributes=' +
|
|
273
|
+
user_attributes;
|
|
274
|
+
}
|
|
315
275
|
|
|
316
|
-
|
|
276
|
+
if (query) {
|
|
277
|
+
src = src + '?' + query;
|
|
317
278
|
}
|
|
318
279
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
* @param event
|
|
322
|
-
* @returns {*}
|
|
323
|
-
*/
|
|
324
|
-
function logCommerceEvent(event) {
|
|
325
|
-
var reportEvent = false;
|
|
280
|
+
return src;
|
|
281
|
+
}
|
|
326
282
|
|
|
327
|
-
|
|
283
|
+
/**
|
|
284
|
+
* Logs page view event to Taplytics
|
|
285
|
+
* @param event
|
|
286
|
+
* @returns {*}
|
|
287
|
+
*/
|
|
288
|
+
function logPageView(event) {
|
|
289
|
+
// Details on the `event` object schema in the README
|
|
290
|
+
try {
|
|
291
|
+
if (event.EventAttributes) {
|
|
292
|
+
Taplytics.page(event.EventName, event.EventAttributes);
|
|
293
|
+
} else {
|
|
294
|
+
trackEvent(event.EventName);
|
|
295
|
+
}
|
|
296
|
+
return true;
|
|
297
|
+
} catch (e) {
|
|
298
|
+
return { error: e };
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Logs purchase events as revenue events to Taplytics
|
|
304
|
+
* @param event
|
|
305
|
+
* @returns {*}
|
|
306
|
+
*/
|
|
307
|
+
function logPurchaseEvent(event) {
|
|
308
|
+
var reportEvent = false;
|
|
309
|
+
if (event.ProductAction.ProductList) {
|
|
310
|
+
try {
|
|
311
|
+
var productList = event.ProductAction.ProductList;
|
|
312
|
+
productList.forEach(function(product) {
|
|
313
|
+
var product = product;
|
|
314
|
+
var attributes = {};
|
|
315
|
+
var productAttributes = product;
|
|
316
|
+
if (product.Attributes) {
|
|
317
|
+
productAttributes = mergeObjects(
|
|
318
|
+
product.Attributes,
|
|
319
|
+
product
|
|
320
|
+
);
|
|
321
|
+
}
|
|
328
322
|
|
|
329
|
-
if (event) {
|
|
330
|
-
try {
|
|
331
323
|
if (event.EventAttributes) {
|
|
332
324
|
attributes['EventAttributes'] = event.EventAttributes;
|
|
333
325
|
}
|
|
@@ -335,220 +327,297 @@ var isobject = function isObject(val) {
|
|
|
335
327
|
if (event.CurrencyCode) {
|
|
336
328
|
attributes['CurrencyCode'] = event.CurrencyCode;
|
|
337
329
|
}
|
|
338
|
-
|
|
339
|
-
if (event.EventCategory === mParticle.CommerceEventType.PromotionClick) {
|
|
340
|
-
var promotionList = event.PromotionAction.PromotionList;
|
|
341
|
-
if (promotionList) {
|
|
342
|
-
promotionList.forEach(function(promotion) {
|
|
343
|
-
attributes["Promotion"] = promotion;
|
|
344
|
-
trackEvent(event.EventName, null, attributes);
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
} else if (event.EventCategory === mParticle.CommerceEventType.ProductImpression) {
|
|
348
|
-
var impressions = event.ProductImpressions;
|
|
349
|
-
if (impressions) {
|
|
350
|
-
impressions.forEach(function(impression) {
|
|
351
|
-
var productList = impression.ProductList;
|
|
352
|
-
var impressionName = impression.ProductImpressionList;
|
|
353
|
-
if (productList) {
|
|
354
|
-
productList.forEach(function(product) {
|
|
355
|
-
var productAttributes = product;
|
|
356
|
-
var attributeCopy = clone(attributes);
|
|
357
|
-
if (product.Attributes) {
|
|
358
|
-
productAttributes = mergeObjects(product, product.Attributes);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
attributeCopy["ProductImpression"] = impressionName;
|
|
362
|
-
attributeCopy["ProductImpressionProduct"] = productAttributes;
|
|
363
|
-
trackEvent(event.EventName, null, attributeCopy);
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
} else if (event.EventCategory === mParticle.CommerceEventType.ProductAddToCart ||
|
|
369
|
-
event.EventCategory === mParticle.CommerceEventType.ProductRemoveFromCart ||
|
|
370
|
-
event.ProductAction) {
|
|
371
|
-
|
|
372
|
-
if (event.ProductAction.ProductList) {
|
|
373
|
-
var productList = event.ProductAction.ProductList;
|
|
374
|
-
productList.forEach(function(product) {
|
|
375
|
-
var productAttributes = product;
|
|
376
|
-
if (product.Attributes) {
|
|
377
|
-
productAttributes = mergeObjects(product, product.Attributes);
|
|
378
|
-
}
|
|
379
|
-
attributes["ProductAttributes"] = productAttributes;
|
|
380
|
-
if (event.ShoppingCart && event.ShoppingCart.ProductList) {
|
|
381
|
-
attributes["ShoppingCart"] = event.ShoppingCart.ProductList;
|
|
382
|
-
}
|
|
383
|
-
trackEvent(event.EventName, null, attributes);
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
} else {
|
|
387
|
-
trackEvent(event.EventName, null, attributes);
|
|
388
|
-
}
|
|
389
330
|
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
catch (e) {
|
|
393
|
-
return {error: e};
|
|
394
|
-
}
|
|
395
|
-
}
|
|
331
|
+
attributes['ProductAttributes'] = productAttributes;
|
|
396
332
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
*/
|
|
404
|
-
function logEvent(event) {
|
|
405
|
-
try {
|
|
406
|
-
trackEvent(event.EventName, null, event.EventAttributes);
|
|
333
|
+
Taplytics.track(
|
|
334
|
+
event.EventName,
|
|
335
|
+
parseFloat(product.TotalAmount),
|
|
336
|
+
attributes
|
|
337
|
+
);
|
|
338
|
+
});
|
|
407
339
|
return true;
|
|
408
|
-
}
|
|
409
|
-
catch (e) {
|
|
340
|
+
} catch (e) {
|
|
410
341
|
return { error: e };
|
|
411
342
|
}
|
|
412
343
|
}
|
|
413
344
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
345
|
+
return reportEvent;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Logs all other commerce events as regular events with metadata to Taplytics
|
|
350
|
+
* @param event
|
|
351
|
+
* @returns {*}
|
|
352
|
+
*/
|
|
353
|
+
function logCommerceEvent(event) {
|
|
354
|
+
var reportEvent = false;
|
|
355
|
+
|
|
356
|
+
var attributes = {};
|
|
357
|
+
|
|
358
|
+
if (event) {
|
|
359
|
+
try {
|
|
360
|
+
if (event.EventAttributes) {
|
|
361
|
+
attributes['EventAttributes'] = event.EventAttributes;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (event.CurrencyCode) {
|
|
365
|
+
attributes['CurrencyCode'] = event.CurrencyCode;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (
|
|
369
|
+
event.EventCategory ===
|
|
370
|
+
mParticle.CommerceEventType.PromotionClick
|
|
371
|
+
) {
|
|
372
|
+
var promotionList = event.PromotionAction.PromotionList;
|
|
373
|
+
if (promotionList) {
|
|
374
|
+
promotionList.forEach(function(promotion) {
|
|
375
|
+
attributes['Promotion'] = promotion;
|
|
376
|
+
trackEvent(event.EventName, null, attributes);
|
|
431
377
|
});
|
|
432
378
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
379
|
+
} else if (
|
|
380
|
+
event.EventCategory ===
|
|
381
|
+
mParticle.CommerceEventType.ProductImpression
|
|
382
|
+
) {
|
|
383
|
+
var impressions = event.ProductImpressions;
|
|
384
|
+
if (impressions) {
|
|
385
|
+
impressions.forEach(function(impression) {
|
|
386
|
+
var productList = impression.ProductList;
|
|
387
|
+
var impressionName =
|
|
388
|
+
impression.ProductImpressionList;
|
|
389
|
+
if (productList) {
|
|
390
|
+
productList.forEach(function(product) {
|
|
391
|
+
var productAttributes = product;
|
|
392
|
+
var attributeCopy = clone(attributes);
|
|
393
|
+
if (product.Attributes) {
|
|
394
|
+
productAttributes = mergeObjects(
|
|
395
|
+
product,
|
|
396
|
+
product.Attributes
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
attributeCopy[
|
|
401
|
+
'ProductImpression'
|
|
402
|
+
] = impressionName;
|
|
403
|
+
attributeCopy[
|
|
404
|
+
'ProductImpressionProduct'
|
|
405
|
+
] = productAttributes;
|
|
406
|
+
trackEvent(
|
|
407
|
+
event.EventName,
|
|
408
|
+
null,
|
|
409
|
+
attributeCopy
|
|
410
|
+
);
|
|
411
|
+
});
|
|
412
|
+
}
|
|
436
413
|
});
|
|
437
414
|
}
|
|
415
|
+
} else if (
|
|
416
|
+
event.EventCategory ===
|
|
417
|
+
mParticle.CommerceEventType.ProductAddToCart ||
|
|
418
|
+
event.EventCategory ===
|
|
419
|
+
mParticle.CommerceEventType.ProductRemoveFromCart ||
|
|
420
|
+
event.ProductAction
|
|
421
|
+
) {
|
|
422
|
+
if (event.ProductAction.ProductList) {
|
|
423
|
+
var productList = event.ProductAction.ProductList;
|
|
424
|
+
productList.forEach(function(product) {
|
|
425
|
+
var productAttributes = product;
|
|
426
|
+
if (product.Attributes) {
|
|
427
|
+
productAttributes = mergeObjects(
|
|
428
|
+
product,
|
|
429
|
+
product.Attributes
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
attributes['ProductAttributes'] = productAttributes;
|
|
433
|
+
if (
|
|
434
|
+
event.ShoppingCart &&
|
|
435
|
+
event.ShoppingCart.ProductList
|
|
436
|
+
) {
|
|
437
|
+
attributes['ShoppingCart'] =
|
|
438
|
+
event.ShoppingCart.ProductList;
|
|
439
|
+
}
|
|
440
|
+
trackEvent(event.EventName, null, attributes);
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
} else {
|
|
444
|
+
trackEvent(event.EventName, null, attributes);
|
|
438
445
|
}
|
|
439
|
-
catch (e) {
|
|
440
|
-
return 'Failed to call setUserIdentity on ' + name + ' ' + e;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
else {
|
|
444
|
-
return 'Can\'t call setUserIdentity on forwarder ' + name + ', not initialized';
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
446
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
* @param value
|
|
452
|
-
* @returns {string}
|
|
453
|
-
*/
|
|
454
|
-
function setUserAttribute(key, value) {
|
|
455
|
-
if (isInitialized) {
|
|
456
|
-
try {
|
|
457
|
-
var attributes = {};
|
|
458
|
-
attributes[key] = value;
|
|
459
|
-
Taplytics.identify(attributes);
|
|
460
|
-
return 'Successfully called setUserAttribute API on ' + name;
|
|
461
|
-
}
|
|
462
|
-
catch (e) {
|
|
463
|
-
return 'Failed to call SET setUserAttribute on ' + name + ' ' + e;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
else {
|
|
467
|
-
return 'Can\'t call setUserAttribute on forwarder ' + name + ', not initialized';
|
|
447
|
+
return true;
|
|
448
|
+
} catch (e) {
|
|
449
|
+
return { error: e };
|
|
468
450
|
}
|
|
469
451
|
}
|
|
470
452
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
453
|
+
return reportEvent;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Log regular Taplytics events
|
|
458
|
+
* @param {*} event
|
|
459
|
+
*/
|
|
460
|
+
function logEvent(event) {
|
|
461
|
+
try {
|
|
462
|
+
trackEvent(event.EventName, null, event.EventAttributes);
|
|
463
|
+
return true;
|
|
464
|
+
} catch (e) {
|
|
465
|
+
return { error: e };
|
|
477
466
|
}
|
|
467
|
+
}
|
|
478
468
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
469
|
+
/**
|
|
470
|
+
* Identifies user id or email with Taplytics
|
|
471
|
+
* @param id
|
|
472
|
+
* @param type
|
|
473
|
+
* @returns {string}
|
|
474
|
+
*/
|
|
475
|
+
function setUserIdentity(id, type) {
|
|
476
|
+
if (isInitialized) {
|
|
477
|
+
try {
|
|
478
|
+
// Some integrations have primary ids that they use
|
|
479
|
+
// (ie. CustomerId, or Email), you may have special methods
|
|
480
|
+
// to call for these. mParticle allows for several other
|
|
481
|
+
// types of userIds to be set. To view all user identity
|
|
482
|
+
// types, navigate to - https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/src/types.js#L88-L101
|
|
483
|
+
if (type === window.mParticle.IdentityType.CustomerId) {
|
|
484
|
+
Taplytics.identify({
|
|
485
|
+
user_id: id,
|
|
486
|
+
});
|
|
487
|
+
} else if (type === window.mParticle.IdentityType.Email) {
|
|
488
|
+
Taplytics.identify({
|
|
489
|
+
email: id,
|
|
490
|
+
});
|
|
496
491
|
}
|
|
492
|
+
} catch (e) {
|
|
493
|
+
return 'Failed to call setUserIdentity on ' + name + ' ' + e;
|
|
497
494
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
495
|
+
} else {
|
|
496
|
+
return (
|
|
497
|
+
"Can't call setUserIdentity on forwarder " +
|
|
498
|
+
name +
|
|
499
|
+
', not initialized'
|
|
500
|
+
);
|
|
501
501
|
}
|
|
502
|
-
|
|
503
|
-
this.init = initForwarder;
|
|
504
|
-
this.process = processEvent;
|
|
505
|
-
this.setUserIdentity = setUserIdentity;
|
|
506
|
-
this.setUserAttribute = setUserAttribute;
|
|
507
|
-
this.removeUserAttribute = removeUserAttribute;
|
|
508
|
-
this.onUserIdentified = onUserIdentified;
|
|
509
|
-
};
|
|
510
|
-
|
|
511
|
-
function getId() {
|
|
512
|
-
return moduleId;
|
|
513
502
|
}
|
|
514
503
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
504
|
+
/**
|
|
505
|
+
* Sets user attributes to Taplytics
|
|
506
|
+
* @param key
|
|
507
|
+
* @param value
|
|
508
|
+
* @returns {string}
|
|
509
|
+
*/
|
|
510
|
+
function setUserAttribute(key, value) {
|
|
511
|
+
if (isInitialized) {
|
|
512
|
+
try {
|
|
513
|
+
var attributes = {};
|
|
514
|
+
attributes[key] = value;
|
|
515
|
+
Taplytics.identify(attributes);
|
|
516
|
+
return 'Successfully called setUserAttribute API on ' + name;
|
|
517
|
+
} catch (e) {
|
|
518
|
+
return (
|
|
519
|
+
'Failed to call SET setUserAttribute on ' + name + ' ' + e
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
} else {
|
|
523
|
+
return (
|
|
524
|
+
"Can't call setUserAttribute on forwarder " +
|
|
525
|
+
name +
|
|
526
|
+
', not initialized'
|
|
527
|
+
);
|
|
519
528
|
}
|
|
529
|
+
}
|
|
520
530
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
531
|
+
/**
|
|
532
|
+
* Remove user attribute by setting it to null
|
|
533
|
+
* @param key
|
|
534
|
+
*/
|
|
535
|
+
function removeUserAttribute(key) {
|
|
536
|
+
setUserAttribute(key, null);
|
|
537
|
+
}
|
|
525
538
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
539
|
+
/**
|
|
540
|
+
* V2 version of setting user identity
|
|
541
|
+
* @param user
|
|
542
|
+
* @returns {string}
|
|
543
|
+
*/
|
|
544
|
+
function onUserIdentified(user) {
|
|
545
|
+
if (isInitialized) {
|
|
546
|
+
var identities = user.getUserIdentities().userIdentities;
|
|
547
|
+
var attributes = {};
|
|
548
|
+
if (identities.customerid) {
|
|
549
|
+
attributes.user_id = identities.customerid;
|
|
550
|
+
}
|
|
551
|
+
if (identities.email) {
|
|
552
|
+
attributes.email = identities.email;
|
|
553
|
+
}
|
|
554
|
+
if (!isEmpty(attributes)) {
|
|
555
|
+
Taplytics.identify(attributes);
|
|
556
|
+
}
|
|
530
557
|
} else {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
558
|
+
return (
|
|
559
|
+
"Can't call onUserIdentified on forwarder " +
|
|
560
|
+
name +
|
|
561
|
+
', not initialized'
|
|
562
|
+
);
|
|
535
563
|
}
|
|
536
|
-
console.log('Successfully registered ' + name + ' to your mParticle configuration');
|
|
537
564
|
}
|
|
538
565
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
566
|
+
this.init = initForwarder;
|
|
567
|
+
this.process = processEvent;
|
|
568
|
+
this.setUserIdentity = setUserIdentity;
|
|
569
|
+
this.setUserAttribute = setUserAttribute;
|
|
570
|
+
this.removeUserAttribute = removeUserAttribute;
|
|
571
|
+
this.onUserIdentified = onUserIdentified;
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
function getId() {
|
|
575
|
+
return moduleId;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function register(config) {
|
|
579
|
+
if (!config) {
|
|
580
|
+
console.log(
|
|
581
|
+
'You must pass a config object to register the kit ' + name
|
|
582
|
+
);
|
|
583
|
+
return;
|
|
547
584
|
}
|
|
548
585
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
586
|
+
if (!isObject(config)) {
|
|
587
|
+
console.log(
|
|
588
|
+
"'config' must be an object. You passed in a " + typeof config
|
|
589
|
+
);
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
if (isObject(config.kits)) {
|
|
594
|
+
config.kits[name] = {
|
|
595
|
+
constructor: constructor,
|
|
596
|
+
};
|
|
597
|
+
} else {
|
|
598
|
+
config.kits = {};
|
|
599
|
+
config.kits[name] = {
|
|
600
|
+
constructor: constructor,
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
console.log(
|
|
604
|
+
'Successfully registered ' + name + ' to your mParticle configuration'
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
if (typeof window !== 'undefined') {
|
|
609
|
+
if (window && window.mParticle && window.mParticle.addForwarder) {
|
|
610
|
+
window.mParticle.addForwarder({
|
|
611
|
+
name: name,
|
|
612
|
+
constructor: constructor,
|
|
613
|
+
getId: getId,
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
var TaplyticsKit = {
|
|
619
|
+
register: register,
|
|
620
|
+
};
|
|
552
621
|
var TaplyticsKit_1 = TaplyticsKit.register;
|
|
553
622
|
|
|
554
623
|
exports.default = TaplyticsKit;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-taplytics-kit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
|
|
5
5
|
"description": "mParticle integration sdk for Taplytics",
|
|
6
6
|
"main": "dist/TaplyticsKit.common.js",
|
|
@@ -8,7 +8,11 @@
|
|
|
8
8
|
"files": [
|
|
9
9
|
"dist/TaplyticsKit.common.js"
|
|
10
10
|
],
|
|
11
|
-
"repository":
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/mParticle/mparticle-web-sdk",
|
|
14
|
+
"directory": "kits/taplytics"
|
|
15
|
+
},
|
|
12
16
|
"scripts": {
|
|
13
17
|
"build": "rollup --config rollup.config.js",
|
|
14
18
|
"watch": "rollup --config rollup.config.js -w",
|
|
@@ -31,7 +35,7 @@
|
|
|
31
35
|
},
|
|
32
36
|
"dependencies": {
|
|
33
37
|
"isobject": "^4.0.0",
|
|
34
|
-
"@mparticle/web-sdk": "^
|
|
38
|
+
"@mparticle/web-sdk": "^3.0.0"
|
|
35
39
|
},
|
|
36
40
|
"license": "Apache-2.0"
|
|
37
41
|
}
|