@mparticle/web-double-click-kit 2.1.2 → 2.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.
@@ -50,12 +50,6 @@ ConsentHandler.prototype.getUserConsentState = function () {
50
50
  return userConsentState;
51
51
  };
52
52
 
53
- ConsentHandler.prototype.getEventConsentState = function (eventConsentState) {
54
- return eventConsentState && eventConsentState.getGDPRConsentState
55
- ? eventConsentState.getGDPRConsentState()
56
- : {};
57
- };
58
-
59
53
  ConsentHandler.prototype.getConsentSettings = function () {
60
54
  var consentSettings = {};
61
55
 
@@ -126,6 +120,7 @@ function Common() {
126
120
 
127
121
  Common.prototype.eventMapping = {};
128
122
  Common.prototype.customVariablesMappings = {};
123
+ Common.prototype.customFieldMappings = {};
129
124
  Common.prototype.settings = {};
130
125
  Common.prototype.setCustomVariables = function(event, gtagProperties) {
131
126
  for (var attribute in event.EventAttributes) {
@@ -135,6 +130,20 @@ Common.prototype.setCustomVariables = function(event, gtagProperties) {
135
130
  }
136
131
  }
137
132
  };
133
+ Common.prototype.setCustomFields = function(event, gtagProperties) {
134
+ var dc_custom_params = {};
135
+ var hasMappings = false;
136
+ for (var attribute in event.EventAttributes) {
137
+ if (this.customFieldMappings[attribute]) {
138
+ dc_custom_params[this.customFieldMappings[attribute]] =
139
+ event.EventAttributes[attribute];
140
+ hasMappings = true;
141
+ }
142
+ }
143
+ if (hasMappings) {
144
+ gtagProperties["dc_custom_params"] = dc_custom_params;
145
+ }
146
+ };
138
147
  Common.prototype.setSendTo = function(mapping, customFlags, gtagProperties) {
139
148
  var tags = mapping.value.split(';');
140
149
  var groupTag = tags[0];
@@ -170,6 +179,42 @@ Common.prototype.sendGtagConsent = function (type, payload) {
170
179
  gtag('consent', type, payload);
171
180
  };
172
181
 
182
+ Common.prototype.getEventConsentState = function (eventConsentState) {
183
+ return eventConsentState && eventConsentState.getGDPRConsentState
184
+ ? eventConsentState.getGDPRConsentState()
185
+ : {};
186
+ };
187
+
188
+ Common.prototype.maybeSendConsentUpdateToGoogle = function (consentState) {
189
+ // If consent payload is empty,
190
+ // we never sent an initial default consent state
191
+ // so we shouldn't send an update.
192
+ if (
193
+ this.consentPayloadAsString &&
194
+ this.consentMappings &&
195
+ !this.isEmpty(consentState)
196
+ ) {
197
+ var updatedConsentPayload =
198
+ this.consentHandler.generateConsentStatePayloadFromMappings(
199
+ consentState,
200
+ this.consentMappings
201
+ );
202
+
203
+ var eventConsentAsString = JSON.stringify(updatedConsentPayload);
204
+
205
+ if (eventConsentAsString !== this.consentPayloadAsString) {
206
+ this.sendGtagConsent('update', updatedConsentPayload);
207
+ this.consentPayloadAsString = eventConsentAsString;
208
+ }
209
+ }
210
+ };
211
+
212
+ Common.prototype.sendDefaultConsentPayloadToGoogle = function (consentPayload) {
213
+ this.consentPayloadAsString = JSON.stringify(consentPayload);
214
+
215
+ this.sendGtagConsent('default', consentPayload);
216
+ };
217
+
173
218
  Common.prototype.cloneObject = function (obj) {
174
219
  return JSON.parse(JSON.stringify(obj));
175
220
  };
@@ -282,37 +327,15 @@ function EventHandler(common) {
282
327
  this.common = common || {};
283
328
  }
284
329
 
285
- EventHandler.prototype.maybeSendConsentUpdateToGoogle = function (event) {
286
- // If consent payload is empty,
287
- // we never sent an initial default consent state
288
- // so we shouldn't send an update.
289
- if (this.common.consentPayloadAsString && this.common.consentMappings) {
290
- var eventConsentState = this.common.consentHandler.getEventConsentState(
291
- event.ConsentState
292
- );
293
-
294
- if (!this.common.isEmpty(eventConsentState)) {
295
- var updatedConsentPayload =
296
- this.common.consentHandler.generateConsentStatePayloadFromMappings(
297
- eventConsentState,
298
- this.common.consentMappings
299
- );
300
-
301
- var eventConsentAsString = JSON.stringify(updatedConsentPayload);
302
-
303
- if (eventConsentAsString !== this.common.consentPayloadAsString) {
304
- this.common.sendGtagConsent('update', updatedConsentPayload);
305
- this.common.consentPayloadAsString = eventConsentAsString;
306
- }
307
- }
308
- }
309
- };
310
-
311
330
  EventHandler.prototype.logEvent = function (event) {
312
- this.maybeSendConsentUpdateToGoogle(event);
331
+ var eventConsentState = this.common.getEventConsentState(
332
+ event.ConsentState
333
+ );
334
+ this.common.maybeSendConsentUpdateToGoogle(eventConsentState);
313
335
 
314
336
  var gtagProperties = {};
315
337
  this.common.setCustomVariables(event, gtagProperties);
338
+ this.common.setCustomFields(event, gtagProperties);
316
339
  var eventMapping = this.common.getEventMapping(event);
317
340
 
318
341
  if (!eventMapping) {
@@ -453,20 +476,28 @@ var initialization = {
453
476
 
454
477
  common.consentPayloadDefaults =
455
478
  common.consentHandler.getConsentSettings();
456
- var initialConsentState = common.consentHandler.getUserConsentState();
457
- var defaultConsentPayload =
479
+ var defaultConsentPayload = common.cloneObject(
480
+ common.consentPayloadDefaults
481
+ );
482
+ var updatedConsentState = common.consentHandler.getUserConsentState();
483
+ var updatedDefaultConsentPayload =
458
484
  common.consentHandler.generateConsentStatePayloadFromMappings(
459
- initialConsentState,
485
+ updatedConsentState,
460
486
  common.consentMappings
461
487
  );
462
-
488
+
489
+ // If a default consent payload exists (as selected in the mParticle UI), set it as the default
463
490
  if (!common.isEmpty(defaultConsentPayload)) {
464
- common.consentPayloadAsString = JSON.stringify(
465
- defaultConsentPayload
491
+ common.sendDefaultConsentPayloadToGoogle(defaultConsentPayload);
492
+ // If a default consent payload does not exist, but the user currently has updated their consent,
493
+ // send that as the default because a default must be sent
494
+ } else if (!common.isEmpty(updatedDefaultConsentPayload)) {
495
+ common.sendDefaultConsentPayloadToGoogle(
496
+ updatedDefaultConsentPayload
466
497
  );
467
-
468
- common.sendGtagConsent('default', defaultConsentPayload);
469
498
  }
499
+
500
+ common.maybeSendConsentUpdateToGoogle(updatedConsentState);
470
501
  },
471
502
  };
472
503
 
@@ -479,6 +510,12 @@ function initializeGoogleDFP(common, settings, isInitialized) {
479
510
  a[b.map] = b.value;
480
511
  return a;
481
512
  }, {});
513
+ common.customFieldMappings = parseSettingsString(
514
+ settings.customParams
515
+ ).reduce(function (a, b) {
516
+ a[b.map] = b.value;
517
+ return a;
518
+ }, {});
482
519
  common.sendGtag('js', new Date(), true);
483
520
  common.sendGtag('allow_custom_scripts', true, true);
484
521
  common.sendGtag('config', settings.advertiserId, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-double-click-kit",
3
- "version": "2.1.2",
3
+ "version": "2.2.0",
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",