@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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
138
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
return (
|
|
176
|
+
"Can't send to forwarder " +
|
|
177
|
+
name +
|
|
178
|
+
', not initialized. Event added to queue.'
|
|
179
|
+
);
|
|
180
|
+
}
|
|
178
181
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
return
|
|
193
|
-
}
|
|
194
|
-
console.warn(
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
221
|
-
|
|
245
|
+
function getUserConsentState() {
|
|
246
|
+
var userConsentState = {};
|
|
222
247
|
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
|
|
227
|
-
|
|
228
|
-
|
|
255
|
+
if (!currentUser) {
|
|
256
|
+
return {};
|
|
257
|
+
}
|
|
229
258
|
|
|
230
|
-
|
|
231
|
-
window.mParticle.Identity.getCurrentUser().getConsentState();
|
|
259
|
+
var consentState = window.mParticle.Identity.getCurrentUser().getConsentState();
|
|
232
260
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
261
|
+
if (consentState && consentState.getGDPRConsentState) {
|
|
262
|
+
userConsentState = consentState.getGDPRConsentState();
|
|
236
263
|
}
|
|
237
|
-
|
|
238
|
-
return userConsentState;
|
|
239
264
|
}
|
|
240
265
|
|
|
241
|
-
|
|
242
|
-
|
|
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
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
269
|
+
function getEventConsentState(eventConsentState) {
|
|
270
|
+
return eventConsentState && eventConsentState.getGDPRConsentState
|
|
271
|
+
? eventConsentState.getGDPRConsentState()
|
|
272
|
+
: {};
|
|
273
|
+
}
|
|
262
274
|
|
|
263
|
-
|
|
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
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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
|
-
|
|
271
|
-
|
|
272
|
-
adWordEvent.google_conversion_order_id = mPEvent.ProductAction.TransactionId;
|
|
273
|
-
}
|
|
293
|
+
return adWordEvent;
|
|
294
|
+
}
|
|
274
295
|
|
|
275
|
-
|
|
276
|
-
|
|
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
|
-
|
|
280
|
-
|
|
281
|
-
|
|
313
|
+
if (mPEvent.CurrencyCode) {
|
|
314
|
+
adWordEvent.google_conversion_currency = mPEvent.CurrencyCode;
|
|
315
|
+
}
|
|
282
316
|
|
|
283
|
-
|
|
284
|
-
|
|
317
|
+
if (mPEvent.ProductAction.TotalAmount) {
|
|
318
|
+
adWordEvent.google_conversion_value =
|
|
319
|
+
mPEvent.ProductAction.TotalAmount;
|
|
285
320
|
}
|
|
286
321
|
|
|
287
|
-
|
|
288
|
-
|
|
322
|
+
adWordEvent.google_custom_params = customProps;
|
|
323
|
+
return adWordEvent;
|
|
324
|
+
}
|
|
289
325
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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
|
-
|
|
296
|
-
|
|
297
|
-
analytics_storage: 'defaultAnalyticsStorageConsentWeb'
|
|
298
|
-
};
|
|
352
|
+
return consentSettings;
|
|
353
|
+
}
|
|
299
354
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
return consentSettings;
|
|
365
|
+
function generateGtagEvent(mPEvent, conversionLabel, customProps) {
|
|
366
|
+
if (!conversionLabel) {
|
|
367
|
+
return null;
|
|
310
368
|
}
|
|
311
369
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
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
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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
|
-
|
|
341
|
-
|
|
342
|
-
|
|
397
|
+
if (mPEvent.ProductAction.TotalAmount) {
|
|
398
|
+
conversionPayload.value = mPEvent.ProductAction.TotalAmount;
|
|
399
|
+
}
|
|
343
400
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
401
|
+
return mergeObjects(conversionPayload, customProps);
|
|
402
|
+
}
|
|
347
403
|
|
|
348
|
-
|
|
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
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
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
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
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
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
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
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
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
|
-
|
|
423
|
-
|
|
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
|
-
|
|
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
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
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
|
-
|
|
458
|
-
|
|
459
|
-
var filteredArray = mapping.filter(function (mappingEntry) {
|
|
565
|
+
return customProps;
|
|
566
|
+
}
|
|
460
567
|
|
|
461
|
-
|
|
462
|
-
|
|
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
|
-
|
|
466
|
-
|
|
582
|
+
return false;
|
|
583
|
+
});
|
|
467
584
|
|
|
468
|
-
|
|
469
|
-
|
|
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
|
-
|
|
476
|
-
|
|
592
|
+
function calculateJSHash(eventDataType, eventCategory, name) {
|
|
593
|
+
var preHash = [eventDataType, eventCategory, name].join('');
|
|
477
594
|
|
|
478
|
-
|
|
479
|
-
|
|
595
|
+
return mParticle.generateHash(preHash);
|
|
596
|
+
}
|
|
480
597
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
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
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
|
|
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
|
-
|
|
520
|
-
function
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
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
|
-
|
|
526
|
-
|
|
527
|
-
|
|
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
|
-
|
|
656
|
+
gtagSiteId = 'AW-' + forwarderSettings.conversionId;
|
|
531
657
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
} else {
|
|
536
|
-
loadLegacySnippet();
|
|
537
|
-
}
|
|
658
|
+
if (testMode !== true) {
|
|
659
|
+
if (forwarderSettings.enableGtag == 'True') {
|
|
660
|
+
loadGtagSnippet();
|
|
538
661
|
} else {
|
|
539
|
-
|
|
540
|
-
processQueue(eventQueue);
|
|
662
|
+
loadLegacySnippet();
|
|
541
663
|
}
|
|
664
|
+
} else {
|
|
665
|
+
isInitialized = true;
|
|
666
|
+
processQueue(eventQueue);
|
|
667
|
+
}
|
|
542
668
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
669
|
+
if (!forwarderSettings.conversionId) {
|
|
670
|
+
return (
|
|
671
|
+
"Can't initialize forwarder: " +
|
|
672
|
+
name +
|
|
673
|
+
', conversionId is not defined'
|
|
674
|
+
);
|
|
675
|
+
}
|
|
546
676
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
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
|
-
|
|
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
|
-
|
|
703
|
+
maybeSendConsentUpdateToGoogle(updatedConsentState);
|
|
704
|
+
}
|
|
578
705
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
labels = JSON.parse(forwarderSettings.labels.replace(/"/g, '"'));
|
|
582
|
-
}
|
|
706
|
+
forwarderSettings.remarketingOnly =
|
|
707
|
+
forwarderSettings.remarketingOnly == 'True';
|
|
583
708
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
709
|
+
try {
|
|
710
|
+
if (forwarderSettings.labels) {
|
|
711
|
+
labels = JSON.parse(
|
|
712
|
+
forwarderSettings.labels.replace(/"/g, '"')
|
|
713
|
+
);
|
|
589
714
|
}
|
|
590
715
|
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
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
|
+
/"/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
|
-
|
|
619
|
-
|
|
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
|
-
|
|
629
|
-
|
|
630
|
-
return;
|
|
631
|
-
}
|
|
738
|
+
function processQueue(queue) {
|
|
739
|
+
var item;
|
|
632
740
|
|
|
633
|
-
if (
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
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
|
-
|
|
647
|
-
|
|
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
|
-
|
|
651
|
-
|
|
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
|
-
|
|
655
|
-
|
|
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
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
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(/"/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
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
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
|
-
|
|
685
|
-
|
|
686
|
-
|
|
835
|
+
var GoogleAdWordsEventForwarder = {
|
|
836
|
+
register: register,
|
|
837
|
+
};
|
|
687
838
|
|
|
688
839
|
exports.default = GoogleAdWordsEventForwarder;
|