@mparticle/web-kissmetrics-kit 2.0.1 → 3.2.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.
@@ -36,297 +36,325 @@ var isobject$1 = getCjsExportFromNamespace(isobject);
36
36
  // See the License for the specific language governing permissions and
37
37
  // limitations under the License.
38
38
 
39
-
40
39
 
41
- var MessageType = {
40
+
41
+ var MessageType = {
42
42
  SessionStart: 1,
43
43
  SessionEnd: 2,
44
44
  PageView: 3,
45
45
  PageEvent: 4,
46
46
  CrashReport: 5,
47
47
  OptOut: 6,
48
- Commerce: 16
48
+ Commerce: 16,
49
49
  },
50
50
  name = 'KISSmetricsForwarder',
51
51
  moduleId = 24;
52
52
 
53
- var constructor = function () {
54
- var self = this,
55
- isInitialized = false,
56
- forwarderSettings,
57
- reportingService;
53
+ var constructor = function() {
54
+ var self = this,
55
+ isInitialized = false,
56
+ forwarderSettings,
57
+ reportingService;
58
58
 
59
- self.name = name;
59
+ self.name = name;
60
60
 
61
- function getEventTypeName(eventType) {
62
- return mParticle.EventType.getName(eventType);
63
- }
61
+ function getEventTypeName(eventType) {
62
+ return mParticle.EventType.getName(eventType);
63
+ }
64
64
 
65
- function getIdentityTypeName(identityType) {
66
- return mParticle.IdentityType.getName(identityType);
67
- }
65
+ function getIdentityTypeName(identityType) {
66
+ return mParticle.IdentityType.getName(identityType);
67
+ }
68
68
 
69
- function reportEvent(event) {
70
- if (reportingService) {
71
- reportingService(self, event);
72
- }
69
+ function reportEvent(event) {
70
+ if (reportingService) {
71
+ reportingService(self, event);
73
72
  }
73
+ }
74
74
 
75
- function processEvent(event) {
76
- if (isInitialized) {
77
- try {
78
- if (event.EventDataType == MessageType.PageEvent || event.EventDataType == MessageType.PageView) {
79
- if (event.EventCategory == window.mParticle.EventType.Transaction) {
80
- logTransaction(event);
81
- }
82
- else {
83
- logEvent(event);
84
- }
85
-
86
- reportEvent(event);
87
- }
88
- else if(event.EventDataType == MessageType.Commerce) {
89
- logCommerceEvent(event);
90
- reportEvent(event);
75
+ function processEvent(event) {
76
+ if (isInitialized) {
77
+ try {
78
+ if (
79
+ event.EventDataType == MessageType.PageEvent ||
80
+ event.EventDataType == MessageType.PageView
81
+ ) {
82
+ if (
83
+ event.EventCategory ==
84
+ window.mParticle.EventType.Transaction
85
+ ) {
86
+ logTransaction(event);
87
+ } else {
88
+ logEvent(event);
91
89
  }
92
90
 
93
- return 'Successfully sent to ' + name;
94
- }
95
- catch (e) {
96
- return 'Failed to send to: ' + name + ' ' + e;
91
+ reportEvent(event);
92
+ } else if (event.EventDataType == MessageType.Commerce) {
93
+ logCommerceEvent(event);
94
+ reportEvent(event);
97
95
  }
98
- }
99
96
 
100
- return 'Can\'t send to forwarder ' + name + ', not initialized';
97
+ return 'Successfully sent to ' + name;
98
+ } catch (e) {
99
+ return 'Failed to send to: ' + name + ' ' + e;
100
+ }
101
101
  }
102
102
 
103
- function setUserAttribute(key, value) {
104
- if (isInitialized) {
105
- if (forwarderSettings.includeUserAttributes.toLowerCase() == 'true') {
106
- try {
107
- var attributeDict = {};
108
- attributeDict[key] = value;
109
- _kmq.push(['set', attributeDict]);
103
+ return "Can't send to forwarder " + name + ', not initialized';
104
+ }
110
105
 
111
- return 'Successfully called SET API on ' + name;
112
- }
113
- catch (e) {
114
- return 'Failed to call SET API on ' + name + ' ' + e;
115
- }
106
+ function setUserAttribute(key, value) {
107
+ if (isInitialized) {
108
+ if (
109
+ forwarderSettings.includeUserAttributes.toLowerCase() == 'true'
110
+ ) {
111
+ try {
112
+ var attributeDict = {};
113
+ attributeDict[key] = value;
114
+ _kmq.push(['set', attributeDict]);
115
+
116
+ return 'Successfully called SET API on ' + name;
117
+ } catch (e) {
118
+ return 'Failed to call SET API on ' + name + ' ' + e;
116
119
  }
117
- } else {
118
- return 'Can\'t call setUserAttribute on forwarder ' + name + ', not initialized';
119
120
  }
121
+ } else {
122
+ return (
123
+ "Can't call setUserAttribute on forwarder " +
124
+ name +
125
+ ', not initialized'
126
+ );
120
127
  }
128
+ }
121
129
 
122
- function setUserIdentity(id, type) {
123
- if (isInitialized) {
124
- if (forwarderSettings.useCustomerId.toLowerCase() == 'true' &&
125
- type == window.mParticle.IdentityType.CustomerId) {
126
-
127
- try {
128
- _kmq.push(['identify', id]);
129
- return 'Successfull called IDENTITY API on ' + name;
130
- }
131
- catch (e) {
132
- return 'Failed to call IDENTITY API on ' + name + ' ' + e;
133
- }
134
- }
135
- else {
136
- setUserAttribute(getIdentityTypeName(type), id);
130
+ function setUserIdentity(id, type) {
131
+ if (isInitialized) {
132
+ if (
133
+ forwarderSettings.useCustomerId.toLowerCase() == 'true' &&
134
+ type == window.mParticle.IdentityType.CustomerId
135
+ ) {
136
+ try {
137
+ _kmq.push(['identify', id]);
138
+ return 'Successfull called IDENTITY API on ' + name;
139
+ } catch (e) {
140
+ return 'Failed to call IDENTITY API on ' + name + ' ' + e;
137
141
  }
142
+ } else {
143
+ setUserAttribute(getIdentityTypeName(type), id);
138
144
  }
139
- else {
140
- return 'Can\'t call setUserIdentity on forwarder ' + name + ', not initialized';
141
- }
142
- }
143
-
144
- function logEvent(data) {
145
- data.EventAttributes = data.EventAttributes || {};
146
- data.EventAttributes['MPEventType'] = getEventTypeName(data.EventCategory);
147
-
148
- _kmq.push(['record',
149
- data.EventName,
150
- data.EventAttributes]);
145
+ } else {
146
+ return (
147
+ "Can't call setUserIdentity on forwarder " +
148
+ name +
149
+ ', not initialized'
150
+ );
151
151
  }
152
+ }
152
153
 
153
- function logTransaction(data) {
154
- if (data.EventAttributes &&
155
- data.EventAttributes.$MethodName &&
156
- data.EventAttributes.$MethodName === 'LogEcommerceTransaction') {
154
+ function logEvent(data) {
155
+ data.EventAttributes = data.EventAttributes || {};
156
+ data.EventAttributes['MPEventType'] = getEventTypeName(
157
+ data.EventCategory
158
+ );
157
159
 
158
- // User used logTransaction method, set the event name
159
- data.EventName = 'Purchased';
160
- }
160
+ _kmq.push(['record', data.EventName, data.EventAttributes]);
161
+ }
161
162
 
162
- logEvent(data);
163
+ function logTransaction(data) {
164
+ if (
165
+ data.EventAttributes &&
166
+ data.EventAttributes.$MethodName &&
167
+ data.EventAttributes.$MethodName === 'LogEcommerceTransaction'
168
+ ) {
169
+ // User used logTransaction method, set the event name
170
+ data.EventName = 'Purchased';
163
171
  }
164
172
 
165
- function logProductData(productList) {
166
- if(productList && productList.length > 0) {
167
- _kmq.push(function() {
168
- productList.forEach(function(product) {
169
- KM.set( {
170
- 'Product SKU': product.Sku,
171
- 'Product Name': product.Name,
172
- 'Category': product.Category,
173
- 'Quantity': product.Quantity,
174
- 'Price': product.Price,
175
- '_t': KM.ts(),
176
- '_d': 1
177
- });
173
+ logEvent(data);
174
+ }
175
+
176
+ function logProductData(productList) {
177
+ if (productList && productList.length > 0) {
178
+ _kmq.push(function() {
179
+ productList.forEach(function(product) {
180
+ KM.set({
181
+ 'Product SKU': product.Sku,
182
+ 'Product Name': product.Name,
183
+ Category: product.Category,
184
+ Quantity: product.Quantity,
185
+ Price: product.Price,
186
+ _t: KM.ts(),
187
+ _d: 1,
178
188
  });
179
189
  });
180
- }
190
+ });
181
191
  }
192
+ }
182
193
 
183
- function logCommerceEvent(data) {
184
- var eventName,
185
- attributes;
186
-
187
- if(data.ProductAction) {
188
- eventName = 'Product ' + mParticle.ProductActionType.getName(
189
- data.ProductAction.ProductActionType);
190
-
191
- if(data.ProductAction.TransactionId) {
192
- attributes = {
193
- 'Order ID':data.ProductAction.TransactionId,
194
- 'Order Total':data.ProductAction.TotalAmount,
195
- 'Order Tax': data.ProductAction.TaxAmount,
196
- 'Order Shipping': data.ProductAction.ShippingAmount
197
- };
198
- }
199
- else if(data.ProductAction.CheckoutStep) {
200
- attributes = {
201
- 'Checkout Step': data.ProductAction.CheckoutStep,
202
- 'Checkout Options': data.ProductAction.CheckoutOptions
203
- };
204
- }
205
-
206
- logProductData(data.ProductAction.ProductList);
207
-
208
- if(attributes) {
209
- _kmq.push(['record', eventName, attributes]);
210
- }
211
- else {
212
- _kmq.push(['record', eventName]);
213
- }
194
+ function logCommerceEvent(data) {
195
+ var eventName, attributes;
196
+
197
+ if (data.ProductAction) {
198
+ eventName =
199
+ 'Product ' +
200
+ mParticle.ProductActionType.getName(
201
+ data.ProductAction.ProductActionType
202
+ );
203
+
204
+ if (data.ProductAction.TransactionId) {
205
+ attributes = {
206
+ 'Order ID': data.ProductAction.TransactionId,
207
+ 'Order Total': data.ProductAction.TotalAmount,
208
+ 'Order Tax': data.ProductAction.TaxAmount,
209
+ 'Order Shipping': data.ProductAction.ShippingAmount,
210
+ };
211
+ } else if (data.ProductAction.CheckoutStep) {
212
+ attributes = {
213
+ 'Checkout Step': data.ProductAction.CheckoutStep,
214
+ 'Checkout Options': data.ProductAction.CheckoutOptions,
215
+ };
214
216
  }
215
- else if(data.PromotionAction) {
216
- eventName = mParticle.PromotionType.getName(
217
- data.PromotionAction.PromotionActionType);
218
-
219
- if(data.PromotionAction.PromotionList) {
220
- _kmq.push(function () {
221
- data.PromotionAction.PromotionList.forEach(function(promotion) {
222
- KM.set({
223
- 'Promotion Id': promotion.Id,
224
- 'Promotion Name': promotion.Name,
225
- 'Promotion Creative': promotion.Creative,
226
- 'Promotion Position': promotion.Position,
227
- '_t':KM.ts(),
228
- '_d':1
229
- });
230
- });
231
- });
232
- }
233
217
 
218
+ logProductData(data.ProductAction.ProductList);
219
+
220
+ if (attributes) {
221
+ _kmq.push(['record', eventName, attributes]);
222
+ } else {
234
223
  _kmq.push(['record', eventName]);
235
224
  }
236
- else if(data.ProductImpressions) {
237
- eventName = 'Product Impression';
225
+ } else if (data.PromotionAction) {
226
+ eventName = mParticle.PromotionType.getName(
227
+ data.PromotionAction.PromotionActionType
228
+ );
238
229
 
239
- _kmq.push(function () {
240
- data.ProductImpressions.forEach(function(impression) {
230
+ if (data.PromotionAction.PromotionList) {
231
+ _kmq.push(function() {
232
+ data.PromotionAction.PromotionList.forEach(function(
233
+ promotion
234
+ ) {
241
235
  KM.set({
242
- 'Impression Name': impression.Name,
243
- '_t': KM.ts(),
244
- '_d': 1
236
+ 'Promotion Id': promotion.Id,
237
+ 'Promotion Name': promotion.Name,
238
+ 'Promotion Creative': promotion.Creative,
239
+ 'Promotion Position': promotion.Position,
240
+ _t: KM.ts(),
241
+ _d: 1,
245
242
  });
246
-
247
- logProductData(impression.ProductList);
248
243
  });
249
244
  });
250
-
251
- _kmq.push(['record', eventName]);
252
245
  }
253
- }
254
246
 
255
- function initForwarder(settings, service, testMode) {
256
- forwarderSettings = settings;
257
- reportingService = service;
247
+ _kmq.push(['record', eventName]);
248
+ } else if (data.ProductImpressions) {
249
+ eventName = 'Product Impression';
258
250
 
259
- try {
260
- function _kms(u) {
261
- setTimeout(function () {
262
- var d = document, f = d.getElementsByTagName('script')[0],
263
- s = d.createElement('script');
264
- s.type = 'text/javascript'; s.async = true; s.src = u;
265
- f.parentNode.insertBefore(s, f);
266
- }, 1);
267
- }
251
+ _kmq.push(function() {
252
+ data.ProductImpressions.forEach(function(impression) {
253
+ KM.set({
254
+ 'Impression Name': impression.Name,
255
+ _t: KM.ts(),
256
+ _d: 1,
257
+ });
268
258
 
269
- var protocol = forwarderSettings.useSecure == 'True' ? 'https:' : '';
259
+ logProductData(impression.ProductList);
260
+ });
261
+ });
270
262
 
271
- if(testMode !== true) {
272
- _kms(protocol + '//i.kissmetrics.com/i.js');
273
- _kms(protocol + '//doug1izaerwt3.cloudfront.net/' + forwarderSettings.apiKey + '.1.js');
274
- }
263
+ _kmq.push(['record', eventName]);
264
+ }
265
+ }
275
266
 
276
- isInitialized = true;
267
+ function initForwarder(settings, service, testMode) {
268
+ forwarderSettings = settings;
269
+ reportingService = service;
277
270
 
278
- return 'Successfully initialized: ' + name;
271
+ try {
272
+ function _kms(u) {
273
+ setTimeout(function() {
274
+ var d = document,
275
+ f = d.getElementsByTagName('script')[0],
276
+ s = d.createElement('script');
277
+ s.type = 'text/javascript';
278
+ s.async = true;
279
+ s.src = u;
280
+ f.parentNode.insertBefore(s, f);
281
+ }, 1);
279
282
  }
280
- catch (e) {
281
- return 'Failed to initialize: ' + name;
283
+
284
+ var protocol =
285
+ forwarderSettings.useSecure == 'True' ? 'https:' : '';
286
+
287
+ if (testMode !== true) {
288
+ _kms(protocol + '//i.kissmetrics.com/i.js');
289
+ _kms(
290
+ protocol +
291
+ '//doug1izaerwt3.cloudfront.net/' +
292
+ forwarderSettings.apiKey +
293
+ '.1.js'
294
+ );
282
295
  }
283
- }
284
296
 
285
- this.init = initForwarder;
286
- this.process = processEvent;
287
- this.setUserIdentity = setUserIdentity;
288
- this.setUserAttribute = setUserAttribute;
289
- };
297
+ isInitialized = true;
290
298
 
291
- function getId() {
292
- return moduleId;
299
+ return 'Successfully initialized: ' + name;
300
+ } catch (e) {
301
+ return 'Failed to initialize: ' + name;
302
+ }
293
303
  }
294
304
 
295
- function register(config) {
296
- if (!config) {
297
- window.console.log('You must pass a config object to register the kit ' + name);
298
- return;
299
- }
305
+ this.init = initForwarder;
306
+ this.process = processEvent;
307
+ this.setUserIdentity = setUserIdentity;
308
+ this.setUserAttribute = setUserAttribute;
309
+ };
300
310
 
301
- if (!isobject$1(config)) {
302
- window.console.log('\'config\' must be an object. You passed in a ' + typeof config);
303
- return;
304
- }
311
+ function getId() {
312
+ return moduleId;
313
+ }
305
314
 
306
- if (isobject$1(config.kits)) {
307
- config.kits[name] = {
308
- constructor: constructor
309
- };
310
- } else {
311
- config.kits = {};
312
- config.kits[name] = {
313
- constructor: constructor
314
- };
315
- }
316
- window.console.log('Successfully registered ' + name + ' to your mParticle configuration');
315
+ function register(config) {
316
+ if (!config) {
317
+ console.log(
318
+ 'You must pass a config object to register the kit ' + name
319
+ );
320
+ return;
321
+ }
322
+
323
+ if (!isobject$1(config)) {
324
+ console.log(
325
+ "'config' must be an object. You passed in a " + typeof config
326
+ );
327
+ return;
328
+ }
329
+
330
+ if (isobject$1(config.kits)) {
331
+ config.kits[name] = {
332
+ constructor: constructor,
333
+ };
334
+ } else {
335
+ config.kits = {};
336
+ config.kits[name] = {
337
+ constructor: constructor,
338
+ };
317
339
  }
340
+ console.log(
341
+ 'Successfully registered ' + name + ' to your mParticle configuration'
342
+ );
343
+ }
318
344
 
345
+ if (typeof window !== 'undefined') {
319
346
  if (window && window.mParticle && window.mParticle.addForwarder) {
320
347
  window.mParticle.addForwarder({
321
348
  name: name,
322
349
  constructor: constructor,
323
- getId: getId
350
+ getId: getId,
324
351
  });
325
352
  }
353
+ }
326
354
 
327
- var KissMetricsForwarder = {
328
- register: register
329
- };
355
+ var KissMetricsForwarder = {
356
+ register: register,
357
+ };
330
358
  var KissMetricsForwarder_1 = KissMetricsForwarder.register;
331
359
 
332
360
  exports.default = KissMetricsForwarder;
package/package.json CHANGED
@@ -1,28 +1,41 @@
1
1
  {
2
- "name": "@mparticle/web-kissmetrics-kit",
3
- "version": "2.0.1",
4
- "author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
5
- "description": "mParticle integration sdk for Kissmetrics",
6
- "main": "dist/KissMetricsForwarder.common.js",
7
- "browser": "dist/KissMetricsForwarder.common.js",
8
- "files": [
9
- "dist/KissMetricsForwarder.common.js"
10
- ],
11
- "repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-kissmetrics",
12
- "scripts": {
13
- "build": "rollup --config rollup.config.js",
14
- "watch": "rollup --config rollup.config.js -w"
15
- },
16
- "devDependencies": {
17
- "should": "^7.1.0",
18
- "mocha": "^2.3.2",
19
- "rollup": "^1.13.1",
20
- "rollup-plugin-commonjs": "^10.0.0",
21
- "rollup-plugin-node-resolve": "^5.0.1"
22
- },
23
- "dependencies": {
24
- "isobject": "^4.0.0",
25
- "@mparticle/web-sdk": "^2.11.1"
26
- },
27
- "license": "Apache-2.0"
2
+ "name": "@mparticle/web-kissmetrics-kit",
3
+ "version": "3.2.0",
4
+ "author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
5
+ "description": "mParticle integration sdk for Kissmetrics",
6
+ "main": "dist/KissMetricsForwarder.common.js",
7
+ "browser": "dist/KissMetricsForwarder.common.js",
8
+ "files": [
9
+ "dist/KissMetricsForwarder.common.js"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/mParticle/mparticle-web-sdk",
14
+ "directory": "kits/kissmetrics"
15
+ },
16
+ "scripts": {
17
+ "build": "rollup --config rollup.config.js",
18
+ "watch": "rollup --config rollup.config.js -w",
19
+ "test": "node test/boilerplate/test-karma.js"
20
+ },
21
+ "devDependencies": {
22
+ "chai": "^4.2.0",
23
+ "karma": "^5.1.0",
24
+ "karma-chai": "^0.1.0",
25
+ "karma-chrome-launcher": "^3.1.0",
26
+ "karma-firefox-launcher": "^1.3.0",
27
+ "karma-mocha": "^2.0.1",
28
+ "mocha": "^2.5.3",
29
+ "rollup": "^1.13.1",
30
+ "rollup-plugin-commonjs": "^10.0.0",
31
+ "rollup-plugin-node-resolve": "^5.0.1",
32
+ "shelljs": "^0.8.4",
33
+ "should": "^7.1.0",
34
+ "watchify": "^3.11.1"
35
+ },
36
+ "dependencies": {
37
+ "isobject": "^4.0.0",
38
+ "@mparticle/web-sdk": "^3.0.0"
39
+ },
40
+ "license": "Apache-2.0"
28
41
  }