@mparticle/web-adobe-client-kit 2.1.3 → 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.
@@ -28,12 +28,12 @@ var MediaEventType = {
28
28
  SegmentStart: 43,
29
29
  SegmentEnd: 44,
30
30
  SegmentSkip: 45,
31
- UpdateQoS: 46
31
+ UpdateQoS: 46,
32
32
  };
33
33
 
34
34
  var ContentType = {
35
35
  Audio: 'Audio',
36
- Video: 'Video'
36
+ Video: 'Video',
37
37
  };
38
38
 
39
39
  var StreamType = {
@@ -41,7 +41,7 @@ var StreamType = {
41
41
  OnDemand: 'OnDemand',
42
42
  Linear: 'Linear',
43
43
  Podcast: 'Podcast',
44
- Audiobook: 'Audiobook'
44
+ Audiobook: 'Audiobook',
45
45
  };
46
46
 
47
47
  function EventHandler(common) {
@@ -269,7 +269,7 @@ var getAdobeMetadataKeys = function(attributes, Heartbeat) {
269
269
  content_mvpd: Heartbeat.VideoMetadataKeys.MVPD,
270
270
  content_authorized: Heartbeat.VideoMetadataKeys.AUTHORIZED,
271
271
  content_daypart: Heartbeat.VideoMetadataKeys.DAY_PART,
272
- content_feed: Heartbeat.VideoMetadataKeys.FEED
272
+ content_feed: Heartbeat.VideoMetadataKeys.FEED,
273
273
  };
274
274
 
275
275
  var adobeMetadataKeys = {};
@@ -425,7 +425,7 @@ var Initialization = {
425
425
  }
426
426
 
427
427
  initHeartbeatCallback();
428
- }
428
+ },
429
429
  };
430
430
 
431
431
  var initialization = Initialization;
@@ -458,7 +458,7 @@ var MessageType = {
458
458
  CrashReport: 5,
459
459
  OptOut: 6,
460
460
  Commerce: 16,
461
- Media: 20
461
+ Media: 20,
462
462
  };
463
463
 
464
464
  function constructor() {
@@ -542,7 +542,7 @@ function constructor() {
542
542
  return true;
543
543
  } catch (e) {
544
544
  return {
545
- error: 'Error logging event on forwarder ' + name + '; ' + e
545
+ error: 'Error logging event on forwarder ' + name + '; ' + e,
546
546
  };
547
547
  }
548
548
  }
@@ -556,7 +556,7 @@ if (window.mParticle && window.mParticle.registerHBK) {
556
556
  }
557
557
 
558
558
  var src = {
559
- AdobeHbkConstructor: constructor
559
+ AdobeHbkConstructor: constructor,
560
560
  };
561
561
  var src_1 = src.AdobeHbkConstructor;
562
562
 
@@ -653,7 +653,7 @@ var name = 'Adobe',
653
653
  CrashReport: 5,
654
654
  OptOut: 6,
655
655
  Commerce: 16,
656
- Media: 20
656
+ Media: 20,
657
657
  },
658
658
  //Custom Flag Names
659
659
  LINK_NAME = 'Adobe.LinkName',
@@ -810,14 +810,14 @@ var constructor$1 = function() {
810
810
  }
811
811
 
812
812
  return {
813
- result: false
813
+ result: false,
814
814
  };
815
815
  });
816
816
 
817
817
  if (filteredArray && filteredArray.length > 0) {
818
818
  return {
819
819
  result: true,
820
- matches: filteredArray
820
+ matches: filteredArray,
821
821
  };
822
822
  }
823
823
  }
