@mparticle/web-criteo-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.
@@ -16,303 +16,334 @@ Object.defineProperty(exports, '__esModule', { value: true });
16
16
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
17
  // See the License for the specific language governing permissions and
18
18
  // limitations under the License.
19
- var name = 'Criteo',
20
- moduleId = 1010,
21
- MessageType = {
22
- SessionStart: 1,
23
- SessionEnd: 2,
24
- PageView: 3,
25
- PageEvent: 4,
26
- CrashReport: 5,
27
- OptOut: 6,
28
- Commerce: 16
29
- },
30
- // below are custom types for logging page views and setting site types for Criteo
31
- CRITEO_SITETYPE = 'CRITEO_SITETYPE',
32
- CRITEO_VIEW_HOMEPAGE = 'CRITEO_VIEW_HOMEPAGE';
33
-
34
- var constructor = function () {
35
- var self = this,
36
- reportingService,
37
- mpCustomFlags;
38
-
39
- setDefaultCriteoEvents();
40
-
41
- self.name = name;
42
-
43
- function initForwarder(forwarderSettings, service, testMode, trackerId, userAttributes, userIdentities, appVersion, appName, customFlags) {
44
- mpCustomFlags = customFlags;
45
- if (!testMode) {
46
- reportingService = service;
47
- settings = forwarderSettings;
48
- try {
49
- var criteoScript = document.createElement('script');
50
- window.criteo_q = window.criteo_q || [];
51
- criteoScript.type = 'text/javascript';
52
- criteoScript.async = true;
53
- criteoScript.src = 'https://static.criteo.net/js/ld/ld.js';
54
- (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(criteoScript);
55
- }
56
- catch (e) {
57
- return 'Failed to initialize: ' + e;
58
- }
59
- } else {
60
- // each event needs to be defaulted for tests
61
- setDefaultCriteoEvents();
19
+ var name = 'Criteo',
20
+ moduleId = 1010,
21
+ MessageType = {
22
+ SessionStart: 1,
23
+ SessionEnd: 2,
24
+ PageView: 3,
25
+ PageEvent: 4,
26
+ CrashReport: 5,
27
+ OptOut: 6,
28
+ Commerce: 16,
29
+ },
30
+ // below are custom types for logging page views and setting site types for Criteo
31
+ CRITEO_SITETYPE = 'CRITEO_SITETYPE',
32
+ CRITEO_VIEW_HOMEPAGE = 'CRITEO_VIEW_HOMEPAGE';
33
+
34
+ var constructor = function() {
35
+ var self = this,
36
+ reportingService,
37
+ mpCustomFlags;
38
+
39
+ setDefaultCriteoEvents();
40
+
41
+ self.name = name;
42
+
43
+ function initForwarder(
44
+ forwarderSettings,
45
+ service,
46
+ testMode,
47
+ trackerId,
48
+ userAttributes,
49
+ userIdentities,
50
+ appVersion,
51
+ appName,
52
+ customFlags
53
+ ) {
54
+ mpCustomFlags = customFlags;
55
+ if (!testMode) {
56
+ reportingService = service;
57
+ settings = forwarderSettings;
58
+ try {
59
+ var criteoScript = document.createElement('script');
60
+ window.criteo_q = window.criteo_q || [];
61
+ criteoScript.type = 'text/javascript';
62
+ criteoScript.async = true;
63
+ criteoScript.src = 'https://static.criteo.net/js/ld/ld.js';
64
+ (
65
+ document.getElementsByTagName('head')[0] ||
66
+ document.getElementsByTagName('body')[0]
67
+ ).appendChild(criteoScript);
68
+ } catch (e) {
69
+ return 'Failed to initialize: ' + e;
62
70
  }
63
-
64
- setAccountEvent.account = forwarderSettings.apiKey;
65
- return 'Criteo successfully loaded';
71
+ } else {
72
+ // each event needs to be defaulted for tests
73
+ setDefaultCriteoEvents();
66
74
  }
67
75
 
68
- // each of the following Criteo Event Types are set and then an
69
- // array of them are processed in processQueuedCriteoEvent
70
- function setDefaultCriteoEvents() {
71
- setAccountEvent = { event: 'setAccount' },
72
- setSiteTypeEvent = { event: 'setSiteType' },
73
- setEmailEvent = { event: 'setEmail' },
74
- setCustomerIdEvent = { event: 'setCustomerId' },
75
- setDataEvent = { event: 'setData' };
76
- }
76
+ setAccountEvent.account = forwarderSettings.apiKey;
77
+ return 'Criteo successfully loaded';
78
+ }
77
79
 
78
- function processEvent(event) {
79
- var reportEvent = false;
80
- var criteoEvent;
80
+ // each of the following Criteo Event Types are set and then an
81
+ // array of them are processed in processQueuedCriteoEvent
82
+ function setDefaultCriteoEvents() {
83
+ (setAccountEvent = { event: 'setAccount' }),
84
+ (setSiteTypeEvent = { event: 'setSiteType' }),
85
+ (setEmailEvent = { event: 'setEmail' }),
86
+ (setCustomerIdEvent = { event: 'setCustomerId' }),
87
+ (setDataEvent = { event: 'setData' });
88
+ }
81
89
 
82
- try {
83
- if (event.EventDataType === MessageType.Commerce) {
84
- if (event.EventCategory === mParticle.CommerceEventType.ProductAddToCart) {
85
- criteoEvent = createViewBasket(event);
86
- }
87
- else if (event.EventCategory === mParticle.CommerceEventType.ProductViewDetail) {
88
- criteoEvent = createViewProduct(event);
89
- }
90
- else if (event.EventCategory === mParticle.CommerceEventType.ProductImpression) {
91
- criteoEvent = createViewList(event);
92
- }
93
- else if (event.EventCategory === mParticle.CommerceEventType.ProductPurchase) {
94
- criteoEvent = createTrackTransactionEvent(event);
95
- }
90
+ function processEvent(event) {
91
+ var reportEvent = false;
92
+ var criteoEvent;
93
+
94
+ try {
95
+ if (event.EventDataType === MessageType.Commerce) {
96
+ if (
97
+ event.EventCategory ===
98
+ mParticle.CommerceEventType.ProductAddToCart
99
+ ) {
100
+ criteoEvent = createViewBasket(event);
101
+ } else if (
102
+ event.EventCategory ===
103
+ mParticle.CommerceEventType.ProductViewDetail
104
+ ) {
105
+ criteoEvent = createViewProduct(event);
106
+ } else if (
107
+ event.EventCategory ===
108
+ mParticle.CommerceEventType.ProductImpression
109
+ ) {
110
+ criteoEvent = createViewList(event);
111
+ } else if (
112
+ event.EventCategory ===
113
+ mParticle.CommerceEventType.ProductPurchase
114
+ ) {
115
+ criteoEvent = createTrackTransactionEvent(event);
96
116
  }
97
- else if (event.EventDataType === MessageType.PageView) {
98
- if (event.CustomFlags && event.CustomFlags[CRITEO_VIEW_HOMEPAGE]) {
99
- criteoEvent = { event: 'viewHome' };
100
- } else {
101
- return 'Error - Criteo home page views are logged via mParticle.logPageView(\'homepage\), no other logPageViews are sent to Criteo';
102
- }
117
+ } else if (event.EventDataType === MessageType.PageView) {
118
+ if (
119
+ event.CustomFlags &&
120
+ event.CustomFlags[CRITEO_VIEW_HOMEPAGE]
121
+ ) {
122
+ criteoEvent = { event: 'viewHome' };
103
123
  } else {
104
- return 'Error - Criteo does not support the event type - ' + event.EventDataType;
124
+ return "Error - Criteo home page views are logged via mParticle.logPageView('homepage), no other logPageViews are sent to Criteo";
105
125
  }
126
+ } else {
127
+ return (
128
+ 'Error - Criteo does not support the event type - ' +
129
+ event.EventDataType
130
+ );
131
+ }
106
132
 
107
- modifySetSiteTypeEvent(event);
108
- modifySetDataEvent(event);
109
- queueCriteoEvent(criteoEvent);
133
+ modifySetSiteTypeEvent();
134
+ modifySetDataEvent(event);
135
+ queueCriteoEvent(criteoEvent);
110
136
 
111
- reportEvent = true;
137
+ reportEvent = true;
112
138
 
113
- if (reportEvent === true && reportingService) {
114
- reportingService(self, event);
115
- return 'Successfully sent to ' + name;
116
- }
117
- else {
118
- return 'Error logging event or event type not supported - ' + reportEvent.error;
119
- }
120
- }
121
- catch (e) {
122
- return 'Failed to send to: ' + name + ' ' + e;
139
+ if (reportEvent === true && reportingService) {
140
+ reportingService(self, event);
141
+ return 'Successfully sent to ' + name;
142
+ } else {
143
+ return (
144
+ 'Error logging event or event type not supported - ' +
145
+ reportEvent.error
146
+ );
123
147
  }
148
+ } catch (e) {
149
+ return 'Failed to send to: ' + name + ' ' + e;
124
150
  }
151
+ }
125
152
 
126
- function modifySetSiteTypeEvent() {
127
- if (mpCustomFlags && mpCustomFlags[CRITEO_SITETYPE]) {
128
- setSiteTypeEvent.type = mpCustomFlags[CRITEO_SITETYPE];
129
- } else {
130
- setSiteTypeEvent.type = 'd';
131
- }
153
+ function modifySetSiteTypeEvent() {
154
+ if (mpCustomFlags && mpCustomFlags[CRITEO_SITETYPE]) {
155
+ setSiteTypeEvent.type = mpCustomFlags[CRITEO_SITETYPE];
156
+ } else {
157
+ setSiteTypeEvent.type = 'd';
132
158
  }
159
+ }
133
160
 
134
- function modifySetDataEvent(event) {
135
- var eventAttributes = event.EventAttributes || {};
161
+ function modifySetDataEvent(event) {
162
+ var eventAttributes = event.EventAttributes || {};
136
163
 
137
- if (Object.keys(eventAttributes).length) {
138
- for (var key in eventAttributes) {
139
- if (key !=='siteType') {
140
- if (eventAttributes.hasOwnProperty(key)) {
141
- setDataEvent[key] = eventAttributes[key];
142
- }
164
+ if (Object.keys(eventAttributes).length) {
165
+ for (var key in eventAttributes) {
166
+ if (key !== 'siteType') {
167
+ if (eventAttributes.hasOwnProperty(key)) {
168
+ setDataEvent[key] = eventAttributes[key];
143
169
  }
144
170
  }
145
171
  }
146
172
  }
173
+ }
147
174
 
148
- function resetSetDataEventAfterQueuingEvent() {
149
- setDataEvent = {
150
- event: 'setData'
151
- };
152
- }
175
+ function resetSetDataEventAfterQueuingEvent() {
176
+ setDataEvent = {
177
+ event: 'setData',
178
+ };
179
+ }
153
180
 
154
- function queueCriteoEvent(criteoEvent) {
155
- var eventQueue = [setAccountEvent, setSiteTypeEvent];
156
- if (setEmailEvent.email) {
157
- eventQueue.push(setEmailEvent);
158
- }
159
- if (setCustomerIdEvent.id) {
160
- eventQueue.push(setCustomerIdEvent);
161
- }
181
+ function queueCriteoEvent(criteoEvent) {
182
+ var eventQueue = [setAccountEvent, setSiteTypeEvent];
183
+ if (setEmailEvent.email) {
184
+ eventQueue.push(setEmailEvent);
185
+ }
186
+ if (setCustomerIdEvent.id) {
187
+ eventQueue.push(setCustomerIdEvent);
188
+ }
162
189
 
163
- eventQueue.push(criteoEvent);
190
+ eventQueue.push(criteoEvent);
164
191
 
165
- if (Object.keys(setDataEvent).length > 1) {
166
- eventQueue.push(setDataEvent);
167
- }
192
+ if (Object.keys(setDataEvent).length > 1) {
193
+ eventQueue.push(setDataEvent);
194
+ }
168
195
 
169
- window.criteo_q.push.apply(window.criteo_q, JSON.parse(JSON.stringify(eventQueue)));
196
+ window.criteo_q.push.apply(
197
+ window.criteo_q,
198
+ JSON.parse(JSON.stringify(eventQueue))
199
+ );
170
200
 
171
- resetSetDataEventAfterQueuingEvent();
172
- }
201
+ resetSetDataEventAfterQueuingEvent();
202
+ }
173
203
 
174
- function createViewBasket(event) {
175
- var criteoEvent = { event: 'viewBasket' },
176
- items = [];
204
+ function createViewBasket(event) {
205
+ var criteoEvent = { event: 'viewBasket' },
206
+ items = [];
177
207
 
178
- event.ProductAction.ProductList.forEach(function(product) {
179
- items.push({
180
- id: product.Sku,
181
- price: product.Price,
182
- quantity: product.Quantity
183
- });
208
+ event.ProductAction.ProductList.forEach(function(product) {
209
+ items.push({
210
+ id: product.Sku,
211
+ price: product.Price,
212
+ quantity: product.Quantity,
184
213
  });
214
+ });
185
215
 
186
- criteoEvent.item = items;
216
+ criteoEvent.item = items;
187
217
 
188
- return criteoEvent;
189
- }
218
+ return criteoEvent;
219
+ }
190
220
 
191
- function createViewProduct(event) {
192
- var criteoEvent = { event: 'viewItem' },
193
- items = [];
221
+ function createViewProduct(event) {
222
+ var criteoEvent = { event: 'viewItem' },
223
+ items = [];
194
224
 
195
- event.ProductAction.ProductList.forEach(function(product) {
196
- if (product.Sku) {
197
- items.push(product.Sku);
198
- }
199
- });
225
+ event.ProductAction.ProductList.forEach(function(product) {
226
+ if (product.Sku) {
227
+ items.push(product.Sku);
228
+ }
229
+ });
200
230
 
201
- criteoEvent.item = items;
231
+ criteoEvent.item = items;
202
232
 
203
- return criteoEvent;
204
- }
233
+ return criteoEvent;
234
+ }
205
235
 
206
- function createViewList(event) {
207
- var criteoEvent = { event: 'viewList' },
208
- items = [];
236
+ function createViewList(event) {
237
+ var criteoEvent = { event: 'viewList' },
238
+ items = [];
209
239
 
210
- event.ProductImpressions.forEach(function(impression) {
211
- impression.ProductList.forEach(function(product) {
212
- if (product.Sku) {
213
- items.push(product.Sku);
214
- }
215
- });
240
+ event.ProductImpressions.forEach(function(impression) {
241
+ impression.ProductList.forEach(function(product) {
242
+ if (product.Sku) {
243
+ items.push(product.Sku);
244
+ }
216
245
  });
246
+ });
217
247
 
218
- criteoEvent.item = items;
248
+ criteoEvent.item = items;
219
249
 
220
- return criteoEvent;
221
- }
250
+ return criteoEvent;
251
+ }
222
252
 
223
- function createTrackTransactionEvent(event) {
224
- var criteoEvent = { event: 'trackTransaction' };
253
+ function createTrackTransactionEvent(event) {
254
+ var criteoEvent = { event: 'trackTransaction' };
225
255
 
226
- if (event.ProductAction.TransactionId) {
227
- criteoEvent.id = event.ProductAction.TransactionId;
228
- }
256
+ if (event.ProductAction.TransactionId) {
257
+ criteoEvent.id = event.ProductAction.TransactionId;
258
+ }
229
259
 
230
- var criteoProductList = [];
260
+ var criteoProductList = [];
231
261
 
232
- event.ProductAction.ProductList.forEach(function(product) {
233
- criteoProductList.push({
234
- id: product.Sku,
235
- price: parseFloat(product.Price),
236
- quantity: product.Quantity
237
- });
262
+ event.ProductAction.ProductList.forEach(function(product) {
263
+ criteoProductList.push({
264
+ id: product.Sku,
265
+ price: parseFloat(product.Price),
266
+ quantity: product.Quantity,
238
267
  });
268
+ });
239
269
 
240
- criteoEvent.item = criteoProductList;
270
+ criteoEvent.item = criteoProductList;
241
271
 
242
- return criteoEvent;
243
- }
272
+ return criteoEvent;
273
+ }
244
274
 
245
- function setUserIdentity(id, type) {
246
- try {
247
- if (type === window.mParticle.IdentityType.CustomerId) {
248
- setCustomerIdEvent.id = id;
249
- }
250
- else if (type === window.mParticle.IdentityType.Email) {
251
- setEmailEvent.email = id.trim().toLowerCase();
252
- }
253
- else {
254
- return 'Only CustomerID and Email types are available on Criteo';
255
- }
256
- }
257
- catch (e) {
258
- return 'Failed to call setUserIdentity on ' + name + ' ' + e;
275
+ function setUserIdentity(id, type) {
276
+ try {
277
+ if (type === window.mParticle.IdentityType.CustomerId) {
278
+ setCustomerIdEvent.id = id;
279
+ } else if (type === window.mParticle.IdentityType.Email) {
280
+ setEmailEvent.email = id.trim().toLowerCase();
281
+ } else {
282
+ return 'Only CustomerID and Email types are available on Criteo';
259
283
  }
284
+ } catch (e) {
285
+ return 'Failed to call setUserIdentity on ' + name + ' ' + e;
260
286
  }
261
-
262
- this.init = initForwarder;
263
- this.process = processEvent;
264
- this.setUserIdentity = setUserIdentity;
265
- };
266
-
267
- function getId() {
268
- return moduleId;
269
287
  }
270
288
 
271
- function isObject(val) {
272
- return (
273
- val != null &&
274
- typeof val === 'object' &&
275
- Array.isArray(val) === false
289
+ this.init = initForwarder;
290
+ this.process = processEvent;
291
+ this.setUserIdentity = setUserIdentity;
292
+ };
293
+
294
+ function getId() {
295
+ return moduleId;
296
+ }
297
+
298
+ function isObject(val) {
299
+ return (
300
+ val != null && typeof val === 'object' && Array.isArray(val) === false
301
+ );
302
+ }
303
+
304
+ function register(config) {
305
+ if (!config) {
306
+ console.log(
307
+ 'You must pass a config object to register the kit ' + name
276
308
  );
309
+ return;
277
310
  }
278
311
 
279
- function register(config) {
280
- if (!config) {
281
- console.log('You must pass a config object to register the kit ' + name);
282
- return;
283
- }
284
-
285
- if (!isObject(config)) {
286
- console.log('\'config\' must be an object. You passed in a ' + typeof config);
287
- return;
288
- }
289
-
290
- if (isObject(config.kits)) {
291
- config.kits[name] = {
292
- constructor: constructor
293
- };
294
- } else {
295
- config.kits = {};
296
- config.kits[name] = {
297
- constructor: constructor
298
- };
299
- }
300
- console.log('Successfully registered ' + name + ' to your mParticle configuration');
312
+ if (!isObject(config)) {
313
+ console.log(
314
+ "'config' must be an object. You passed in a " + typeof config
315
+ );
316
+ return;
301
317
  }
302
318
 
303
- if (typeof window !== 'undefined') {
304
- if (window && window.mParticle && window.mParticle.addForwarder) {
305
- window.mParticle.addForwarder({
306
- name: name,
307
- constructor: constructor,
308
- getId: getId
309
- });
310
- }
319
+ if (isObject(config.kits)) {
320
+ config.kits[name] = {
321
+ constructor: constructor,
322
+ };
323
+ } else {
324
+ config.kits = {};
325
+ config.kits[name] = {
326
+ constructor: constructor,
327
+ };
328
+ }
329
+ console.log(
330
+ 'Successfully registered ' + name + ' to your mParticle configuration'
331
+ );
332
+ }
333
+
334
+ if (typeof window !== 'undefined') {
335
+ if (window && window.mParticle && window.mParticle.addForwarder) {
336
+ window.mParticle.addForwarder({
337
+ name: name,
338
+ constructor: constructor,
339
+ getId: getId,
340
+ });
311
341
  }
342
+ }
312
343
 
313
- var CriteoEventForwarder = {
314
- register: register
315
- };
344
+ var CriteoEventForwarder = {
345
+ register: register,
346
+ };
316
347
  var CriteoEventForwarder_1 = CriteoEventForwarder.register;
317
348
 
318
349
  exports.default = CriteoEventForwarder;
package/package.json CHANGED
@@ -1,37 +1,41 @@
1
1
  {
2
- "name": "@mparticle/web-criteo-kit",
3
- "version": "2.0.2",
4
- "author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
5
- "description": "mParticle integration sdk for Criteo",
6
- "browser": "dist/CriteoEventForwarder.common.js",
7
- "main": "dist/CriteoEventForwarder.common.js",
8
- "files": [
9
- "dist/CriteoEventForwarder.common.js"
10
- ],
11
- "repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-criteo",
12
- "scripts": {
13
- "build": "rollup --config rollup.config.js",
14
- "watch": "rollup --config rollup.config.js -w",
15
- "build:test": "rollup --config rollup.test.config.js",
16
- "test": "npm run build && npm run build:test && DEBUG=false karma start test/karma.config.js",
17
- "test:debug": "npm run build && npm run build:test && DEBUG=true karma start test/karma.config.js"
18
- },
19
- "devDependencies": {
20
- "@mparticle/web-sdk": "^2.23.6",
21
- "@semantic-release/changelog": "^5.0.1",
22
- "@semantic-release/exec": "^5.0.0",
23
- "@semantic-release/git": "^9.0.0",
24
- "chai": "^4.2.0",
25
- "karma": "^5.1.0",
26
- "karma-chai": "^0.1.0",
27
- "karma-chrome-launcher": "^3.1.0",
28
- "karma-firefox-launcher": "^1.3.0",
29
- "karma-mocha": "^2.0.1",
30
- "mocha": "^2.3.2",
31
- "rollup": "^1.13.1",
32
- "rollup-plugin-commonjs": "^10.0.0",
33
- "rollup-plugin-node-resolve": "^5.0.1",
34
- "should": "^7.1.0"
35
- },
36
- "license": "Apache-2.0"
2
+ "name": "@mparticle/web-criteo-kit",
3
+ "version": "3.1.0",
4
+ "author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
5
+ "description": "mParticle integration sdk for Criteo",
6
+ "browser": "dist/CriteoEventForwarder.common.js",
7
+ "main": "dist/CriteoEventForwarder.common.js",
8
+ "files": [
9
+ "dist/CriteoEventForwarder.common.js"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/mParticle/mparticle-web-sdk",
14
+ "directory": "kits/criteo"
15
+ },
16
+ "scripts": {
17
+ "build": "rollup --config rollup.config.js",
18
+ "watch": "rollup --config rollup.config.js -w",
19
+ "build:test": "rollup --config rollup.test.config.js",
20
+ "test": "npm run build && npm run build:test && DEBUG=false karma start test/karma.config.js",
21
+ "test:debug": "npm run build && npm run build:test && DEBUG=true karma start test/karma.config.js"
22
+ },
23
+ "devDependencies": {
24
+ "@mparticle/web-sdk": "^3.0.0",
25
+ "@semantic-release/changelog": "^5.0.1",
26
+ "@semantic-release/exec": "^5.0.0",
27
+ "@semantic-release/git": "^9.0.0",
28
+ "chai": "^4.2.0",
29
+ "karma": "^5.1.0",
30
+ "karma-chai": "^0.1.0",
31
+ "karma-chrome-launcher": "^3.1.0",
32
+ "karma-firefox-launcher": "^1.3.0",
33
+ "karma-mocha": "^2.0.1",
34
+ "mocha": "^2.3.2",
35
+ "rollup": "^1.13.1",
36
+ "rollup-plugin-commonjs": "^10.0.0",
37
+ "rollup-plugin-node-resolve": "^5.0.1",
38
+ "should": "^7.1.0"
39
+ },
40
+ "license": "Apache-2.0"
37
41
  }