@mparticle/web-double-click-kit 2.0.4 → 2.1.1
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.
- package/dist/DoubleClick-Kit.common.js +200 -5
- package/package.json +1 -1
|
@@ -2,7 +2,124 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
var googleConsentValues = {
|
|
6
|
+
// Server Integration uses 'Unspecified' as a value when the setting is 'not set'.
|
|
7
|
+
// However, this is not used by Google's Web SDK. We are referencing it here as a comment
|
|
8
|
+
// as a record of this distinction and for posterity.
|
|
9
|
+
// If Google ever adds this for web, the line can just be uncommented to support this.
|
|
10
|
+
//
|
|
11
|
+
// Docs:
|
|
12
|
+
// Web: https://developers.google.com/tag-platform/gtagjs/reference#consent
|
|
13
|
+
// S2S: https://developers.google.com/google-ads/api/reference/rpc/v15/ConsentStatusEnum.ConsentStatus
|
|
14
|
+
//
|
|
15
|
+
// Unspecified: 'unspecified',
|
|
16
|
+
Denied: 'denied',
|
|
17
|
+
Granted: 'granted',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Declares list of valid Google Consent Properties
|
|
21
|
+
var googleConsentProperties = [
|
|
22
|
+
'ad_storage',
|
|
23
|
+
'ad_user_data',
|
|
24
|
+
'ad_personalization',
|
|
25
|
+
'analytics_storage',
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
function ConsentHandler(common) {
|
|
29
|
+
this.common = common || {};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
ConsentHandler.prototype.getUserConsentState = function () {
|
|
33
|
+
var userConsentState = {};
|
|
34
|
+
|
|
35
|
+
if (mParticle.Identity && mParticle.Identity.getCurrentUser) {
|
|
36
|
+
var currentUser = mParticle.Identity.getCurrentUser();
|
|
37
|
+
|
|
38
|
+
if (!currentUser) {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var consentState =
|
|
43
|
+
mParticle.Identity.getCurrentUser().getConsentState();
|
|
44
|
+
|
|
45
|
+
if (consentState && consentState.getGDPRConsentState) {
|
|
46
|
+
userConsentState = consentState.getGDPRConsentState();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return userConsentState;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
ConsentHandler.prototype.getEventConsentState = function (eventConsentState) {
|
|
54
|
+
return eventConsentState && eventConsentState.getGDPRConsentState
|
|
55
|
+
? eventConsentState.getGDPRConsentState()
|
|
56
|
+
: {};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
ConsentHandler.prototype.getConsentSettings = function () {
|
|
60
|
+
var consentSettings = {};
|
|
61
|
+
|
|
62
|
+
var googleToMpConsentSettingsMapping = {
|
|
63
|
+
ad_user_data: 'defaultAdUserDataConsent',
|
|
64
|
+
ad_personalization: 'defaultAdPersonalizationConsent',
|
|
65
|
+
ad_storage: 'defaultAdStorageConsentWeb',
|
|
66
|
+
analytics_storage: 'defaultAnalyticsStorageConsentWeb',
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
var settings = this.common.settings;
|
|
70
|
+
|
|
71
|
+
Object.keys(googleToMpConsentSettingsMapping).forEach(function (
|
|
72
|
+
googleConsentKey
|
|
73
|
+
) {
|
|
74
|
+
var mpConsentSettingKey =
|
|
75
|
+
googleToMpConsentSettingsMapping[googleConsentKey];
|
|
76
|
+
var googleConsentValuesKey = settings[mpConsentSettingKey];
|
|
77
|
+
|
|
78
|
+
if (googleConsentValuesKey && mpConsentSettingKey) {
|
|
79
|
+
consentSettings[googleConsentKey] =
|
|
80
|
+
googleConsentValues[googleConsentValuesKey];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return consentSettings;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
ConsentHandler.prototype.generateConsentStatePayloadFromMappings = function (
|
|
88
|
+
consentState,
|
|
89
|
+
mappings
|
|
90
|
+
) {
|
|
91
|
+
if (!mappings) return {};
|
|
92
|
+
|
|
93
|
+
var payload = this.common.cloneObject(this.common.consentPayloadDefaults);
|
|
94
|
+
|
|
95
|
+
for (var i = 0; i <= mappings.length - 1; i++) {
|
|
96
|
+
var mappingEntry = mappings[i];
|
|
97
|
+
var mpMappedConsentName = mappingEntry.map;
|
|
98
|
+
var googleMappedConsentName = mappingEntry.value;
|
|
99
|
+
|
|
100
|
+
if (
|
|
101
|
+
consentState[mpMappedConsentName] &&
|
|
102
|
+
googleConsentProperties.indexOf(googleMappedConsentName) !== -1
|
|
103
|
+
) {
|
|
104
|
+
payload[googleMappedConsentName] = consentState[mpMappedConsentName]
|
|
105
|
+
.Consented
|
|
106
|
+
? googleConsentValues.Granted
|
|
107
|
+
: googleConsentValues.Denied;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return payload;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
var consent = ConsentHandler;
|
|
115
|
+
|
|
116
|
+
function Common() {
|
|
117
|
+
this.consentMappings = [];
|
|
118
|
+
this.consentPayloadDefaults = {};
|
|
119
|
+
this.consentPayloadAsString = '';
|
|
120
|
+
|
|
121
|
+
this.consentHandler = new consent(this);
|
|
122
|
+
}
|
|
6
123
|
|
|
7
124
|
Common.prototype.eventMapping = {};
|
|
8
125
|
Common.prototype.customVariablesMappings = {};
|
|
@@ -43,6 +160,21 @@ Common.prototype.sendGtag = function(type, properties, isInitialization) {
|
|
|
43
160
|
}
|
|
44
161
|
};
|
|
45
162
|
|
|
163
|
+
Common.prototype.sendGtagConsent = function (type, payload) {
|
|
164
|
+
function gtag() {
|
|
165
|
+
window.dataLayer.push(arguments);
|
|
166
|
+
}
|
|
167
|
+
gtag('consent', type, payload);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
Common.prototype.cloneObject = function (obj) {
|
|
171
|
+
return JSON.parse(JSON.stringify(obj));
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
Common.prototype.isEmpty = function isEmpty(value) {
|
|
175
|
+
return value == null || !(Object.keys(value) || value).length;
|
|
176
|
+
};
|
|
177
|
+
|
|
46
178
|
var common = Common;
|
|
47
179
|
|
|
48
180
|
function findValueInMapping(jsHash, mapping) {
|
|
@@ -147,7 +279,35 @@ function EventHandler(common) {
|
|
|
147
279
|
this.common = common || {};
|
|
148
280
|
}
|
|
149
281
|
|
|
150
|
-
EventHandler.prototype.
|
|
282
|
+
EventHandler.prototype.maybeSendConsentUpdateToGoogle = function (event) {
|
|
283
|
+
// If consent payload is empty,
|
|
284
|
+
// we never sent an initial default consent state
|
|
285
|
+
// so we shouldn't send an update.
|
|
286
|
+
if (this.common.consentPayloadAsString && this.common.consentMappings) {
|
|
287
|
+
var eventConsentState = this.common.consentHandler.getEventConsentState(
|
|
288
|
+
event.ConsentState
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
if (!this.common.isEmpty(eventConsentState)) {
|
|
292
|
+
var updatedConsentPayload =
|
|
293
|
+
this.common.consentHandler.generateConsentStatePayloadFromMappings(
|
|
294
|
+
eventConsentState,
|
|
295
|
+
this.common.consentMappings
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
var eventConsentAsString = JSON.stringify(updatedConsentPayload);
|
|
299
|
+
|
|
300
|
+
if (eventConsentAsString !== this.common.consentPayloadAsString) {
|
|
301
|
+
this.common.sendGtagConsent('update', updatedConsentPayload);
|
|
302
|
+
this.common.consentPayloadAsString = eventConsentAsString;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
EventHandler.prototype.logEvent = function (event) {
|
|
309
|
+
this.maybeSendConsentUpdateToGoogle(event);
|
|
310
|
+
|
|
151
311
|
var gtagProperties = {};
|
|
152
312
|
this.common.setCustomVariables(event, gtagProperties);
|
|
153
313
|
var eventMapping = this.common.getEventMapping(event);
|
|
@@ -250,6 +410,18 @@ var initialization = {
|
|
|
250
410
|
initForwarder: function(settings, testMode, userAttributes, userIdentities, processEvent, eventQueue, isInitialized, common) {
|
|
251
411
|
common.settings = settings;
|
|
252
412
|
|
|
413
|
+
if (common.settings.consentMappingWeb) {
|
|
414
|
+
common.consentMappings = parseSettingsString(
|
|
415
|
+
common.settings.consentMappingWeb
|
|
416
|
+
);
|
|
417
|
+
} else {
|
|
418
|
+
// Ensures consent mappings is an empty array
|
|
419
|
+
// for future use
|
|
420
|
+
common.consentMappings = [];
|
|
421
|
+
common.consentPayloadDefaults = {};
|
|
422
|
+
common.consentPayloadAsString = '';
|
|
423
|
+
}
|
|
424
|
+
|
|
253
425
|
window.dataLayer = window.dataLayer || [];
|
|
254
426
|
if (!testMode) {
|
|
255
427
|
var url = 'https://www.googletagmanager.com/gtag/js?id=' + settings.advertiserId;
|
|
@@ -275,13 +447,32 @@ var initialization = {
|
|
|
275
447
|
} else {
|
|
276
448
|
initializeGoogleDFP(common, settings);
|
|
277
449
|
}
|
|
278
|
-
|
|
450
|
+
|
|
451
|
+
common.consentPayloadDefaults =
|
|
452
|
+
common.consentHandler.getConsentSettings();
|
|
453
|
+
var initialConsentState = common.consentHandler.getUserConsentState();
|
|
454
|
+
var defaultConsentPayload =
|
|
455
|
+
common.consentHandler.generateConsentStatePayloadFromMappings(
|
|
456
|
+
initialConsentState,
|
|
457
|
+
common.consentMappings
|
|
458
|
+
);
|
|
459
|
+
|
|
460
|
+
if (!common.isEmpty(defaultConsentPayload)) {
|
|
461
|
+
common.consentPayloadAsString = JSON.stringify(
|
|
462
|
+
defaultConsentPayload
|
|
463
|
+
);
|
|
464
|
+
|
|
465
|
+
common.sendGtagConsent('default', defaultConsentPayload);
|
|
466
|
+
}
|
|
467
|
+
},
|
|
279
468
|
};
|
|
280
469
|
|
|
281
470
|
function initializeGoogleDFP(common, settings, isInitialized) {
|
|
282
|
-
common.eventMapping =
|
|
471
|
+
common.eventMapping = parseSettingsString(settings.eventMapping);
|
|
283
472
|
|
|
284
|
-
common.customVariablesMappings =
|
|
473
|
+
common.customVariablesMappings = parseSettingsString(
|
|
474
|
+
settings.customVariables
|
|
475
|
+
).reduce(function (a, b) {
|
|
285
476
|
a[b.map] = b.value;
|
|
286
477
|
return a;
|
|
287
478
|
}, {});
|
|
@@ -290,6 +481,10 @@ function initializeGoogleDFP(common, settings, isInitialized) {
|
|
|
290
481
|
common.sendGtag('config', settings.advertiserId, true);
|
|
291
482
|
}
|
|
292
483
|
|
|
484
|
+
function parseSettingsString(settingsString) {
|
|
485
|
+
return JSON.parse(settingsString.replace(/"/g, '"'));
|
|
486
|
+
}
|
|
487
|
+
|
|
293
488
|
var initialization_1 = initialization;
|
|
294
489
|
|
|
295
490
|
var sessionHandler = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-double-click-kit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-doubleclick",
|
|
5
5
|
"main": "dist/DoubleClick-Kit.common.js",
|
|
6
6
|
"browser": "dist/DoubleClick-Kit.common.js",
|