@@ -1231,7 +1231,7 @@ var constructor$1 = function() {
1231
1231
  if (Object.keys(userIdentities).length) {
1232
1232
  for (var identity in userIdentities) {
1233
1233
  identitiesToSet[identity] = {
1234
- id: userIdentities[identity]
1234
+ id: userIdentities[identity],
1235
1235
  };
1236
1236
  }
1237
1237
  } else {
@@ -1276,7 +1276,7 @@ if (window && window.mParticle && window.mParticle.addForwarder) {
1276
1276
  window.mParticle.addForwarder({
1277
1277
  name: name,
1278
1278
  constructor: constructor$1,
1279
- getId: getId
1279
+ getId: getId,
1280
1280
  });
1281
1281
  }
1282
1282
 
@@ -1297,12 +1297,12 @@ function register(config) {
1297
1297
 
1298
1298
  if (isObject(config.kits)) {
1299
1299
  config.kits[name] = {
1300
- constructor: constructor$1
1300
+ constructor: constructor$1,
1301
1301
  };
1302
1302
  } else {
1303
1303
  config.kits = {};
1304
1304
  config.kits[name] = {
1305
- constructor: constructor$1
1305
+ constructor: constructor$1,
1306
1306
  };
1307
1307
  }
1308
1308
  window.console.log(
@@ -1317,7 +1317,7 @@ function isObject(val) {
1317
1317
  }
1318
1318
 
1319
1319
  var AdobeClientSideKit_esm = {
1320
- register: register
1320
+ register: register,
1321
1321
  };
1322
1322
 
1323
1323
  module.exports = AdobeClientSideKit_esm;
@@ -1,4 +1,4 @@
1
- var mParticleAdobe = (function () {
1
+ var mParticleAdobeClient = (function () {
2
2
  function Common() {
3
3
  this.playheadPosition = 0;
4
4
  this.startupTime = 0;
@@ -29,12 +29,12 @@ var mParticleAdobe = (function () {
29
29
  SegmentStart: 43,
30
30
  SegmentEnd: 44,
31
31
  SegmentSkip: 45,
32
- UpdateQoS: 46
32
+ UpdateQoS: 46,
33
33
  };
34
34
 
35
35
  var ContentType = {
36
36
  Audio: 'Audio',
37
- Video: 'Video'
37
+ Video: 'Video',
38
38
  };
39
39
 
40
40
  var StreamType = {
@@ -42,7 +42,7 @@ var mParticleAdobe = (function () {
42
42
  OnDemand: 'OnDemand',
43
43
  Linear: 'Linear',
44
44
  Podcast: 'Podcast',
45
- Audiobook: 'Audiobook'
45
+ Audiobook: 'Audiobook',
46
46
  };
47
47
 
48
48
  function EventHandler(common) {
@@ -270,7 +270,7 @@ var mParticleAdobe = (function () {
270
270
  content_mvpd: Heartbeat.VideoMetadataKeys.MVPD,
271
271
  content_authorized: Heartbeat.VideoMetadataKeys.AUTHORIZED,
272
272
  content_daypart: Heartbeat.VideoMetadataKeys.DAY_PART,
273
- content_feed: Heartbeat.VideoMetadataKeys.FEED
273
+ content_feed: Heartbeat.VideoMetadataKeys.FEED,
274
274
  };
275
275
 
276
276
  var adobeMetadataKeys = {};
@@ -426,7 +426,7 @@ var mParticleAdobe = (function () {
426
426
  }
427
427
 
428
428
  initHeartbeatCallback();
429
- }
429
+ },
430
430
  };
431
431
 
432
432
  var initialization = Initialization;
@@ -459,7 +459,7 @@ var mParticleAdobe = (function () {
459
459
  CrashReport: 5,
460
460
  OptOut: 6,
461
461
  Commerce: 16,
462
- Media: 20
462
+ Media: 20,
463
463
  };
464
464
 
465
465
  function constructor() {
@@ -543,7 +543,7 @@ var mParticleAdobe = (function () {
543
543
  return true;
544
544
  } catch (e) {
545
545
  return {
546
- error: 'Error logging event on forwarder ' + name + '; ' + e
546
+ error: 'Error logging event on forwarder ' + name + '; ' + e,
547
547
  };
548
548
  }
549
549
  }
@@ -557,7 +557,7 @@ var mParticleAdobe = (function () {
557
557
  }
558
558
 
559
559
  var src = {
560
- AdobeHbkConstructor: constructor
560
+ AdobeHbkConstructor: constructor,
561
561
  };
562
562
  var src_1 = src.AdobeHbkConstructor;
563
563
 
@@ -654,7 +654,7 @@ var mParticleAdobe = (function () {
654
654
  CrashReport: 5,
655
655
  OptOut: 6,
656
656
  Commerce: 16,
657
- Media: 20
657
+ Media: 20,
658
658
  },
659
659
  //Custom Flag Names
660
660
  LINK_NAME = 'Adobe.LinkName',
@@ -811,14 +811,14 @@ var mParticleAdobe = (function () {
811
811
  }
812
812
 
813
813
  return {
814
- result: false
814
+ result: false,
815
815
  };
816
816
  });
817
817
 
818
818
  if (filteredArray && filteredArray.length > 0) {
819
819
  return {
820
820
  result: true,
821
- matches: filteredArray
821
+ matches: filteredArray,
822
822
  };
823
823
  }
824
824
  }
@@ -1232,7 +1232,7 @@ var mParticleAdobe = (function () {
1232
1232
  if (Object.keys(userIdentities).length) {
1233
1233
  for (var identity in userIdentities) {
1234
1234
  identitiesToSet[identity] = {
1235
- id: userIdentities[identity]
1235
+ id: userIdentities[identity],
1236
1236
  };
1237
1237
  }
1238
1238
  } else {
@@ -1277,7 +1277,7 @@ var mParticleAdobe = (function () {
1277
1277
  window.mParticle.addForwarder({
1278
1278
  name: name,
1279
1279
  constructor: constructor$1,
1280
- getId: getId
1280
+ getId: getId,
1281
1281
  });
1282
1282
  }
1283
1283
 
@@ -1298,12 +1298,12 @@ var mParticleAdobe = (function () {
1298
1298
 
1299
1299
  if (isObject(config.kits)) {
1300
1300
  config.kits[name] = {
1301
- constructor: constructor$1
1301
+ constructor: constructor$1,
1302
1302
  };
1303
1303
  } else {
1304
1304
  config.kits = {};
1305
1305
  config.kits[name] = {
1306
- constructor: constructor$1
1306
+ constructor: constructor$1,
1307
1307
  };
1308
1308
  }
1309
1309
  window.console.log(
@@ -1318,7 +1318,7 @@ var mParticleAdobe = (function () {
1318
1318
  }
1319
1319
 
1320
1320
  var AdobeClientSideKit_esm = {
1321
- register: register
1321
+ register: register,
1322
1322
  };
1323
1323
 
1324
1324
  return AdobeClientSideKit_esm;
package/package.json CHANGED
@@ -1,16 +1,23 @@
1
1
  {
2
- "name": "@mparticle/web-adobe-client-kit",
3
- "version": "2.1.3",
4
- "description": "mParticle integration sdk for Adobe (client side)",
5
- "main": "dist/AdobeClientSideKit.common.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
10
- "license": "Apache-2.0",
11
- "publishConfig": {
12
- "access": "public"
13
- },
14
- "repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-adobe/tree/master/packages/AdobeClient",
15
- "gitHead": "e37f85d60b1ecce6ebbdce8bd92c92e72a331b9b"
2
+ "name": "@mparticle/web-adobe-client-kit",
3
+ "version": "3.2.0",
4
+ "description": "mParticle integration sdk for Adobe (client side)",
5
+ "main": "dist/AdobeClientSideKit.common.js",
6
+ "files": [
7
+ "dist/AdobeClientSideKit.common.js",
8
+ "dist/AdobeClientSideKit.iife.js"
9
+ ],
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
14
+ "license": "Apache-2.0",
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/mParticle/mparticle-web-sdk",
21
+ "directory": "kits/adobe/packages/AdobeClient"
22
+ }
16
23
  }
@@ -1,698 +0,0 @@
1
- // START OF ADOBE MPARTICLE JS INTEGRATION
2
-
3
- /* eslint-disable no-undef */
4
-
5
- //
6
- // Copyright 2018 mParticle, Inc.
7
- //
8
- // Licensed under the Apache License, Version 2.0 (the 'License');
9
- // you may not use this file except in compliance with the License.
10
- // You may obtain a copy of the License at
11
- //
12
- // http://www.apache.org/licenses/LICENSE-2.0
13
- //
14
- // Unless required by applicable law or agreed to in writing, software
15
- // distributed under the License is distributed on an 'AS IS' BASIS,
16
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- // See the License for the specific language governing permissions and
18
- // limitations under the License.
19
-
20
- import { AdobeHbkConstructor } from '../../../HeartbeatKit/dist/AdobeHBKit.esm.js';
21
-
22
- var name = 'Adobe',
23
- ADOBEMODULENUMBER = 124,
24
- MARKETINGCLOUDIDKEY = 'mid',
25
- MessageType = {
26
- SessionStart: 1,
27
- SessionEnd: 2,
28
- PageView: 3,
29
- PageEvent: 4,
30
- CrashReport: 5,
31
- OptOut: 6,
32
- Commerce: 16,
33
- Media: 20
34
- },
35
- //Custom Flag Names
36
- LINK_NAME = 'Adobe.LinkName',
37
- PAGE_NAME = 'Adobe.PageName';
38
-
39
- var constructor = function() {
40
- var self = this,
41
- //one or more instances of AppMeasurement returned from s_gi()
42
- appMeasurement,
43
- settings,
44
- timestampOption,
45
- isAdobeClientKitInitialized = false,
46
- reportingService,
47
- contextVariableMapping,
48
- productIncrementorMapping,
49
- productMerchandisingMapping,
50
- propsMapping,
51
- eVarsMapping,
52
- hiersMapping,
53
- eventsMapping;
54
-
55
- (self.adobeMediaSDK = new AdobeHbkConstructor()), (self.name = name);
56
-
57
- function initForwarder(forwarderSettings, service, testMode) {
58
- settings = forwarderSettings;
59
- reportingService = service;
60
- try {
61
- loadMappings();
62
- timestampOption =
63
- settings.timestampOption === 'optional' ||
64
- settings.timestampOption === 'required';
65
- finishAdobeInitialization();
66
- if (settings.mediaTrackingServer) {
67
- self.adobeMediaSDK.init(forwarderSettings, service, testMode);
68
- }
69
- isAdobeClientKitInitialized = true;
70
-
71
- return 'ClientSDK successfully loaded';
72
- } catch (e) {
73
- return 'Failed to initialize: ' + e;
74
- }
75
- }
76
-
77
- function loadMappings() {
78
- eVarsMapping = settings.evars
79
- ? JSON.parse(settings.evars.replace(/&quot;/g, '"'))
80
- : [];
81
- propsMapping = settings.props
82
- ? JSON.parse(settings.props.replace(/&quot;/g, '"'))
83
- : [];
84
- productIncrementorMapping = settings.productIncrementor
85
- ? JSON.parse(settings.productIncrementor.replace(/&quot;/g, '"'))
86
- : [];
87
- productMerchandisingMapping = settings.productMerchandising
88
- ? JSON.parse(settings.productMerchandising.replace(/&quot;/g, '"'))
89
- : [];
90
- hiersMapping = settings.hvars
91
- ? JSON.parse(settings.hvars.replace(/&quot;/g, '"'))
92
- : [];
93
- eventsMapping = settings.events
94
- ? JSON.parse(settings.events.replace(/&quot;/g, '"'))
95
- : [];
96
- contextVariableMapping = settings.contextVariables
97
- ? JSON.parse(settings.contextVariables.replace(/&quot;/g, '"'))
98
- : [];
99
- }
100
-
101
- function finishAdobeInitialization() {
102
- var visitorOptions = {};
103
- if (settings.audienceManagerServer) {
104
- visitorOptions.audienceManagerServer =
105
- settings.audienceManagerServer;
106
- }
107
- try {
108
- appMeasurement = s_gi(settings.reportSuiteIDs);
109
- if (settings.setGlobalObject === 'True') {
110
- window.s = appMeasurement;
111
- }
112
- appMeasurement.visitor = Visitor.getInstance(
113
- settings.organizationID,
114
- visitorOptions
115
- );
116
-
117
- appMeasurement.trackingServer = settings.trackingServer;
118
-
119
- appMeasurement.trackDownloadLinks = true;
120
- appMeasurement.trackExternalLinks =
121
- settings.trackExternalLinks === 'True';
122
- appMeasurement.trackInlineStats = true;
123
- appMeasurement.linkDownloadFileTypes =
124
- 'exe,zip,wav,mp3,mov,mpg,avi,wmv,pdf,doc,docx,xls,xlsx,ppt,pptx';
125
- appMeasurement.linkInternalFilters = 'javascript:';
126
- appMeasurement.linkLeaveQueryString = false;
127
- appMeasurement.linkTrackVars = 'None';
128
- appMeasurement.linkTrackEvents = 'None';
129
- appMeasurement.visitorNamespace = '';
130
-
131
- // On first load, adobe will call the callback correctly if no MCID exists
132
- // On subsequent loads, it does not, so we need to manually call setMCIDOnIntegrationAttributes
133
- var mcID = Visitor.getInstance(
134
- settings.organizationID,
135
- visitorOptions
136
- ).getMarketingCloudVisitorID(setMarketingCloudId);
137
- if (mcID && mcID.length > 0) {
138
- setMCIDOnIntegrationAttributes(mcID);
139
- }
140
-
141
- return true;
142
- } catch (e) {
143
- return 'error initializing adobe: ' + e;
144
- }
145
- }
146
-
147
- function setMarketingCloudId(mcid) {
148
- setMCIDOnIntegrationAttributes(mcid);
149
- }
150
-
151
- function setMCIDOnIntegrationAttributes(mcid) {
152
- var adobeIntegrationAttributes = {};
153
- adobeIntegrationAttributes[MARKETINGCLOUDIDKEY] = mcid;
154
- mParticle.setIntegrationAttribute(
155
- ADOBEMODULENUMBER,
156
- adobeIntegrationAttributes
157
- );
158
- mParticle._setIntegrationDelay(ADOBEMODULENUMBER, false);
159
- }
160
-
161
- // Get the mapped value for custom events
162
- function getEventMappingValue(event) {
163
- var jsHash = calculateJSHash(
164
- event.EventDataType,
165
- event.EventCategory,
166
- event.EventName
167
- );
168
- return findValueInMapping(jsHash, eventsMapping);
169
- }
170
-
171
- function calculateJSHash(eventDataType, eventCategory, name) {
172
- var preHash =
173
- '' + eventDataType + ('' + eventCategory) + '' + (name || '');
174
-
175
- return mParticle.generateHash(preHash);
176
- }
177
-
178
- function findValueInMapping(jsHash, mapping) {
179
- if (mapping) {
180
- var filteredArray = mapping.filter(function(mappingEntry) {
181
- if (
182
- mappingEntry.jsmap &&
183
- mappingEntry.maptype &&
184
- mappingEntry.value
185
- ) {
186
- return mappingEntry.jsmap === jsHash.toString();
187
- }
188
-
189
- return {
190
- result: false
191
- };
192
- });
193
-
194
- if (filteredArray && filteredArray.length > 0) {
195
- return {
196
- result: true,
197
- matches: filteredArray
198
- };
199
- }
200
- }
201
- return null;
202
- }
203
-
204
- // for each type of event, we run setMappings which sets the eVars, props, hvars, and contextData values
205
- // after each event is sent to the server (either using t() for pageViews or tl() for non-pageview events), clearVars() is run to wipe out
206
- function resetVariables() {
207
- appMeasurement.clearVars();
208
- appMeasurement.contextData = {};
209
- }
210
- // any eVars, props, and hvars
211
- function processEvent(event) {
212
- var linkName,
213
- pageName,
214
- reportEvent = false,
215
- linkTrackVars = [];
216
-
217
- appMeasurement.timestamp = timestampOption
218
- ? Math.floor(new Date().getTime() / 1000)
219
- : null;
220
- appMeasurement.events = '';
221
- if (event.CustomFlags && event.CustomFlags.hasOwnProperty(LINK_NAME)) {
222
- linkName = event.CustomFlags[LINK_NAME];
223
- }
224
- if (event.CustomFlags && event.CustomFlags.hasOwnProperty(PAGE_NAME)) {
225
- pageName = event.CustomFlags[PAGE_NAME];
226
- }
227
-
228
- if (isAdobeClientKitInitialized) {
229
- try {
230
- // First determine if an eventName is mapped, if so, log it as an event as opposed to a pageview or commerceview
231
- // ex. If a pageview is mapped to an event, we logEvent instead of logging it as a pageview
232
- var eventMapping = getEventMappingValue(event);
233
-
234
- if (
235
- eventMapping &&
236
- eventMapping.result &&
237
- eventMapping.matches
238
- ) {
239
- setMappings(event, true, linkTrackVars);
240
- reportEvent = logEvent(
241
- event,
242
- linkTrackVars,
243
- eventMapping.matches,
244
- linkName,
245
- pageName
246
- );
247
- } else if (event.EventDataType === MessageType.PageView) {
248
- setMappings(event, false);
249
- reportEvent = logPageView(event, pageName);
250
- } else if (event.EventDataType === MessageType.Commerce) {
251
- setMappings(event, true, linkTrackVars);
252
- reportEvent = processCommerceTransaction(
253
- event,
254
- linkTrackVars,
255
- linkName,
256
- pageName
257
- );
258
- } else if (event.EventDataType === MessageType.Media) {
259
- self.adobeMediaSDK.process(event);
260
- } else {
261
- return 'event name not mapped, aborting event logging';
262
- }
263
-
264
- if (
265
- reportEvent === true &&
266
- reportingService &&
267
- event.EventDataType
268
- ) {
269
- reportingService(self, event);
270
- return 'Successfully sent to ' + name;
271
- }
272
- } catch (e) {
273
- return 'Failed to send to: ' + name + ' ' + e;
274
- }
275
- }
276
-
277
- return 'Cannot send to forwarder ' + name + ', not initialized.';
278
- }
279
-
280
- function setMappings(event, includeTrackVars, linkTrackVars) {
281
- if (includeTrackVars) {
282
- setEvars(event, linkTrackVars);
283
- setProps(event, linkTrackVars);
284
- setHiers(event, linkTrackVars);
285
- setContextData(event, linkTrackVars);
286
- } else {
287
- setEvars(event);
288
- setProps(event);
289
- setHiers(event);
290
- setContextData(event);
291
- }
292
- }
293
-
294
- function processCommerceTransaction(
295
- event,
296
- linkTrackVars,
297
- linkName,
298
- pageName
299
- ) {
300
- if (
301
- event.EventCategory === mParticle.CommerceEventType.ProductPurchase
302
- ) {
303
- appMeasurement.events = 'purchase';
304
- appMeasurement.purchaseID = event.ProductAction.TransactionId;
305
- appMeasurement.transactionID = event.ProductAction.TransactionId;
306
- linkTrackVars.push('purchaseID', 'transactionID');
307
- } else if (
308
- event.EventCategory ===
309
- mParticle.CommerceEventType.ProductViewDetail
310
- ) {
311
- appMeasurement.events = 'prodView';
312
- } else if (
313
- event.EventCategory === mParticle.CommerceEventType.ProductAddToCart
314
- ) {
315
- appMeasurement.events = 'scAdd';
316
- } else if (
317
- event.EventCategory ===
318
- mParticle.CommerceEventType.ProductRemoveFromCart
319
- ) {
320
- appMeasurement.events = 'scRemove';
321
- } else if (
322
- event.EventCategory === mParticle.CommerceEventType.ProductCheckout
323
- ) {
324
- appMeasurement.events = 'scCheckout';
325
- }
326
- appMeasurement.linkTrackEvents = appMeasurement.events || null;
327
- processProductsAndSetEvents(event, linkTrackVars);
328
-
329
- linkTrackVars.push('products', 'events');
330
- setPageName(linkTrackVars, appMeasurement, pageName);
331
- appMeasurement.linkTrackVars = linkTrackVars;
332
- appMeasurement.tl(true, 'o', linkName);
333
-
334
- resetVariables();
335
-
336
- return true;
337
- }
338
-
339
- function processProductsAndSetEvents(event) {
340
- try {
341
- var productDetails,
342
- incrementor,
343
- merchandising,
344
- productBuilder,
345
- product,
346
- allProducts = [];
347
-
348
- var expandedEvents = mParticle.eCommerce.expandCommerceEvent(event);
349
- expandedEvents.forEach(function(expandedEvt) {
350
- productBuilder = [];
351
- productDetails = [];
352
- incrementor = [];
353
- merchandising = [];
354
-
355
- if (expandedEvt.EventName === 'eCommerce - purchase - Total') {
356
- for (var eventAttributeKey in expandedEvt.EventAttributes) {
357
- if (
358
- expandedEvt.EventAttributes.hasOwnProperty(
359
- eventAttributeKey
360
- )
361
- ) {
362
- var jsHash = calculateJSHash(
363
- event.EventDataType,
364
- event.EventCategory,
365
- eventAttributeKey
366
- );
367
- var mapping = findValueInMapping(
368
- jsHash,
369
- eventsMapping
370
- );
371
- if (mapping && mapping.result && mapping.matches) {
372
- mapping.matches.forEach(function(mapping) {
373
- if (mapping.value) {
374
- if (
375
- appMeasurement.events.indexOf(
376
- mapping.value
377
- ) < 0
378
- ) {
379
- appMeasurement.events +=
380
- ',' +
381
- mapping.value +
382
- '=' +
383
- expandedEvt.EventAttributes[
384
- eventAttributeKey
385
- ];
386
- }
387
- }
388
- });
389
- }
390
- }
391
- }
392
- } else {
393
- var productAttributes = expandedEvt.EventAttributes;
394
- productDetails.push(
395
- productAttributes.Category || '',
396
- productAttributes.Name,
397
- productAttributes.Id,
398
- productAttributes.Quantity || 1,
399
- productAttributes['Item Price'] || 0
400
- );
401
- for (var productAttributeKey in expandedEvt.EventAttributes) {
402
- if (
403
- expandedEvt.EventAttributes.hasOwnProperty(
404
- productAttributeKey
405
- )
406
- ) {
407
- productIncrementorMapping.forEach(function(
408
- productIncrementorMap
409
- ) {
410
- if (
411
- productIncrementorMap.map ===
412
- productAttributeKey
413
- ) {
414
- incrementor.push(
415
- productIncrementorMap.value +
416
- '=' +
417
- productAttributes[
418
- productAttributeKey
419
- ]
420
- );
421
- if (
422
- appMeasurement.events.indexOf(
423
- productIncrementorMap.value
424
- ) < 0
425
- ) {
426
- appMeasurement.events +=
427
- ',' + productIncrementorMap.value;
428
- }
429
- }
430
- });
431
- productMerchandisingMapping.forEach(function(
432
- productMerchandisingMap
433
- ) {
434
- if (
435
- productMerchandisingMap.map ===
436
- productAttributeKey
437
- ) {
438
- merchandising.push(
439
- productMerchandisingMap.value +
440
- '=' +
441
- productAttributes[
442
- productAttributeKey
443
- ]
444
- );
445
- }
446
- });
447
- }
448
- }
449
- productBuilder.push(
450
- productDetails.join(';'),
451
- incrementor.join('|'),
452
- merchandising.join('|')
453
- );
454
- product = productBuilder.join(';');
455
- allProducts.push(product);
456
- }
457
- });
458
-
459
- appMeasurement.products = allProducts.join(',');
460
- } catch (e) {
461
- window.console.log(e);
462
- }
463
- }
464
-
465
- function logPageView(event, pageName) {
466
- try {
467
- appMeasurement.pageName =
468
- pageName || event.EventName || window.document.title;
469
- appMeasurement.t();
470
- resetVariables();
471
- return true;
472
- } catch (e) {
473
- resetVariables();
474
- return { error: 'logPageView not called, error ' + e };
475
- }
476
- }
477
-
478
- function logEvent(
479
- event,
480
- linkTrackVars,
481
- mappingMatches,
482
- linkName,
483
- pageName
484
- ) {
485
- try {
486
- if (mappingMatches) {
487
- mappingMatches.forEach(function(match) {
488
- if (appMeasurement.events.length === 0) {
489
- appMeasurement.events += match.value;
490
- } else {
491
- appMeasurement.events += ',' + match.value;
492
- }
493
- });
494
- appMeasurement.linkTrackEvents = appMeasurement.events;
495
-
496
- linkTrackVars.push('events');
497
- setPageName(linkTrackVars, appMeasurement, pageName);
498
-
499
- appMeasurement.linkTrackVars = linkTrackVars;
500
-
501
- appMeasurement.tl(true, 'o', linkName);
502
- resetVariables();
503
- return true;
504
- } else {
505
- resetVariables();
506
- window.console.log(
507
- 'event name not mapped, aborting event logging'
508
- );
509
- return false;
510
- }
511
- } catch (e) {
512
- resetVariables();
513
- return { error: e };
514
- }
515
- }
516
-
517
- // .map is the attribute passed through, .value is the eVar value
518
- function setEvars(event, linkTrackVars) {
519
- var eventAttributes = event.EventAttributes;
520
- for (var eventAttributeKey in eventAttributes) {
521
- if (eventAttributes.hasOwnProperty(eventAttributeKey)) {
522
- eVarsMapping.forEach(function(eVarMap) {
523
- if (eVarMap.map === eventAttributeKey) {
524
- appMeasurement[eVarMap.value] =
525
- eventAttributes[eventAttributeKey];
526
- if (linkTrackVars) {
527
- linkTrackVars.push(eVarMap.value);
528
- }
529
- }
530
- if (event.EventName === eVarMap.map) {
531
- appMeasurement[eVarMap.value] = event.EventName;
532
- }
533
- });
534
- }
535
- }
536
- }
537
-
538
- // .map is the attribute passed through, .value is the prop value
539
- function setProps(event, linkTrackVars) {
540
- var eventAttributes = event.EventAttributes;
541
- for (var eventAttributeKey in eventAttributes) {
542
- if (eventAttributes.hasOwnProperty(eventAttributeKey)) {
543
- propsMapping.forEach(function(propMap) {
544
- if (propMap.map === eventAttributeKey) {
545
- appMeasurement[propMap.value] =
546
- eventAttributes[eventAttributeKey];
547
- if (linkTrackVars) {
548
- linkTrackVars.push(propMap.value);
549
- }
550
- }
551
- });
552
- }
553
- }
554
- }
555
-
556
- // .map is the attribute passed through, .value is the hier value
557
- function setHiers(event, linkTrackVars) {
558
- var eventAttributes = event.EventAttributes;
559
- for (var eventAttributeKey in eventAttributes) {
560
- if (eventAttributes.hasOwnProperty(eventAttributeKey)) {
561
- var jsHash = calculateJSHash(
562
- event.EventDataType,
563
- event.EventCategory,
564
- eventAttributeKey
565
- );
566
- var mapping = findValueInMapping(jsHash, hiersMapping);
567
- if (mapping && mapping.result && mapping.matches) {
568
- mapping.matches.forEach(function(mapping) {
569
- if (mapping.value) {
570
- appMeasurement[mapping.value] =
571
- eventAttributes[eventAttributeKey];
572
- if (linkTrackVars) {
573
- linkTrackVars.push(mapping.value);
574
- }
575
- }
576
- });
577
- }
578
- }
579
- }
580
- }
581
-
582
- // .map is the attribute passed through, .value is the contextData value
583
- function setContextData(event, linkTrackVars) {
584
- var eventAttributes = event.EventAttributes;
585
- for (var eventAttributeKey in eventAttributes) {
586
- if (eventAttributes.hasOwnProperty(eventAttributeKey)) {
587
- contextVariableMapping.forEach(function(contextVariableMap) {
588
- if (contextVariableMap.map === eventAttributeKey) {
589
- appMeasurement.contextData[contextVariableMap.value] =
590
- eventAttributes[eventAttributeKey];
591
- if (linkTrackVars) {
592
- linkTrackVars.push(
593
- 'contextData.' + contextVariableMap.value
594
- );
595
- }
596
- }
597
- });
598
- }
599
- }
600
- }
601
-
602
- function onUserIdentified(mpUserObject) {
603
- if (isAdobeClientKitInitialized) {
604
- var userIdentities = mpUserObject.getUserIdentities()
605
- .userIdentities;
606
-
607
- var identitiesToSet = {};
608
- if (Object.keys(userIdentities).length) {
609
- for (var identity in userIdentities) {
610
- identitiesToSet[identity] = {
611
- id: userIdentities[identity]
612
- };
613
- }
614
- } else {
615
- // no user identities means there was a logout, so set all current customer ids to null
616
- var currentAdobeCustomerIds = appMeasurement.visitor.getCustomerIDs();
617
- for (var currentIdentityKey in currentAdobeCustomerIds) {
618
- identitiesToSet[currentIdentityKey] = null;
619
- }
620
- }
621
-
622
- try {
623
- appMeasurement.visitor.setCustomerIDs(identitiesToSet);
624
- } catch (e) {
625
- return 'Error calling setCustomerIDs on adobe';
626
- }
627
- } else {
628
- return (
629
- 'Cannot call setUserIdentity on forwarder ' +
630
- name +
631
- ', not initialized'
632
- );
633
- }
634
- }
635
-
636
- function setPageName(linkTrackVars, appMeasurement, pageName) {
637
- if (settings.enablePageName === 'True') {
638
- appMeasurement.pageName = pageName || window.document.title;
639
- linkTrackVars.push('pageName');
640
- }
641
- }
642
-
643
- this.init = initForwarder;
644
- this.onUserIdentified = onUserIdentified;
645
- this.process = processEvent;
646
- };
647
-
648
- function getId() {
649
- return moduleId;
650
- }
651
-
652
- if (window && window.mParticle && window.mParticle.addForwarder) {
653
- window.mParticle.addForwarder({
654
- name: name,
655
- constructor: constructor,
656
- getId: getId
657
- });
658
- }
659
-
660
- function register(config) {
661
- if (!config) {
662
- window.console.log(
663
- 'You must pass a config object to register the kit ' + name
664
- );
665
- return;
666
- }
667
-
668
- if (!isObject(config)) {
669
- window.console.log(
670
- '`config` must be an object. You passed in a ' + typeof config
671
- );
672
- return;
673
- }
674
-
675
- if (isObject(config.kits)) {
676
- config.kits[name] = {
677
- constructor: constructor
678
- };
679
- } else {
680
- config.kits = {};
681
- config.kits[name] = {
682
- constructor: constructor
683
- };
684
- }
685
- window.console.log(
686
- 'Successfully registered ' + name + ' to your mParticle configuration'
687
- );
688
- }
689
-
690
- function isObject(val) {
691
- return (
692
- val != null && typeof val === 'object' && Array.isArray(val) === false
693
- );
694
- }
695
-
696
- export default {
697
- register: register
698
- };