@mparticle/web-adwords-kit 2.3.2 → 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.
|
@@ -17,682 +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
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
sendEventFunction = sendGtagEvent;
|
|
103
|
-
generateEventFunction = generateGtagEvent;
|
|
104
|
-
generateCommerceEvent = generateGtagCommerceEvent;
|
|
105
|
-
|
|
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
|
-
|
|
112
|
-
} else {
|
|
113
|
-
eventQueue.push({
|
|
114
|
-
action: processEvent,
|
|
115
|
-
data: event
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
return 'Can\'t send to forwarder ' + name + ', not initialized. Event added to queue.';
|
|
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
|
+
);
|
|
119
101
|
}
|
|
120
102
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
+
);
|
|
142
148
|
}
|
|
143
149
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
150
|
+
if (eventPayload) {
|
|
151
|
+
reportEvent = sendEventFunction(eventPayload);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (reportEvent && reportingService) {
|
|
155
|
+
reportingService(self, event);
|
|
156
|
+
|
|
157
|
+
return 'Successfully sent to ' + name;
|
|
158
|
+
}
|
|
148
159
|
}
|
|
149
|
-
} else {
|
|
150
|
-
eventQueue.push({
|
|
151
|
-
action: processEvent,
|
|
152
|
-
data: event
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
160
|
|
|
156
|
-
|
|
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
|
+
});
|
|
157
173
|
}
|
|
158
174
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
175
|
+
return (
|
|
176
|
+
"Can't send to forwarder " +
|
|
177
|
+
name +
|
|
178
|
+
', not initialized. Event added to queue.'
|
|
179
|
+
);
|
|
180
|
+
}
|
|
162
181
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return
|
|
177
|
-
}
|
|
178
|
-
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
|
+
);
|
|
179
202
|
return {};
|
|
180
203
|
}
|
|
181
|
-
|
|
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 {};
|
|
182
214
|
}
|
|
215
|
+
}
|
|
183
216
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
+
);
|
|
199
236
|
} else {
|
|
237
|
+
console.error('Unrecognized Commerce Event', mPEvent);
|
|
200
238
|
return false;
|
|
201
239
|
}
|
|
240
|
+
} else {
|
|
241
|
+
return false;
|
|
202
242
|
}
|
|
243
|
+
}
|
|
203
244
|
|
|
204
|
-
|
|
205
|
-
|
|
245
|
+
function getUserConsentState() {
|
|
246
|
+
var userConsentState = {};
|
|
206
247
|
|
|
207
|
-
|
|
208
|
-
|
|
248
|
+
if (
|
|
249
|
+
window.mParticle &&
|
|
250
|
+
window.mParticle.Identity &&
|
|
251
|
+
window.mParticle.Identity.getCurrentUser
|
|
252
|
+
) {
|
|
253
|
+
var currentUser = window.mParticle.Identity.getCurrentUser();
|
|
209
254
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
255
|
+
if (!currentUser) {
|
|
256
|
+
return {};
|
|
257
|
+
}
|
|
213
258
|
|
|
214
|
-
|
|
215
|
-
window.mParticle.Identity.getCurrentUser().getConsentState();
|
|
259
|
+
var consentState = window.mParticle.Identity.getCurrentUser().getConsentState();
|
|
216
260
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
261
|
+
if (consentState && consentState.getGDPRConsentState) {
|
|
262
|
+
userConsentState = consentState.getGDPRConsentState();
|
|
220
263
|
}
|
|
221
|
-
|
|
222
|
-
return userConsentState;
|
|
223
264
|
}
|
|
224
265
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
? eventConsentState.getGDPRConsentState()
|
|
228
|
-
: {};
|
|
229
|
-
}
|
|
230
|
-
// ** Adwords Events
|
|
231
|
-
function getBaseAdWordEvent() {
|
|
232
|
-
var adWordEvent = {};
|
|
233
|
-
adWordEvent.google_conversion_value = 0;
|
|
234
|
-
adWordEvent.google_conversion_language = 'en';
|
|
235
|
-
adWordEvent.google_conversion_format = '3';
|
|
236
|
-
adWordEvent.google_conversion_color = 'ffffff';
|
|
237
|
-
adWordEvent.google_remarketing_only = forwarderSettings.remarketingOnly == 'True';
|
|
238
|
-
adWordEvent.google_conversion_id = forwarderSettings.conversionId;
|
|
239
|
-
return adWordEvent;
|
|
240
|
-
}
|
|
266
|
+
return userConsentState;
|
|
267
|
+
}
|
|
241
268
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
269
|
+
function getEventConsentState(eventConsentState) {
|
|
270
|
+
return eventConsentState && eventConsentState.getGDPRConsentState
|
|
271
|
+
? eventConsentState.getGDPRConsentState()
|
|
272
|
+
: {};
|
|
273
|
+
}
|
|
246
274
|
|
|
247
|
-
|
|
248
|
-
|
|
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
|
+
}
|
|
249
287
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
288
|
+
function generateAdwordsEvent(mPEvent, conversionLabel, customProps) {
|
|
289
|
+
var adWordEvent = getBaseAdWordEvent();
|
|
290
|
+
adWordEvent.google_conversion_label = conversionLabel;
|
|
291
|
+
adWordEvent.google_custom_params = customProps;
|
|
253
292
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
adWordEvent.google_conversion_order_id = mPEvent.ProductAction.TransactionId;
|
|
257
|
-
}
|
|
293
|
+
return adWordEvent;
|
|
294
|
+
}
|
|
258
295
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
296
|
+
function generateAdwordsCommerceEvent(
|
|
297
|
+
mPEvent,
|
|
298
|
+
conversionLabel,
|
|
299
|
+
customProps
|
|
300
|
+
) {
|
|
301
|
+
var adWordEvent = getBaseAdWordEvent();
|
|
302
|
+
adWordEvent.google_conversion_label = conversionLabel;
|
|
262
303
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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
|
+
}
|
|
266
312
|
|
|
267
|
-
|
|
268
|
-
|
|
313
|
+
if (mPEvent.CurrencyCode) {
|
|
314
|
+
adWordEvent.google_conversion_currency = mPEvent.CurrencyCode;
|
|
269
315
|
}
|
|
270
316
|
|
|
271
|
-
|
|
272
|
-
|
|
317
|
+
if (mPEvent.ProductAction.TotalAmount) {
|
|
318
|
+
adWordEvent.google_conversion_value =
|
|
319
|
+
mPEvent.ProductAction.TotalAmount;
|
|
320
|
+
}
|
|
273
321
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
ad_personalization: 'defaultAdPersonalizationConsent',
|
|
322
|
+
adWordEvent.google_custom_params = customProps;
|
|
323
|
+
return adWordEvent;
|
|
324
|
+
}
|
|
278
325
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
+
});
|
|
283
351
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
var googleConsentValuesKey = forwarderSettings[mpConsentSettingKey];
|
|
352
|
+
return consentSettings;
|
|
353
|
+
}
|
|
287
354
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
+
}
|
|
295
364
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
return
|
|
299
|
-
'send_to': gtagSiteId + '/' + conversionLabel,
|
|
300
|
-
'value': 0,
|
|
301
|
-
'language': 'en',
|
|
302
|
-
'remarketing_only': forwarderSettings.remarketingOnly == 'True'
|
|
303
|
-
}
|
|
365
|
+
function generateGtagEvent(mPEvent, conversionLabel, customProps) {
|
|
366
|
+
if (!conversionLabel) {
|
|
367
|
+
return null;
|
|
304
368
|
}
|
|
305
369
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
return mergeObjects(conversionPayload, customProps);
|
|
311
|
-
}
|
|
370
|
+
var conversionPayload = getBaseGtagEvent(conversionLabel);
|
|
371
|
+
conversionPayload.transaction_id = mPEvent.SourceMessageId;
|
|
372
|
+
return mergeObjects(conversionPayload, customProps);
|
|
373
|
+
}
|
|
312
374
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
375
|
+
function generateGtagCommerceEvent(mPEvent, conversionLabel, customProps) {
|
|
376
|
+
if (!conversionLabel) {
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
316
379
|
|
|
317
|
-
|
|
318
|
-
&& mPEvent.ProductAction.TransactionId) {
|
|
319
|
-
conversionPayload.transaction_id = mPEvent.ProductAction.TransactionId;
|
|
320
|
-
} else {
|
|
321
|
-
conversionPayload.transaction_id = mPEvent.SourceMessageId;
|
|
322
|
-
}
|
|
380
|
+
var conversionPayload = getBaseGtagEvent(conversionLabel);
|
|
323
381
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
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 {
|
|
390
|
+
conversionPayload.transaction_id = mPEvent.SourceMessageId;
|
|
391
|
+
}
|
|
327
392
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
393
|
+
if (mPEvent.CurrencyCode) {
|
|
394
|
+
conversionPayload.currency = mPEvent.CurrencyCode;
|
|
395
|
+
}
|
|
331
396
|
|
|
332
|
-
|
|
397
|
+
if (mPEvent.ProductAction.TotalAmount) {
|
|
398
|
+
conversionPayload.value = mPEvent.ProductAction.TotalAmount;
|
|
333
399
|
}
|
|
334
400
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
401
|
+
return mergeObjects(conversionPayload, customProps);
|
|
402
|
+
}
|
|
403
|
+
|
|
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;
|
|
344
415
|
}
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
345
418
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
419
|
+
function maybeSendConsentUpdateToGoogle(consentState) {
|
|
420
|
+
if (
|
|
421
|
+
consentPayloadAsString &&
|
|
422
|
+
forwarderSettings.consentMappingWeb &&
|
|
423
|
+
!isEmpty(consentState)
|
|
424
|
+
) {
|
|
425
|
+
var updatedConsentPayload = generateConsentStatePayloadFromMappings(
|
|
426
|
+
consentState,
|
|
427
|
+
consentMappings
|
|
428
|
+
);
|
|
356
429
|
|
|
357
|
-
|
|
358
|
-
JSON.stringify(updatedConsentPayload);
|
|
430
|
+
var eventConsentAsString = JSON.stringify(updatedConsentPayload);
|
|
359
431
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
432
|
+
if (eventConsentAsString !== consentPayloadAsString) {
|
|
433
|
+
sendGtagConsentUpdate(updatedConsentPayload);
|
|
434
|
+
consentPayloadAsString = eventConsentAsString;
|
|
364
435
|
}
|
|
365
436
|
}
|
|
437
|
+
}
|
|
366
438
|
|
|
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
|
|
371
450
|
);
|
|
372
|
-
|
|
373
|
-
try {
|
|
374
|
-
gtag('consent', 'default', payload);
|
|
375
|
-
} catch (e) {
|
|
376
|
-
console.error('gtag is not available to send consent defaults: ', payload, e);
|
|
377
|
-
return false;
|
|
378
|
-
}
|
|
379
|
-
return true;
|
|
451
|
+
return false;
|
|
380
452
|
}
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
381
455
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
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;
|
|
391
467
|
}
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
392
470
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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;
|
|
401
481
|
}
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
402
484
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
for (var i = 0; i <= mappings.length - 1; i++) {
|
|
409
|
-
var mappingEntry = mappings[i];
|
|
410
|
-
// Although consent purposes can be inputted into the UI in any casing
|
|
411
|
-
// the SDK will automatically lowercase them to prevent pseudo-duplicate
|
|
412
|
-
// consent purposes, so we call `toLowerCase` on the consentMapping purposes here
|
|
413
|
-
var mpMappedConsentName = mappingEntry.map.toLowerCase();
|
|
414
|
-
// var mpMappedConsentName = mappingEntry.map;
|
|
415
|
-
var googleMappedConsentName = mappingEntry.value;
|
|
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);
|
|
416
489
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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;
|
|
426
508
|
}
|
|
427
|
-
|
|
428
|
-
return payload;
|
|
429
509
|
}
|
|
430
510
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
var jsHash = calculateJSHash(event.EventDataType, event.EventCategory, event.EventName);
|
|
434
|
-
var type = event.EventDataType === MessageType.PageEvent ? 'EventClass.Id' : 'EventClassDetails.Id';
|
|
435
|
-
var conversionLabel = null;
|
|
436
|
-
var mappingEntry = findValueInMapping(jsHash, type, labels);
|
|
437
|
-
|
|
438
|
-
if (mappingEntry) {
|
|
439
|
-
conversionLabel = mappingEntry.value;
|
|
440
|
-
}
|
|
511
|
+
return payload;
|
|
512
|
+
}
|
|
441
513
|
|
|
442
|
-
|
|
443
|
-
|
|
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;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
return conversionLabel;
|
|
533
|
+
}
|
|
444
534
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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];
|
|
459
560
|
}
|
|
460
561
|
}
|
|
461
562
|
}
|
|
462
|
-
|
|
463
|
-
return customProps;
|
|
464
563
|
}
|
|
465
564
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
var filteredArray = mapping.filter(function (mappingEntry) {
|
|
565
|
+
return customProps;
|
|
566
|
+
}
|
|
469
567
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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
|
+
}
|
|
473
581
|
|
|
474
|
-
|
|
475
|
-
|
|
582
|
+
return false;
|
|
583
|
+
});
|
|
476
584
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
}
|
|
585
|
+
if (filteredArray && filteredArray.length > 0) {
|
|
586
|
+
return filteredArray[0];
|
|
480
587
|
}
|
|
481
|
-
return null;
|
|
482
588
|
}
|
|
589
|
+
return null;
|
|
590
|
+
}
|
|
483
591
|
|
|
484
|
-
|
|
485
|
-
|
|
592
|
+
function calculateJSHash(eventDataType, eventCategory, name) {
|
|
593
|
+
var preHash = [eventDataType, eventCategory, name].join('');
|
|
486
594
|
|
|
487
|
-
|
|
488
|
-
|
|
595
|
+
return mParticle.generateHash(preHash);
|
|
596
|
+
}
|
|
489
597
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
gTagScript.async = true;
|
|
497
|
-
gTagScript.onload = function () {
|
|
498
|
-
gtag('js', new Date());
|
|
499
|
-
if (forwarderSettings.enableEnhancedConversions === 'True') {
|
|
500
|
-
gtag('config', gtagSiteId, {
|
|
501
|
-
allow_enhanced_conversions: true
|
|
502
|
-
});
|
|
503
|
-
} else {
|
|
504
|
-
gtag('config', gtagSiteId);
|
|
505
|
-
}
|
|
506
|
-
isInitialized = true;
|
|
507
|
-
processQueue(eventQueue);
|
|
508
|
-
};
|
|
509
|
-
gTagScript.src = 'https://www.googletagmanager.com/gtag/js?id=' + gtagSiteId;
|
|
510
|
-
document.getElementsByTagName('head')[0].appendChild(gTagScript);
|
|
511
|
-
})();
|
|
512
|
-
}
|
|
598
|
+
function loadGtagSnippet() {
|
|
599
|
+
(function() {
|
|
600
|
+
window.dataLayer = window.dataLayer || [];
|
|
601
|
+
window.gtag = function() {
|
|
602
|
+
dataLayer.push(arguments);
|
|
603
|
+
};
|
|
513
604
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
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
|
+
}
|
|
527
624
|
|
|
528
|
-
|
|
529
|
-
function
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
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
|
+
}
|
|
533
640
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
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
|
+
}
|
|
538
655
|
|
|
539
|
-
|
|
656
|
+
gtagSiteId = 'AW-' + forwarderSettings.conversionId;
|
|
540
657
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
} else {
|
|
545
|
-
loadLegacySnippet();
|
|
546
|
-
}
|
|
658
|
+
if (testMode !== true) {
|
|
659
|
+
if (forwarderSettings.enableGtag == 'True') {
|
|
660
|
+
loadGtagSnippet();
|
|
547
661
|
} else {
|
|
548
|
-
|
|
549
|
-
processQueue(eventQueue);
|
|
662
|
+
loadLegacySnippet();
|
|
550
663
|
}
|
|
664
|
+
} else {
|
|
665
|
+
isInitialized = true;
|
|
666
|
+
processQueue(eventQueue);
|
|
667
|
+
}
|
|
551
668
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
669
|
+
if (!forwarderSettings.conversionId) {
|
|
670
|
+
return (
|
|
671
|
+
"Can't initialize forwarder: " +
|
|
672
|
+
name +
|
|
673
|
+
', conversionId is not defined'
|
|
674
|
+
);
|
|
675
|
+
}
|
|
555
676
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
consentPayloadDefaults = getConsentSettings();
|
|
569
|
-
var defaultConsentPayload = cloneObject(consentPayloadDefaults);
|
|
570
|
-
var updatedConsentState = getUserConsentState();
|
|
571
|
-
var updatedDefaultConsentPayload =
|
|
572
|
-
generateConsentStatePayloadFromMappings(
|
|
573
|
-
updatedConsentState,
|
|
574
|
-
consentMappings
|
|
575
|
-
);
|
|
576
|
-
|
|
577
|
-
if (!isEmpty(defaultConsentPayload)) {
|
|
578
|
-
sendGtagConsentDefaults(defaultConsentPayload);
|
|
579
|
-
} else if (!isEmpty(updatedDefaultConsentPayload)) {
|
|
580
|
-
sendGtagConsentDefaults(updatedDefaultConsentPayload);
|
|
581
|
-
}
|
|
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
|
+
}
|
|
582
688
|
|
|
583
|
-
|
|
689
|
+
consentPayloadDefaults = getConsentSettings();
|
|
690
|
+
var defaultConsentPayload = cloneObject(consentPayloadDefaults);
|
|
691
|
+
var updatedConsentState = getUserConsentState();
|
|
692
|
+
var updatedDefaultConsentPayload = generateConsentStatePayloadFromMappings(
|
|
693
|
+
updatedConsentState,
|
|
694
|
+
consentMappings
|
|
695
|
+
);
|
|
584
696
|
|
|
697
|
+
if (!isEmpty(defaultConsentPayload)) {
|
|
698
|
+
sendGtagConsentDefaults(defaultConsentPayload);
|
|
699
|
+
} else if (!isEmpty(updatedDefaultConsentPayload)) {
|
|
700
|
+
sendGtagConsentDefaults(updatedDefaultConsentPayload);
|
|
585
701
|
}
|
|
586
702
|
|
|
587
|
-
|
|
703
|
+
maybeSendConsentUpdateToGoogle(updatedConsentState);
|
|
704
|
+
}
|
|
588
705
|
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
labels = JSON.parse(forwarderSettings.labels.replace(/"/g, '"'));
|
|
592
|
-
}
|
|
706
|
+
forwarderSettings.remarketingOnly =
|
|
707
|
+
forwarderSettings.remarketingOnly == 'True';
|
|
593
708
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
709
|
+
try {
|
|
710
|
+
if (forwarderSettings.labels) {
|
|
711
|
+
labels = JSON.parse(
|
|
712
|
+
forwarderSettings.labels.replace(/"/g, '"')
|
|
713
|
+
);
|
|
599
714
|
}
|
|
600
715
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
function processQueue(queue) {
|
|
609
|
-
var item;
|
|
610
|
-
|
|
611
|
-
if ((window.gtag || window.google_trackConversion) && queue.length > 0) {
|
|
612
|
-
try {
|
|
613
|
-
while (queue.length > 0) {
|
|
614
|
-
item = queue.shift();
|
|
615
|
-
item.action(item.data);
|
|
616
|
-
}
|
|
617
|
-
} catch (e) {
|
|
618
|
-
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
|
+
);
|
|
619
723
|
}
|
|
724
|
+
} catch (e) {
|
|
725
|
+
return (
|
|
726
|
+
"Can't initialize forwarder: " +
|
|
727
|
+
name +
|
|
728
|
+
', Could not process event to label mapping'
|
|
729
|
+
);
|
|
620
730
|
}
|
|
621
|
-
}
|
|
622
731
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
};
|
|
627
|
-
|
|
628
|
-
function getId() {
|
|
629
|
-
return moduleId;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
function register(config) {
|
|
633
|
-
if (!config) {
|
|
634
|
-
console.log('You must pass a config object to register the kit ' + name);
|
|
635
|
-
return;
|
|
732
|
+
return 'Successfully initialized: ' + name;
|
|
733
|
+
} catch (e) {
|
|
734
|
+
return 'Failed to initialize: ' + name;
|
|
636
735
|
}
|
|
736
|
+
}
|
|
637
737
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
return;
|
|
641
|
-
}
|
|
738
|
+
function processQueue(queue) {
|
|
739
|
+
var item;
|
|
642
740
|
|
|
643
|
-
if (
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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
|
+
}
|
|
652
753
|
}
|
|
653
|
-
console.log('Successfully registered ' + name + ' to your mParticle configuration');
|
|
654
754
|
}
|
|
655
755
|
|
|
656
|
-
|
|
657
|
-
|
|
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;
|
|
658
771
|
}
|
|
659
772
|
|
|
660
|
-
|
|
661
|
-
|
|
773
|
+
if (!isObject(config)) {
|
|
774
|
+
console.log(
|
|
775
|
+
"'config' must be an object. You passed in a " + typeof config
|
|
776
|
+
);
|
|
777
|
+
return;
|
|
662
778
|
}
|
|
663
779
|
|
|
664
|
-
|
|
665
|
-
|
|
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
|
+
};
|
|
666
789
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
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]];
|
|
676
816
|
}
|
|
677
|
-
return resObj;
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
function cloneObject(obj) {
|
|
681
|
-
return JSON.parse(JSON.stringify(obj));
|
|
682
817
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
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
|
+
});
|
|
692
832
|
}
|
|
833
|
+
}
|
|
693
834
|
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
835
|
+
var GoogleAdWordsEventForwarder = {
|
|
836
|
+
register: register,
|
|
837
|
+
};
|
|
697
838
|
|
|
698
839
|
exports.default = GoogleAdWordsEventForwarder;
|