Skip to content

Commit 09c908f

Browse files
chore(build): Generate latest bundle [skip ci]
1 parent ec0bf79 commit 09c908f

File tree

2 files changed

+118
-84
lines changed

2 files changed

+118
-84
lines changed

packages/GA4Client/dist/GoogleAnalytics4EventForwarderClientSide-Kit.common.js

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ ConsentHandler.prototype.getUserConsentState = function () {
5050
return userConsentState;
5151
};
5252

53-
ConsentHandler.prototype.getEventConsentState = function (eventConsentState) {
54-
return eventConsentState && eventConsentState.getGDPRConsentState
55-
? eventConsentState.getGDPRConsentState()
56-
: {};
57-
};
58-
5953
ConsentHandler.prototype.getConsentSettings = function () {
6054
var consentSettings = {};
6155

@@ -258,6 +252,42 @@ Common.prototype.limitProductAttributes = function (attributes) {
258252
return this.mergeObjects(limitedProductAttributes, reservedAttributes);
259253
};
260254

255+
Common.prototype.getEventConsentState = function (eventConsentState) {
256+
return eventConsentState && eventConsentState.getGDPRConsentState
257+
? eventConsentState.getGDPRConsentState()
258+
: {};
259+
};
260+
261+
Common.prototype.maybeSendConsentUpdateToGoogle = function (consentState) {
262+
// If consent payload is empty,
263+
// we never sent an initial default consent state
264+
// so we shouldn't send an update.
265+
if (
266+
this.consentPayloadAsString &&
267+
this.consentMappings &&
268+
!this.isEmpty(consentState)
269+
) {
270+
var updatedConsentPayload =
271+
this.consentHandler.generateConsentStatePayloadFromMappings(
272+
consentState,
273+
this.consentMappings
274+
);
275+
276+
var eventConsentAsString = JSON.stringify(updatedConsentPayload);
277+
278+
if (eventConsentAsString !== this.consentPayloadAsString) {
279+
gtag('consent', 'update', updatedConsentPayload);
280+
this.consentPayloadAsString = eventConsentAsString;
281+
}
282+
}
283+
};
284+
285+
Common.prototype.sendDefaultConsentPayloadToGoogle = function (consentPayload) {
286+
this.consentPayloadAsString = JSON.stringify(consentPayload);
287+
288+
gtag('consent', 'default', consentPayload);
289+
};
290+
261291
Common.prototype.truncateEventName = function (eventName) {
262292
return truncateString(eventName, EVENT_NAME_MAX_LENGTH);
263293
};
@@ -1017,32 +1047,6 @@ function EventHandler(common) {
10171047
this.common = common || {};
10181048
}
10191049

1020-
EventHandler.prototype.maybeSendConsentUpdateToGa4 = function (event) {
1021-
// If consent payload is empty,
1022-
// we never sent an initial default consent state
1023-
// so we shouldn't send an update.
1024-
if (this.common.consentPayloadAsString && this.common.consentMappings) {
1025-
var eventConsentState = this.common.consentHandler.getEventConsentState(
1026-
event.ConsentState
1027-
);
1028-
1029-
if (!this.common.isEmpty(eventConsentState)) {
1030-
var updatedConsentPayload =
1031-
this.common.consentHandler.generateConsentStatePayloadFromMappings(
1032-
eventConsentState,
1033-
this.common.consentMappings
1034-
);
1035-
1036-
var eventConsentAsString = JSON.stringify(updatedConsentPayload);
1037-
1038-
if (eventConsentAsString !== this.common.consentPayloadAsString) {
1039-
gtag('consent', 'update', updatedConsentPayload);
1040-
this.common.consentPayloadAsString = eventConsentAsString;
1041-
}
1042-
}
1043-
}
1044-
};
1045-
10461050
// TODO: https://mparticle-eng.atlassian.net/browse/SQDSDKS-5715
10471051
EventHandler.prototype.sendEventToGA4 = function (eventName, eventAttributes) {
10481052
var standardizedEventName;
@@ -1073,7 +1077,10 @@ EventHandler.prototype.sendEventToGA4 = function (eventName, eventAttributes) {
10731077
};
10741078

10751079
EventHandler.prototype.logEvent = function (event) {
1076-
this.maybeSendConsentUpdateToGa4(event);
1080+
var eventConsentState = this.common.getEventConsentState(
1081+
event.ConsentState
1082+
);
1083+
this.common.maybeSendConsentUpdateToGoogle(eventConsentState);
10771084
this.sendEventToGA4(event.EventName, event.EventAttributes);
10781085
};
10791086

@@ -1124,7 +1131,10 @@ EventHandler.prototype.logPageView = function (event) {
11241131
event.EventAttributes
11251132
);
11261133

1127-
this.maybeSendConsentUpdateToGa4(event);
1134+
var eventConsentState = this.common.getEventConsentState(
1135+
event.ConsentState
1136+
);
1137+
this.common.maybeSendConsentUpdateToGoogle(eventConsentState);
11281138
this.sendEventToGA4('page_view', eventAttributes);
11291139

11301140
return true;
@@ -1303,22 +1313,29 @@ var initialization = {
13031313

13041314
common.consentPayloadDefaults =
13051315
common.consentHandler.getConsentSettings();
1306-
var initialConsentState = common.consentHandler.getUserConsentState();
1307-
1308-
var defaultConsentPayload =
1316+
var defaultConsentPayload = common.cloneObject(
1317+
common.consentPayloadDefaults
1318+
);
1319+
var updatedConsentState = common.consentHandler.getUserConsentState();
1320+
var updatedDefaultConsentPayload =
13091321
common.consentHandler.generateConsentStatePayloadFromMappings(
1310-
initialConsentState,
1322+
updatedConsentState,
13111323
common.consentMappings
13121324
);
13131325

1326+
// If a default consent payload exists (as selected in the mParticle UI), set it as the default
13141327
if (!common.isEmpty(defaultConsentPayload)) {
1315-
common.consentPayloadAsString = JSON.stringify(
1316-
defaultConsentPayload
1328+
common.sendDefaultConsentPayloadToGoogle(defaultConsentPayload);
1329+
// If a default consent payload does not exist, but the user currently has updated their consent,
1330+
// send that as the default because a default must be sent
1331+
} else if (!common.isEmpty(updatedDefaultConsentPayload)) {
1332+
common.sendDefaultConsentPayloadToGoogle(
1333+
updatedDefaultConsentPayload
13171334
);
1318-
1319-
gtag('consent', 'default', defaultConsentPayload);
13201335
}
13211336

1337+
common.maybeSendConsentUpdateToGoogle(updatedConsentState);
1338+
13221339
return isInitialized;
13231340
},
13241341
};

packages/GA4Client/dist/GoogleAnalytics4EventForwarderClientSide-Kit.iife.js

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ var GoogleAnalytics4Kit = (function (exports) {
4949
return userConsentState;
5050
};
5151

52-
ConsentHandler.prototype.getEventConsentState = function (eventConsentState) {
53-
return eventConsentState && eventConsentState.getGDPRConsentState
54-
? eventConsentState.getGDPRConsentState()
55-
: {};
56-
};
57-
5852
ConsentHandler.prototype.getConsentSettings = function () {
5953
var consentSettings = {};
6054

@@ -257,6 +251,42 @@ var GoogleAnalytics4Kit = (function (exports) {
257251
return this.mergeObjects(limitedProductAttributes, reservedAttributes);
258252
};
259253

254+
Common.prototype.getEventConsentState = function (eventConsentState) {
255+
return eventConsentState && eventConsentState.getGDPRConsentState
256+
? eventConsentState.getGDPRConsentState()
257+
: {};
258+
};
259+
260+
Common.prototype.maybeSendConsentUpdateToGoogle = function (consentState) {
261+
// If consent payload is empty,
262+
// we never sent an initial default consent state
263+
// so we shouldn't send an update.
264+
if (
265+
this.consentPayloadAsString &&
266+
this.consentMappings &&
267+
!this.isEmpty(consentState)
268+
) {
269+
var updatedConsentPayload =
270+
this.consentHandler.generateConsentStatePayloadFromMappings(
271+
consentState,
272+
this.consentMappings
273+
);
274+
275+
var eventConsentAsString = JSON.stringify(updatedConsentPayload);
276+
277+
if (eventConsentAsString !== this.consentPayloadAsString) {
278+
gtag('consent', 'update', updatedConsentPayload);
279+
this.consentPayloadAsString = eventConsentAsString;
280+
}
281+
}
282+
};
283+
284+
Common.prototype.sendDefaultConsentPayloadToGoogle = function (consentPayload) {
285+
this.consentPayloadAsString = JSON.stringify(consentPayload);
286+
287+
gtag('consent', 'default', consentPayload);
288+
};
289+
260290
Common.prototype.truncateEventName = function (eventName) {
261291
return truncateString(eventName, EVENT_NAME_MAX_LENGTH);
262292
};
@@ -1016,32 +1046,6 @@ var GoogleAnalytics4Kit = (function (exports) {
10161046
this.common = common || {};
10171047
}
10181048

1019-
EventHandler.prototype.maybeSendConsentUpdateToGa4 = function (event) {
1020-
// If consent payload is empty,
1021-
// we never sent an initial default consent state
1022-
// so we shouldn't send an update.
1023-
if (this.common.consentPayloadAsString && this.common.consentMappings) {
1024-
var eventConsentState = this.common.consentHandler.getEventConsentState(
1025-
event.ConsentState
1026-
);
1027-
1028-
if (!this.common.isEmpty(eventConsentState)) {
1029-
var updatedConsentPayload =
1030-
this.common.consentHandler.generateConsentStatePayloadFromMappings(
1031-
eventConsentState,
1032-
this.common.consentMappings
1033-
);
1034-
1035-
var eventConsentAsString = JSON.stringify(updatedConsentPayload);
1036-
1037-
if (eventConsentAsString !== this.common.consentPayloadAsString) {
1038-
gtag('consent', 'update', updatedConsentPayload);
1039-
this.common.consentPayloadAsString = eventConsentAsString;
1040-
}
1041-
}
1042-
}
1043-
};
1044-
10451049
// TODO: https://mparticle-eng.atlassian.net/browse/SQDSDKS-5715
10461050
EventHandler.prototype.sendEventToGA4 = function (eventName, eventAttributes) {
10471051
var standardizedEventName;
@@ -1072,7 +1076,10 @@ var GoogleAnalytics4Kit = (function (exports) {
10721076
};
10731077

10741078
EventHandler.prototype.logEvent = function (event) {
1075-
this.maybeSendConsentUpdateToGa4(event);
1079+
var eventConsentState = this.common.getEventConsentState(
1080+
event.ConsentState
1081+
);
1082+
this.common.maybeSendConsentUpdateToGoogle(eventConsentState);
10761083
this.sendEventToGA4(event.EventName, event.EventAttributes);
10771084
};
10781085

@@ -1123,7 +1130,10 @@ var GoogleAnalytics4Kit = (function (exports) {
11231130
event.EventAttributes
11241131
);
11251132

1126-
this.maybeSendConsentUpdateToGa4(event);
1133+
var eventConsentState = this.common.getEventConsentState(
1134+
event.ConsentState
1135+
);
1136+
this.common.maybeSendConsentUpdateToGoogle(eventConsentState);
11271137
this.sendEventToGA4('page_view', eventAttributes);
11281138

11291139
return true;
@@ -1302,22 +1312,29 @@ var GoogleAnalytics4Kit = (function (exports) {
13021312

13031313
common.consentPayloadDefaults =
13041314
common.consentHandler.getConsentSettings();
1305-
var initialConsentState = common.consentHandler.getUserConsentState();
1306-
1307-
var defaultConsentPayload =
1315+
var defaultConsentPayload = common.cloneObject(
1316+
common.consentPayloadDefaults
1317+
);
1318+
var updatedConsentState = common.consentHandler.getUserConsentState();
1319+
var updatedDefaultConsentPayload =
13081320
common.consentHandler.generateConsentStatePayloadFromMappings(
1309-
initialConsentState,
1321+
updatedConsentState,
13101322
common.consentMappings
13111323
);
13121324

1325+
// If a default consent payload exists (as selected in the mParticle UI), set it as the default
13131326
if (!common.isEmpty(defaultConsentPayload)) {
1314-
common.consentPayloadAsString = JSON.stringify(
1315-
defaultConsentPayload
1327+
common.sendDefaultConsentPayloadToGoogle(defaultConsentPayload);
1328+
// If a default consent payload does not exist, but the user currently has updated their consent,
1329+
// send that as the default because a default must be sent
1330+
} else if (!common.isEmpty(updatedDefaultConsentPayload)) {
1331+
common.sendDefaultConsentPayloadToGoogle(
1332+
updatedDefaultConsentPayload
13161333
);
1317-
1318-
gtag('consent', 'default', defaultConsentPayload);
13191334
}
13201335

1336+
common.maybeSendConsentUpdateToGoogle(updatedConsentState);
1337+
13211338
return isInitialized;
13221339
},
13231340
};

0 commit comments

Comments
 (0)