@mparticle/web-adwords-kit 2.3.1 → 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.
@@ -17,672 +17,823 @@ Object.defineProperty(exports, '__esModule', { value: true });
17
17
  // See the License for the specific language governing permissions and
18
18
  // limitations under the License.
19
19
 
20
- var name = 'GoogleAdWords',
21
- moduleId = 82,
22
- MessageType = {
23
- SessionStart: 1,
24
- SessionEnd: 2,
25
- PageView: 3,
26
- PageEvent: 4,
27
- CrashReport: 5,
28
- OptOut: 6,
29
- Commerce: 16
30
- },
31
- ENHANCED_CONVERSION_DATA = "GoogleAds.ECData";
32
-
33
- // Declares valid Google consent values
34
- var googleConsentValues = {
35
- // Server Integration uses 'Unspecified' as a value when the setting is 'not set'.
36
- // However, this is not used by Google's Web SDK. We are referencing it here as a comment
37
- // as a record of this distinction and for posterity.
38
- // If Google ever adds this for web, the line can just be uncommented to support this.
39
- //
40
- // Docs:
41
- // Web: https://developers.google.com/tag-platform/gtagjs/reference#consent
42
- // S2S: https://developers.google.com/google-ads/api/reference/rpc/v15/ConsentStatusEnum.ConsentStatus
43
- //
44
- // Unspecified: 'unspecified',
45
- Denied: 'denied',
46
- Granted: 'granted',
47
- };
48
-
49
- // Declares list of valid Google Consent Properties
50
- var googleConsentProperties = [
51
- 'ad_storage',
52
- 'ad_user_data',
53
- 'ad_personalization',
54
- 'analytics_storage',
55
- ];
56
-
57
- var constructor = function () {
58
- var self = this,
59
- isInitialized = false,
60
- forwarderSettings,
61
- labels,
62
- customAttributeMappings,
63
- consentMappings = [],
64
- consentPayloadDefaults = {},
65
- consentPayloadAsString = '',
66
- reportingService,
67
- eventQueue = [],
68
- gtagSiteId;
69
-
70
- self.name = name;
71
-
72
- function processEvent(event) {
73
- var reportEvent = false;
74
- var sendEventFunction = function() {};
75
- var generateEventFunction = function () {};
76
- var conversionLabel;
77
- var eventPayload;
78
-
79
- if (isInitialized) {
80
- // First, process anything in the queue
81
- processQueue(eventQueue);
20
+ var name = 'GoogleAdWords',
21
+ moduleId = 82,
22
+ MessageType = {
23
+ SessionStart: 1,
24
+ SessionEnd: 2,
25
+ PageView: 3,
26
+ PageEvent: 4,
27
+ CrashReport: 5,
28
+ OptOut: 6,
29
+ Commerce: 16,
30
+ },
31
+ ENHANCED_CONVERSION_DATA = 'GoogleAds.ECData';
32
+
33
+ // Declares valid Google consent values
34
+ var googleConsentValues = {
35
+ // Server Integration uses 'Unspecified' as a value when the setting is 'not set'.
36
+ // However, this is not used by Google's Web SDK. We are referencing it here as a comment
37
+ // as a record of this distinction and for posterity.
38
+ // If Google ever adds this for web, the line can just be uncommented to support this.
39
+ //
40
+ // Docs:
41
+ // Web: https://developers.google.com/tag-platform/gtagjs/reference#consent
42
+ // S2S: https://developers.google.com/google-ads/api/reference/rpc/v15/ConsentStatusEnum.ConsentStatus
43
+ //
44
+ // Unspecified: 'unspecified',
45
+ Denied: 'denied',
46
+ Granted: 'granted',
47
+ };
48
+
49
+ // Declares list of valid Google Consent Properties
50
+ var googleConsentProperties = [
51
+ 'ad_storage',
52
+ 'ad_user_data',
53
+ 'ad_personalization',
54
+ 'analytics_storage',
55
+ ];
56
+
57
+ var constructor = function() {
58
+ var self = this,
59
+ isInitialized = false,
60
+ forwarderSettings,
61
+ labels,
62
+ customAttributeMappings,
63
+ consentMappings = [],
64
+ consentPayloadDefaults = {},
65
+ consentPayloadAsString = '',
66
+ reportingService,
67
+ eventQueue = [],
68
+ gtagSiteId;
69
+
70
+ self.name = name;
71
+
72
+ function processEvent(event) {
73
+ var reportEvent = false;
74
+ var sendEventFunction = function() {};
75
+ var generateEventFunction = function() {};
76
+ var conversionLabel;
77
+ var eventPayload;
78
+
79
+ if (isInitialized) {
80
+ // First, process anything in the queue
81
+ processQueue(eventQueue);
82
+
83
+ try {
84
+ if (window.gtag && forwarderSettings.enableGtag == 'True') {
85
+ // If consent payload is empty,
86
+ // we never sent an initial default consent state
87
+ // so we shouldn't send an update.
88
+ var eventConsentState = getEventConsentState(
89
+ event.ConsentState
90
+ );
91
+ maybeSendConsentUpdateToGoogle(eventConsentState);
92
+
93
+ if (
94
+ forwarderSettings.enableEnhancedConversions ===
95
+ 'True' &&
96
+ hasEnhancedConversionData(event.CustomFlags)
97
+ ) {
98
+ window.enhanced_conversion_data = parseEnhancedConversionData(
99
+ event.CustomFlags[ENHANCED_CONVERSION_DATA]
100
+ );
101
+ }
82
102
 
83
- try {
84
- if (window.gtag && forwarderSettings.enableGtag == 'True') {
85
- // If consent payload is empty,
86
- // we never sent an initial default consent state
87
- // so we shouldn't send an update.
88
- if (consentPayloadAsString && forwarderSettings.consentMappingWeb) {
89
- var eventConsentState = getEventConsentState(event.ConsentState);
90
-
91
- if (!isEmpty(eventConsentState)) {
92
- var updatedConsentPayload = generateConsentStatePayloadFromMappings(
93
- eventConsentState,
94
- consentMappings,
95
- );
96
-
97
- var eventConsentAsString =
98
- JSON.stringify(updatedConsentPayload);
99
-
100
- if (eventConsentAsString !== consentPayloadAsString) {
101
- sendGtagConsentUpdate(updatedConsentPayload);
102
- consentPayloadAsString = eventConsentAsString;
103
- }
104
- }
105
- }
106
-
107
- if (
108
- forwarderSettings.enableEnhancedConversions ===
109
- 'True' &&
110
- hasEnhancedConversionData(event.CustomFlags)
111
- ) {
112
- window.enhanced_conversion_data =
113
- parseEnhancedConversionData(
114
- event.CustomFlags[ENHANCED_CONVERSION_DATA]
115
- );
116
- }
117
-
118
- sendEventFunction = sendGtagEvent;
119
- generateEventFunction = generateGtagEvent;
120
- generateCommerceEvent = generateGtagCommerceEvent;
121
-
122
- } else if (window.google_trackConversion) {
123
- // window.google_trackConversion is a legacy API and will be deprecated
124
- sendEventFunction = sendAdwordsEvent;
125
- generateEventFunction = generateAdwordsEvent;
126
- generateCommerceEvent = generateAdwordsCommerceEvent;
127
-
128
- } else {
129
- eventQueue.push({
130
- action: processEvent,
131
- data: event
132
- });
133
-
134
- return 'Can\'t send to forwarder ' + name + ', not initialized. Event added to queue.';
103
+ sendEventFunction = sendGtagEvent;
104
+ generateEventFunction = generateGtagEvent;
105
+ generateCommerceEvent = generateGtagCommerceEvent;
106
+ } else if (window.google_trackConversion) {
107
+ // window.google_trackConversion is a legacy API and will be deprecated
108
+ sendEventFunction = sendAdwordsEvent;
109
+ generateEventFunction = generateAdwordsEvent;
110
+ generateCommerceEvent = generateAdwordsCommerceEvent;
111
+ } else {
112
+ eventQueue.push({
113
+ action: processEvent,
114
+ data: event,
115
+ });
116
+
117
+ return (
118
+ "Can't send to forwarder " +
119
+ name +
120
+ ', not initialized. Event added to queue.'
121
+ );
122
+ }
123
+
124
+ // Get conversionLabel to be used for event generation
125
+ var conversionLabel = getConversionLabel(event);
126
+ var customProps = getCustomProps(event);
127
+
128
+ if (conversionLabel) {
129
+ // Determines the proper event to fire
130
+ if (
131
+ event.EventDataType == MessageType.PageView ||
132
+ event.EventDataType == MessageType.PageEvent
133
+ ) {
134
+ eventPayload = generateEventFunction(
135
+ event,
136
+ conversionLabel,
137
+ customProps
138
+ );
139
+ } else if (
140
+ event.EventDataType == MessageType.Commerce &&
141
+ event.ProductAction
142
+ ) {
143
+ eventPayload = generateCommerceEvent(
144
+ event,
145
+ conversionLabel,
146
+ customProps
147
+ );
135
148
  }
136
149
 
137
- // Get conversionLabel to be used for event generation
138
- var conversionLabel = getConversionLabel(event);
139
- var customProps = getCustomProps(event);
140
-
141
- if (conversionLabel) {
142
- // Determines the proper event to fire
143
- if (event.EventDataType == MessageType.PageView || event.EventDataType == MessageType.PageEvent) {
144
- eventPayload = generateEventFunction(event, conversionLabel, customProps);
145
- } else if (event.EventDataType == MessageType.Commerce && event.ProductAction) {
146
- eventPayload = generateCommerceEvent(event, conversionLabel, customProps);
147
- }
148
-
149
- if (eventPayload) {
150
- reportEvent = sendEventFunction(eventPayload);
151
- }
152
-
153
- if (reportEvent && reportingService) {
154
- reportingService(self, event);
155
-
156
- return 'Successfully sent to ' + name;
157
- }
150
+ if (eventPayload) {
151
+ reportEvent = sendEventFunction(eventPayload);
158
152
  }
159
153
 
160
- return 'Can\'t send to forwarder: ' + name + '. Event not mapped';
161
- } catch (e) {
162
- console.error('Can\t send to forwarder', e);
163
- return 'Can\'t send to forwarder: ' + name + ' ' + e;
154
+ if (reportEvent && reportingService) {
155
+ reportingService(self, event);
156
+
157
+ return 'Successfully sent to ' + name;
158
+ }
164
159
  }
165
- } else {
166
- eventQueue.push({
167
- action: processEvent,
168
- data: event
169
- });
170
- }
171
160
 
172
- return 'Can\'t send to forwarder ' + name + ', not initialized. Event added to queue.';
161
+ return (
162
+ "Can't send to forwarder: " + name + '. Event not mapped'
163
+ );
164
+ } catch (e) {
165
+ console.error('Can\t send to forwarder', e);
166
+ return "Can't send to forwarder: " + name + ' ' + e;
167
+ }
168
+ } else {
169
+ eventQueue.push({
170
+ action: processEvent,
171
+ data: event,
172
+ });
173
173
  }
174
174
 
175
- function hasEnhancedConversionData(customFlags) {
176
- return customFlags && Object.keys(customFlags).length && customFlags[ENHANCED_CONVERSION_DATA];
177
- }
175
+ return (
176
+ "Can't send to forwarder " +
177
+ name +
178
+ ', not initialized. Event added to queue.'
179
+ );
180
+ }
178
181
 
179
- function parseEnhancedConversionData(conversionData) {
180
- // Checks if conversion data in custom flags is a stringified object
181
- // Conversion data should only be a stringified object or a JS object
182
- if (typeof conversionData === 'string') {
183
- try {
184
- return JSON.parse(conversionData);
185
- } catch (error) {
186
- console.warn('Unrecognized Enhanced Conversion Data Format', conversionData, error);
187
- return {};
188
- }
189
- } else if (typeof conversionData === 'object') {
190
- // Not a stringified object so it can be used as-is. However,
191
- // we want to avoid mutating the original state, so we make a copy.
192
- return cloneObject(conversionData);
193
- } else {
194
- console.warn('Unrecognized Enhanced Conversion Data Format', conversionData);
182
+ function hasEnhancedConversionData(customFlags) {
183
+ return (
184
+ customFlags &&
185
+ Object.keys(customFlags).length &&
186
+ customFlags[ENHANCED_CONVERSION_DATA]
187
+ );
188
+ }
189
+
190
+ function parseEnhancedConversionData(conversionData) {
191
+ // Checks if conversion data in custom flags is a stringified object
192
+ // Conversion data should only be a stringified object or a JS object
193
+ if (typeof conversionData === 'string') {
194
+ try {
195
+ return JSON.parse(conversionData);
196
+ } catch (error) {
197
+ console.warn(
198
+ 'Unrecognized Enhanced Conversion Data Format',
199
+ conversionData,
200
+ error
201
+ );
195
202
  return {};
196
203
  }
197
-
204
+ } else if (typeof conversionData === 'object') {
205
+ // Not a stringified object so it can be used as-is. However,
206
+ // we want to avoid mutating the original state, so we make a copy.
207
+ return cloneObject(conversionData);
208
+ } else {
209
+ console.warn(
210
+ 'Unrecognized Enhanced Conversion Data Format',
211
+ conversionData
212
+ );
213
+ return {};
198
214
  }
215
+ }
199
216
 
200
- // Converts an mParticle Commerce Event into either Legacy or gtag Event
201
- function generateCommerceEvent(mPEvent, conversionLabel, isPageEvent) {
202
- if (mPEvent.ProductAction
203
- && mPEvent.ProductAction.ProductList
204
- && mPEvent.ProductAction.ProductActionType) {
205
-
206
- if (window.gtag && forwarderSettings.enableGtag == 'True') {
207
- return generateGtagCommerceEvent(mPEvent, conversionLabel, isPageEvent);
208
- } else if (window.google_trackConversion) {
209
- return generateAdwordsCommerceEvent(mPEvent, conversionLabel, isPageEvent);
210
- } else {
211
- console.error('Unrecognized Commerce Event', mPEvent);
212
- return false;
213
- }
214
-
217
+ // Converts an mParticle Commerce Event into either Legacy or gtag Event
218
+ function generateCommerceEvent(mPEvent, conversionLabel, isPageEvent) {
219
+ if (
220
+ mPEvent.ProductAction &&
221
+ mPEvent.ProductAction.ProductList &&
222
+ mPEvent.ProductAction.ProductActionType
223
+ ) {
224
+ if (window.gtag && forwarderSettings.enableGtag == 'True') {
225
+ return generateGtagCommerceEvent(
226
+ mPEvent,
227
+ conversionLabel,
228
+ isPageEvent
229
+ );
230
+ } else if (window.google_trackConversion) {
231
+ return generateAdwordsCommerceEvent(
232
+ mPEvent,
233
+ conversionLabel,
234
+ isPageEvent
235
+ );
215
236
  } else {
237
+ console.error('Unrecognized Commerce Event', mPEvent);
216
238
  return false;
217
239
  }
240
+ } else {
241
+ return false;
218
242
  }
243
+ }
219
244
 
220
- function getUserConsentState() {
221
- var userConsentState = {};
245
+ function getUserConsentState() {
246
+ var userConsentState = {};
222
247
 
223
- if (window.mParticle && window.mParticle.Identity && window.mParticle.Identity.getCurrentUser) {
224
- var currentUser = window.mParticle.Identity.getCurrentUser();
248
+ if (
249
+ window.mParticle &&
250
+ window.mParticle.Identity &&
251
+ window.mParticle.Identity.getCurrentUser
252
+ ) {
253
+ var currentUser = window.mParticle.Identity.getCurrentUser();
225
254
 
226
- if (!currentUser) {
227
- return {};
228
- }
255
+ if (!currentUser) {
256
+ return {};
257
+ }
229
258
 
230
- var consentState =
231
- window.mParticle.Identity.getCurrentUser().getConsentState();
259
+ var consentState = window.mParticle.Identity.getCurrentUser().getConsentState();
232
260
 
233
- if (consentState && consentState.getGDPRConsentState) {
234
- userConsentState = consentState.getGDPRConsentState();
235
- }
261
+ if (consentState && consentState.getGDPRConsentState) {
262
+ userConsentState = consentState.getGDPRConsentState();
236
263
  }
237
-
238
- return userConsentState;
239
264
  }
240
265
 
241
- function getEventConsentState(eventConsentState) {
242
- return eventConsentState && eventConsentState.getGDPRConsentState
243
- ? eventConsentState.getGDPRConsentState()
244
- : {};
245
- }
246
- // ** Adwords Events
247
- function getBaseAdWordEvent() {
248
- var adWordEvent = {};
249
- adWordEvent.google_conversion_value = 0;
250
- adWordEvent.google_conversion_language = 'en';
251
- adWordEvent.google_conversion_format = '3';
252
- adWordEvent.google_conversion_color = 'ffffff';
253
- adWordEvent.google_remarketing_only = forwarderSettings.remarketingOnly == 'True';
254
- adWordEvent.google_conversion_id = forwarderSettings.conversionId;
255
- return adWordEvent;
256
- }
266
+ return userConsentState;
267
+ }
257
268
 
258
- function generateAdwordsEvent(mPEvent, conversionLabel, customProps) {
259
- var adWordEvent = getBaseAdWordEvent();
260
- adWordEvent.google_conversion_label = conversionLabel;
261
- adWordEvent.google_custom_params = customProps;
269
+ function getEventConsentState(eventConsentState) {
270
+ return eventConsentState && eventConsentState.getGDPRConsentState
271
+ ? eventConsentState.getGDPRConsentState()
272
+ : {};
273
+ }
262
274
 
263
- return adWordEvent;
264
- }
275
+ // ** Adwords Events
276
+ function getBaseAdWordEvent() {
277
+ var adWordEvent = {};
278
+ adWordEvent.google_conversion_value = 0;
279
+ adWordEvent.google_conversion_language = 'en';
280
+ adWordEvent.google_conversion_format = '3';
281
+ adWordEvent.google_conversion_color = 'ffffff';
282
+ adWordEvent.google_remarketing_only =
283
+ forwarderSettings.remarketingOnly == 'True';
284
+ adWordEvent.google_conversion_id = forwarderSettings.conversionId;
285
+ return adWordEvent;
286
+ }
265
287
 
266
- function generateAdwordsCommerceEvent(mPEvent, conversionLabel, customProps) {
267
- var adWordEvent = getBaseAdWordEvent();
268
- adWordEvent.google_conversion_label = conversionLabel;
288
+ function generateAdwordsEvent(mPEvent, conversionLabel, customProps) {
289
+ var adWordEvent = getBaseAdWordEvent();
290
+ adWordEvent.google_conversion_label = conversionLabel;
291
+ adWordEvent.google_custom_params = customProps;
269
292
 
270
- if (mPEvent.ProductAction.ProductActionType === mParticle.ProductActionType.Purchase
271
- && mPEvent.ProductAction.TransactionId) {
272
- adWordEvent.google_conversion_order_id = mPEvent.ProductAction.TransactionId;
273
- }
293
+ return adWordEvent;
294
+ }
274
295
 
275
- if (mPEvent.CurrencyCode) {
276
- adWordEvent.google_conversion_currency = mPEvent.CurrencyCode;
277
- }
296
+ function generateAdwordsCommerceEvent(
297
+ mPEvent,
298
+ conversionLabel,
299
+ customProps
300
+ ) {
301
+ var adWordEvent = getBaseAdWordEvent();
302
+ adWordEvent.google_conversion_label = conversionLabel;
303
+
304
+ if (
305
+ mPEvent.ProductAction.ProductActionType ===
306
+ mParticle.ProductActionType.Purchase &&
307
+ mPEvent.ProductAction.TransactionId
308
+ ) {
309
+ adWordEvent.google_conversion_order_id =
310
+ mPEvent.ProductAction.TransactionId;
311
+ }
278
312
 
279
- if (mPEvent.ProductAction.TotalAmount) {
280
- adWordEvent.google_conversion_value = mPEvent.ProductAction.TotalAmount;
281
- }
313
+ if (mPEvent.CurrencyCode) {
314
+ adWordEvent.google_conversion_currency = mPEvent.CurrencyCode;
315
+ }
282
316
 
283
- adWordEvent.google_custom_params = customProps;
284
- return adWordEvent;
317
+ if (mPEvent.ProductAction.TotalAmount) {
318
+ adWordEvent.google_conversion_value =
319
+ mPEvent.ProductAction.TotalAmount;
285
320
  }
286
321
 
287
- function getConsentSettings() {
288
- var consentSettings = {};
322
+ adWordEvent.google_custom_params = customProps;
323
+ return adWordEvent;
324
+ }
289
325
 
290
- var googleToMpConsentSettingsMapping = {
291
- // Inherited from S2S Integration Settings
292
- ad_user_data: 'defaultAdUserDataConsent',
293
- ad_personalization: 'defaultAdPersonalizationConsent',
326
+ function getConsentSettings() {
327
+ var consentSettings = {};
328
+
329
+ var googleToMpConsentSettingsMapping = {
330
+ // Inherited from S2S Integration Settings
331
+ ad_user_data: 'defaultAdUserDataConsent',
332
+ ad_personalization: 'defaultAdPersonalizationConsent',
333
+
334
+ // Unique to Web Kits
335
+ ad_storage: 'defaultAdStorageConsentWeb',
336
+ analytics_storage: 'defaultAnalyticsStorageConsentWeb',
337
+ };
338
+
339
+ Object.keys(googleToMpConsentSettingsMapping).forEach(function(
340
+ googleConsentKey
341
+ ) {
342
+ var mpConsentSettingKey =
343
+ googleToMpConsentSettingsMapping[googleConsentKey];
344
+ var googleConsentValuesKey = forwarderSettings[mpConsentSettingKey];
345
+
346
+ if (googleConsentValuesKey && mpConsentSettingKey) {
347
+ consentSettings[googleConsentKey] =
348
+ googleConsentValues[googleConsentValuesKey];
349
+ }
350
+ });
294
351
 
295
- // Unique to Web Kits
296
- ad_storage: 'defaultAdStorageConsentWeb',
297
- analytics_storage: 'defaultAnalyticsStorageConsentWeb'
298
- };
352
+ return consentSettings;
353
+ }
299
354
 
300
- Object.keys(googleToMpConsentSettingsMapping).forEach(function (googleConsentKey) {
301
- var mpConsentSettingKey = googleToMpConsentSettingsMapping[googleConsentKey];
302
- var googleConsentValuesKey = forwarderSettings[mpConsentSettingKey];
355
+ // gtag Events
356
+ function getBaseGtagEvent(conversionLabel) {
357
+ return {
358
+ send_to: gtagSiteId + '/' + conversionLabel,
359
+ value: 0,
360
+ language: 'en',
361
+ remarketing_only: forwarderSettings.remarketingOnly == 'True',
362
+ };
363
+ }
303
364
 
304
- if (googleConsentValuesKey && mpConsentSettingKey){
305
- consentSettings[googleConsentKey] = googleConsentValues[googleConsentValuesKey];
306
- }
307
- });
308
-
309
- return consentSettings;
365
+ function generateGtagEvent(mPEvent, conversionLabel, customProps) {
366
+ if (!conversionLabel) {
367
+ return null;
310
368
  }
311
369
 
312
- // gtag Events
313
- function getBaseGtagEvent(conversionLabel) {
314
- return {
315
- 'send_to': gtagSiteId + '/' + conversionLabel,
316
- 'value': 0,
317
- 'language': 'en',
318
- 'remarketing_only': forwarderSettings.remarketingOnly == 'True'
319
- }
370
+ var conversionPayload = getBaseGtagEvent(conversionLabel);
371
+ conversionPayload.transaction_id = mPEvent.SourceMessageId;
372
+ return mergeObjects(conversionPayload, customProps);
373
+ }
374
+
375
+ function generateGtagCommerceEvent(mPEvent, conversionLabel, customProps) {
376
+ if (!conversionLabel) {
377
+ return null;
320
378
  }
321
379
 
322
- function generateGtagEvent(mPEvent, conversionLabel, customProps) {
323
- if (!conversionLabel) { return null; }
324
- var conversionPayload = getBaseGtagEvent(conversionLabel);
380
+ var conversionPayload = getBaseGtagEvent(conversionLabel);
381
+
382
+ if (
383
+ mPEvent.ProductAction.ProductActionType ===
384
+ mParticle.ProductActionType.Purchase &&
385
+ mPEvent.ProductAction.TransactionId
386
+ ) {
387
+ conversionPayload.transaction_id =
388
+ mPEvent.ProductAction.TransactionId;
389
+ } else {
325
390
  conversionPayload.transaction_id = mPEvent.SourceMessageId;
326
- return mergeObjects(conversionPayload, customProps);
327
391
  }
328
392
 
329
- function generateGtagCommerceEvent(mPEvent, conversionLabel, customProps) {
330
- if (!conversionLabel) { return null; }
331
- var conversionPayload = getBaseGtagEvent(conversionLabel);
332
-
333
- if (mPEvent.ProductAction.ProductActionType === mParticle.ProductActionType.Purchase
334
- && mPEvent.ProductAction.TransactionId) {
335
- conversionPayload.transaction_id = mPEvent.ProductAction.TransactionId;
336
- } else {
337
- conversionPayload.transaction_id = mPEvent.SourceMessageId;
338
- }
393
+ if (mPEvent.CurrencyCode) {
394
+ conversionPayload.currency = mPEvent.CurrencyCode;
395
+ }
339
396
 
340
- if (mPEvent.CurrencyCode) {
341
- conversionPayload.currency = mPEvent.CurrencyCode;
342
- }
397
+ if (mPEvent.ProductAction.TotalAmount) {
398
+ conversionPayload.value = mPEvent.ProductAction.TotalAmount;
399
+ }
343
400
 
344
- if (mPEvent.ProductAction.TotalAmount) {
345
- conversionPayload.value = mPEvent.ProductAction.TotalAmount;
346
- }
401
+ return mergeObjects(conversionPayload, customProps);
402
+ }
347
403
 
348
- return mergeObjects(conversionPayload, customProps);
404
+ function sendGtagEvent(payload) {
405
+ // https://go.mparticle.com/work/SQDSDKS-6165
406
+ try {
407
+ gtag('event', 'conversion', payload);
408
+ } catch (e) {
409
+ console.error(
410
+ 'gtag is not available to send payload: ',
411
+ payload,
412
+ e
413
+ );
414
+ return false;
349
415
  }
416
+ return true;
417
+ }
350
418
 
351
- function sendGtagEvent(payload) {
352
- // https://go.mparticle.com/work/SQDSDKS-6165
353
- try {
354
- gtag('event', 'conversion', payload);
355
- } catch (e) {
356
- console.error('gtag is not available to send payload: ', payload, e);
357
- return false;
419
+ function maybeSendConsentUpdateToGoogle(consentState) {
420
+ if (
421
+ consentPayloadAsString &&
422
+ forwarderSettings.consentMappingWeb &&
423
+ !isEmpty(consentState)
424
+ ) {
425
+ var updatedConsentPayload = generateConsentStatePayloadFromMappings(
426
+ consentState,
427
+ consentMappings
428
+ );
429
+
430
+ var eventConsentAsString = JSON.stringify(updatedConsentPayload);
431
+
432
+ if (eventConsentAsString !== consentPayloadAsString) {
433
+ sendGtagConsentUpdate(updatedConsentPayload);
434
+ consentPayloadAsString = eventConsentAsString;
358
435
  }
359
- return true;
360
436
  }
437
+ }
361
438
 
362
- function sendGtagConsentDefaults(payload) {
363
- // https://go.mparticle.com/work/SQDSDKS-6165
364
- try {
365
- gtag('consent', 'default', payload);
366
- } catch (e) {
367
- console.error('gtag is not available to send consent defaults: ', payload, e);
368
- return false;
369
- }
370
- return true;
439
+ function sendGtagConsentDefaults(payload) {
440
+ // https://go.mparticle.com/work/SQDSDKS-6165
441
+ consentPayloadAsString = JSON.stringify(payload);
442
+
443
+ try {
444
+ gtag('consent', 'default', payload);
445
+ } catch (e) {
446
+ console.error(
447
+ 'gtag is not available to send consent defaults: ',
448
+ payload,
449
+ e
450
+ );
451
+ return false;
371
452
  }
453
+ return true;
454
+ }
372
455
 
373
- function sendGtagConsentUpdate(payload) {
374
- // https://go.mparticle.com/work/SQDSDKS-6165
375
- try {
376
- gtag('consent', 'update', payload);
377
- } catch (e) {
378
- console.error('gtag is not available to send consent update: ', payload, e);
379
- return false;
380
- }
381
- return true;
456
+ function sendGtagConsentUpdate(payload) {
457
+ // https://go.mparticle.com/work/SQDSDKS-6165
458
+ try {
459
+ gtag('consent', 'update', payload);
460
+ } catch (e) {
461
+ console.error(
462
+ 'gtag is not available to send consent update: ',
463
+ payload,
464
+ e
465
+ );
466
+ return false;
382
467
  }
468
+ return true;
469
+ }
383
470
 
384
- function sendAdwordsEvent(payload) {
385
- try {
386
- window.google_trackConversion(payload);
387
- } catch (e) {
388
- console.error('google_trackConversion is not available to send payload: ', payload, e);
389
- return false;
390
- }
391
- return true;
471
+ function sendAdwordsEvent(payload) {
472
+ try {
473
+ window.google_trackConversion(payload);
474
+ } catch (e) {
475
+ console.error(
476
+ 'google_trackConversion is not available to send payload: ',
477
+ payload,
478
+ e
479
+ );
480
+ return false;
392
481
  }
482
+ return true;
483
+ }
393
484
 
394
- // Creates a new Consent State Payload based on Consent State and Mapping
395
- function generateConsentStatePayloadFromMappings(consentState, mappings) {
396
- if (!mappings) return {};
397
- var payload = cloneObject(consentPayloadDefaults);
398
-
399
- for (var i = 0; i <= mappings.length - 1; i++) {
400
- var mappingEntry = mappings[i];
401
- // Although consent purposes can be inputted into the UI in any casing
402
- // the SDK will automatically lowercase them to prevent pseudo-duplicate
403
- // consent purposes, so we call `toLowerCase` on the consentMapping purposes here
404
- var mpMappedConsentName = mappingEntry.map.toLowerCase();
405
- // var mpMappedConsentName = mappingEntry.map;
406
- var googleMappedConsentName = mappingEntry.value;
407
-
408
- if (
409
- consentState[mpMappedConsentName] &&
410
- googleConsentProperties.indexOf(googleMappedConsentName) !== -1
411
- ) {
412
- payload[googleMappedConsentName] = consentState[mpMappedConsentName]
413
- .Consented
414
- ? googleConsentValues.Granted
415
- : googleConsentValues.Denied;
416
- }
485
+ // Creates a new Consent State Payload based on Consent State and Mapping
486
+ function generateConsentStatePayloadFromMappings(consentState, mappings) {
487
+ if (!mappings) return {};
488
+ var payload = cloneObject(consentPayloadDefaults);
489
+
490
+ for (var i = 0; i <= mappings.length - 1; i++) {
491
+ var mappingEntry = mappings[i];
492
+ // Although consent purposes can be inputted into the UI in any casing
493
+ // the SDK will automatically lowercase them to prevent pseudo-duplicate
494
+ // consent purposes, so we call `toLowerCase` on the consentMapping purposes here
495
+ var mpMappedConsentName = mappingEntry.map.toLowerCase();
496
+ // var mpMappedConsentName = mappingEntry.map;
497
+ var googleMappedConsentName = mappingEntry.value;
498
+
499
+ if (
500
+ consentState[mpMappedConsentName] &&
501
+ googleConsentProperties.indexOf(googleMappedConsentName) !== -1
502
+ ) {
503
+ payload[googleMappedConsentName] = consentState[
504
+ mpMappedConsentName
505
+ ].Consented
506
+ ? googleConsentValues.Granted
507
+ : googleConsentValues.Denied;
417
508
  }
418
-
419
- return payload;
420
509
  }
421
510
 
422
- // Looks up an Event's conversionLabel from customAttributeMappings based on computed jsHash value
423
- function getConversionLabel(event) {
424
- var jsHash = calculateJSHash(event.EventDataType, event.EventCategory, event.EventName);
425
- var type = event.EventDataType === MessageType.PageEvent ? 'EventClass.Id' : 'EventClassDetails.Id';
426
- var conversionLabel = null;
427
- var mappingEntry = findValueInMapping(jsHash, type, labels);
428
-
429
- if (mappingEntry) {
430
- conversionLabel = mappingEntry.value;
431
- }
511
+ return payload;
512
+ }
432
513
 
433
- return conversionLabel;
514
+ // Looks up an Event's conversionLabel from customAttributeMappings based on computed jsHash value
515
+ function getConversionLabel(event) {
516
+ var jsHash = calculateJSHash(
517
+ event.EventDataType,
518
+ event.EventCategory,
519
+ event.EventName
520
+ );
521
+ var type =
522
+ event.EventDataType === MessageType.PageEvent
523
+ ? 'EventClass.Id'
524
+ : 'EventClassDetails.Id';
525
+ var conversionLabel = null;
526
+ var mappingEntry = findValueInMapping(jsHash, type, labels);
527
+
528
+ if (mappingEntry) {
529
+ conversionLabel = mappingEntry.value;
434
530
  }
435
531
 
436
- // Filters Event.EventAttributes for attributes that are in customAttributeMappings
437
- function getCustomProps(event) {
438
- var customProps = {};
439
- var attributes = event.EventAttributes;
440
- var type = event.EventDataType === MessageType.PageEvent ? 'EventAttributeClass.Id' : 'EventAttributeClassDetails.Id';
441
-
442
- if (attributes) {
443
- for (var attributeKey in attributes) {
444
- if (attributes.hasOwnProperty(attributeKey)) {
445
- var jsHash = calculateJSHash(event.EventDataType, event.EventCategory, attributeKey);
446
- var mappingEntry = findValueInMapping(jsHash, type, customAttributeMappings);
447
- if (mappingEntry) {
448
- customProps[mappingEntry.value] = attributes[attributeKey];
449
- }
532
+ return conversionLabel;
533
+ }
534
+
535
+ // Filters Event.EventAttributes for attributes that are in customAttributeMappings
536
+ function getCustomProps(event) {
537
+ var customProps = {};
538
+ var attributes = event.EventAttributes;
539
+ var type =
540
+ event.EventDataType === MessageType.PageEvent
541
+ ? 'EventAttributeClass.Id'
542
+ : 'EventAttributeClassDetails.Id';
543
+
544
+ if (attributes) {
545
+ for (var attributeKey in attributes) {
546
+ if (attributes.hasOwnProperty(attributeKey)) {
547
+ var jsHash = calculateJSHash(
548
+ event.EventDataType,
549
+ event.EventCategory,
550
+ attributeKey
551
+ );
552
+ var mappingEntry = findValueInMapping(
553
+ jsHash,
554
+ type,
555
+ customAttributeMappings
556
+ );
557
+ if (mappingEntry) {
558
+ customProps[mappingEntry.value] =
559
+ attributes[attributeKey];
450
560
  }
451
561
  }
452
562
  }
453
-
454
- return customProps;
455
563
  }
456
564
 
457
- function findValueInMapping(jsHash, type, mapping) {
458
- if (mapping) {
459
- var filteredArray = mapping.filter(function (mappingEntry) {
565
+ return customProps;
566
+ }
460
567
 
461
- if (mappingEntry.jsmap && mappingEntry.maptype && mappingEntry.value) {
462
- return mappingEntry.jsmap == jsHash && mappingEntry.maptype == type;
463
- }
568
+ function findValueInMapping(jsHash, type, mapping) {
569
+ if (mapping) {
570
+ var filteredArray = mapping.filter(function(mappingEntry) {
571
+ if (
572
+ mappingEntry.jsmap &&
573
+ mappingEntry.maptype &&
574
+ mappingEntry.value
575
+ ) {
576
+ return (
577
+ mappingEntry.jsmap == jsHash &&
578
+ mappingEntry.maptype == type
579
+ );
580
+ }
464
581
 
465
- return false;
466
- });
582
+ return false;
583
+ });
467
584
 
468
- if (filteredArray && filteredArray.length > 0) {
469
- return filteredArray[0];
470
- }
585
+ if (filteredArray && filteredArray.length > 0) {
586
+ return filteredArray[0];
471
587
  }
472
- return null;
473
588
  }
589
+ return null;
590
+ }
474
591
 
475
- function calculateJSHash(eventDataType, eventCategory, name) {
476
- var preHash = [eventDataType, eventCategory, name].join('');
592
+ function calculateJSHash(eventDataType, eventCategory, name) {
593
+ var preHash = [eventDataType, eventCategory, name].join('');
477
594
 
478
- return mParticle.generateHash(preHash);
479
- }
595
+ return mParticle.generateHash(preHash);
596
+ }
480
597
 
481
- function loadGtagSnippet() {
482
- (function () {
483
- window.dataLayer = window.dataLayer || [];
484
- window.gtag = function(){dataLayer.push(arguments);};
485
-
486
- var gTagScript = document.createElement('script');
487
- gTagScript.async = true;
488
- gTagScript.onload = function () {
489
- gtag('js', new Date());
490
- if (forwarderSettings.enableEnhancedConversions === 'True') {
491
- gtag('config', gtagSiteId, {
492
- allow_enhanced_conversions: true
493
- });
494
- } else {
495
- gtag('config', gtagSiteId);
496
- }
497
- isInitialized = true;
498
- processQueue(eventQueue);
499
- };
500
- gTagScript.src = 'https://www.googletagmanager.com/gtag/js?id=' + gtagSiteId;
501
- document.getElementsByTagName('head')[0].appendChild(gTagScript);
502
- })();
503
- }
598
+ function loadGtagSnippet() {
599
+ (function() {
600
+ window.dataLayer = window.dataLayer || [];
601
+ window.gtag = function() {
602
+ dataLayer.push(arguments);
603
+ };
504
604
 
505
- function loadLegacySnippet() {
506
- (function () {
507
- var googleAdwords = document.createElement('script');
508
- googleAdwords.type = 'text/javascript';
509
- googleAdwords.async = true;
510
- googleAdwords.onload = function() {
511
- isInitialized = true;
512
- processQueue(eventQueue);
513
- };
514
- googleAdwords.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://www.googleadservices.com/pagead/conversion_async.js';
515
- document.getElementsByTagName('head')[0].appendChild(googleAdwords);
516
- })();
517
- }
605
+ var gTagScript = document.createElement('script');
606
+ gTagScript.async = true;
607
+ gTagScript.onload = function() {
608
+ gtag('js', new Date());
609
+ if (forwarderSettings.enableEnhancedConversions === 'True') {
610
+ gtag('config', gtagSiteId, {
611
+ allow_enhanced_conversions: true,
612
+ });
613
+ } else {
614
+ gtag('config', gtagSiteId);
615
+ }
616
+ isInitialized = true;
617
+ processQueue(eventQueue);
618
+ };
619
+ gTagScript.src =
620
+ 'https://www.googletagmanager.com/gtag/js?id=' + gtagSiteId;
621
+ document.getElementsByTagName('head')[0].appendChild(gTagScript);
622
+ })();
623
+ }
518
624
 
519
- // https://go.mparticle.com/work/SQDSDKS-6166
520
- function initForwarder(settings, service, testMode) {
521
- window.enhanced_conversion_data = {};
522
- forwarderSettings = settings;
523
- reportingService = service;
625
+ function loadLegacySnippet() {
626
+ (function() {
627
+ var googleAdwords = document.createElement('script');
628
+ googleAdwords.type = 'text/javascript';
629
+ googleAdwords.async = true;
630
+ googleAdwords.onload = function() {
631
+ isInitialized = true;
632
+ processQueue(eventQueue);
633
+ };
634
+ googleAdwords.src =
635
+ ('https:' == document.location.protocol ? 'https' : 'http') +
636
+ '://www.googleadservices.com/pagead/conversion_async.js';
637
+ document.getElementsByTagName('head')[0].appendChild(googleAdwords);
638
+ })();
639
+ }
524
640
 
525
- try {
526
- if (!forwarderSettings.conversionId) {
527
- return 'Can\'t initialize forwarder: ' + name + ', conversionId is not defined';
528
- }
641
+ // https://go.mparticle.com/work/SQDSDKS-6166
642
+ function initForwarder(settings, service, testMode) {
643
+ window.enhanced_conversion_data = {};
644
+ forwarderSettings = settings;
645
+ reportingService = service;
646
+
647
+ try {
648
+ if (!forwarderSettings.conversionId) {
649
+ return (
650
+ "Can't initialize forwarder: " +
651
+ name +
652
+ ', conversionId is not defined'
653
+ );
654
+ }
529
655
 
530
- gtagSiteId = "AW-" + forwarderSettings.conversionId;
656
+ gtagSiteId = 'AW-' + forwarderSettings.conversionId;
531
657
 
532
- if (testMode !== true) {
533
- if (forwarderSettings.enableGtag == 'True') {
534
- loadGtagSnippet();
535
- } else {
536
- loadLegacySnippet();
537
- }
658
+ if (testMode !== true) {
659
+ if (forwarderSettings.enableGtag == 'True') {
660
+ loadGtagSnippet();
538
661
  } else {
539
- isInitialized = true;
540
- processQueue(eventQueue);
662
+ loadLegacySnippet();
541
663
  }
664
+ } else {
665
+ isInitialized = true;
666
+ processQueue(eventQueue);
667
+ }
542
668
 
543
- if (!forwarderSettings.conversionId) {
544
- return 'Can\'t initialize forwarder: ' + name + ', conversionId is not defined';
545
- }
669
+ if (!forwarderSettings.conversionId) {
670
+ return (
671
+ "Can't initialize forwarder: " +
672
+ name +
673
+ ', conversionId is not defined'
674
+ );
675
+ }
546
676
 
547
- // https://go.mparticle.com/work/SQDSDKS-6165
548
- if (window.gtag && forwarderSettings.enableGtag === 'True') {
549
- if (forwarderSettings.consentMappingWeb) {
550
- consentMappings = parseSettingsString(
551
- forwarderSettings.consentMappingWeb
552
- );
553
- } else {
554
- // Ensures consent mappings is an empty array
555
- // for future use
556
- consentMappings = [];
557
- }
558
-
559
- consentPayloadDefaults = getConsentSettings();
560
- var initialConsentState = getUserConsentState();
561
-
562
- var defaultConsentPayload =
563
- generateConsentStatePayloadFromMappings(
564
- initialConsentState,
565
- consentMappings
566
- );
567
-
568
- if(!isEmpty(defaultConsentPayload)) {
569
- consentPayloadAsString = JSON.stringify(
570
- defaultConsentPayload
571
- );
677
+ // https://go.mparticle.com/work/SQDSDKS-6165
678
+ if (window.gtag && forwarderSettings.enableGtag === 'True') {
679
+ if (forwarderSettings.consentMappingWeb) {
680
+ consentMappings = parseSettingsString(
681
+ forwarderSettings.consentMappingWeb
682
+ );
683
+ } else {
684
+ // Ensures consent mappings is an empty array
685
+ // for future use
686
+ consentMappings = [];
687
+ }
572
688
 
573
- sendGtagConsentDefaults(defaultConsentPayload);
574
- }
689
+ consentPayloadDefaults = getConsentSettings();
690
+ var defaultConsentPayload = cloneObject(consentPayloadDefaults);
691
+ var updatedConsentState = getUserConsentState();
692
+ var updatedDefaultConsentPayload = generateConsentStatePayloadFromMappings(
693
+ updatedConsentState,
694
+ consentMappings
695
+ );
696
+
697
+ if (!isEmpty(defaultConsentPayload)) {
698
+ sendGtagConsentDefaults(defaultConsentPayload);
699
+ } else if (!isEmpty(updatedDefaultConsentPayload)) {
700
+ sendGtagConsentDefaults(updatedDefaultConsentPayload);
575
701
  }
576
702
 
577
- forwarderSettings.remarketingOnly = forwarderSettings.remarketingOnly == 'True';
703
+ maybeSendConsentUpdateToGoogle(updatedConsentState);
704
+ }
578
705
 
579
- try {
580
- if (forwarderSettings.labels) {
581
- labels = JSON.parse(forwarderSettings.labels.replace(/&quot;/g, '"'));
582
- }
706
+ forwarderSettings.remarketingOnly =
707
+ forwarderSettings.remarketingOnly == 'True';
583
708
 
584
- if (forwarderSettings.customParameters) {
585
- customAttributeMappings = JSON.parse(forwarderSettings.customParameters.replace(/&quot;/g, '"'));
586
- }
587
- } catch (e) {
588
- return 'Can\'t initialize forwarder: ' + name + ', Could not process event to label mapping';
709
+ try {
710
+ if (forwarderSettings.labels) {
711
+ labels = JSON.parse(
712
+ forwarderSettings.labels.replace(/&quot;/g, '"')
713
+ );
589
714
  }
590
715
 
591
- return 'Successfully initialized: ' + name;
592
- }
593
- catch (e) {
594
- return 'Failed to initialize: ' + name;
595
- }
596
- }
597
-
598
- function processQueue(queue) {
599
- var item;
600
-
601
- if ((window.gtag || window.google_trackConversion) && queue.length > 0) {
602
- try {
603
- while (queue.length > 0) {
604
- item = queue.shift();
605
- item.action(item.data);
606
- }
607
- } catch (e) {
608
- console.error('Error on mParticle Adwords Kit', e);
716
+ if (forwarderSettings.customParameters) {
717
+ customAttributeMappings = JSON.parse(
718
+ forwarderSettings.customParameters.replace(
719
+ /&quot;/g,
720
+ '"'
721
+ )
722
+ );
609
723
  }
724
+ } catch (e) {
725
+ return (
726
+ "Can't initialize forwarder: " +
727
+ name +
728
+ ', Could not process event to label mapping'
729
+ );
610
730
  }
611
- }
612
-
613
- this.init = initForwarder;
614
- this.process = processEvent;
615
- this.processQueue = processQueue;
616
- };
617
731
 
618
- function getId() {
619
- return moduleId;
620
- }
621
-
622
- function register(config) {
623
- if (!config) {
624
- console.log('You must pass a config object to register the kit ' + name);
625
- return;
732
+ return 'Successfully initialized: ' + name;
733
+ } catch (e) {
734
+ return 'Failed to initialize: ' + name;
626
735
  }
736
+ }
627
737
 
628
- if (!isObject(config)) {
629
- console.log('\'config\' must be an object. You passed in a ' + typeof config);
630
- return;
631
- }
738
+ function processQueue(queue) {
739
+ var item;
632
740
 
633
- if (isObject(config.kits)) {
634
- config.kits[name] = {
635
- constructor: constructor
636
- };
637
- } else {
638
- config.kits = {};
639
- config.kits[name] = {
640
- constructor: constructor
641
- };
741
+ if (
742
+ (window.gtag || window.google_trackConversion) &&
743
+ queue.length > 0
744
+ ) {
745
+ try {
746
+ while (queue.length > 0) {
747
+ item = queue.shift();
748
+ item.action(item.data);
749
+ }
750
+ } catch (e) {
751
+ console.error('Error on mParticle Adwords Kit', e);
752
+ }
642
753
  }
643
- console.log('Successfully registered ' + name + ' to your mParticle configuration');
644
754
  }
645
755
 
646
- function parseSettingsString(settingsString) {
647
- return JSON.parse(settingsString.replace(/&quot;/g, '"'));
756
+ this.init = initForwarder;
757
+ this.process = processEvent;
758
+ this.processQueue = processQueue;
759
+ };
760
+
761
+ function getId() {
762
+ return moduleId;
763
+ }
764
+
765
+ function register(config) {
766
+ if (!config) {
767
+ console.log(
768
+ 'You must pass a config object to register the kit ' + name
769
+ );
770
+ return;
648
771
  }
649
772
 
650
- function isObject(val) {
651
- return val != null && typeof val === 'object' && Array.isArray(val) === false;
773
+ if (!isObject(config)) {
774
+ console.log(
775
+ "'config' must be an object. You passed in a " + typeof config
776
+ );
777
+ return;
652
778
  }
653
779
 
654
- function isEmpty(value) {
655
- return value == null || !(Object.keys(value) || value).length;
780
+ if (isObject(config.kits)) {
781
+ config.kits[name] = {
782
+ constructor: constructor,
783
+ };
784
+ } else {
785
+ config.kits = {};
786
+ config.kits[name] = {
787
+ constructor: constructor,
788
+ };
656
789
  }
657
-
658
- function mergeObjects() {
659
- var resObj = {};
660
- for(var i=0; i < arguments.length; i += 1) {
661
- var obj = arguments[i],
662
- keys = Object.keys(obj);
663
- for(var j=0; j < keys.length; j += 1) {
664
- resObj[keys[j]] = obj[keys[j]];
665
- }
790
+ console.log(
791
+ 'Successfully registered ' + name + ' to your mParticle configuration'
792
+ );
793
+ }
794
+
795
+ function parseSettingsString(settingsString) {
796
+ return JSON.parse(settingsString.replace(/&quot;/g, '"'));
797
+ }
798
+
799
+ function isObject(val) {
800
+ return (
801
+ val != null && typeof val === 'object' && Array.isArray(val) === false
802
+ );
803
+ }
804
+
805
+ function isEmpty(value) {
806
+ return value == null || !(Object.keys(value) || value).length;
807
+ }
808
+
809
+ function mergeObjects() {
810
+ var resObj = {};
811
+ for (var i = 0; i < arguments.length; i += 1) {
812
+ var obj = arguments[i],
813
+ keys = Object.keys(obj);
814
+ for (var j = 0; j < keys.length; j += 1) {
815
+ resObj[keys[j]] = obj[keys[j]];
666
816
  }
667
- return resObj;
668
817
  }
669
-
670
- function cloneObject(obj) {
671
- return JSON.parse(JSON.stringify(obj));
672
- }
673
-
674
- if (typeof window !== 'undefined') {
675
- if (window && window.mParticle && window.mParticle.addForwarder) {
676
- window.mParticle.addForwarder({
677
- name: name,
678
- constructor: constructor,
679
- getId: getId
680
- });
681
- }
818
+ return resObj;
819
+ }
820
+
821
+ function cloneObject(obj) {
822
+ return JSON.parse(JSON.stringify(obj));
823
+ }
824
+
825
+ if (typeof window !== 'undefined') {
826
+ if (window && window.mParticle && window.mParticle.addForwarder) {
827
+ window.mParticle.addForwarder({
828
+ name: name,
829
+ constructor: constructor,
830
+ getId: getId,
831
+ });
682
832
  }
833
+ }
683
834
 
684
- var GoogleAdWordsEventForwarder = {
685
- register: register
686
- };
835
+ var GoogleAdWordsEventForwarder = {
836
+ register: register,
837
+ };
687
838
 
688
839
  exports.default = GoogleAdWordsEventForwarder;