From 3c691a0970c26f0391de75b681110fb4cd3c2d85 Mon Sep 17 00:00:00 2001 From: Mo Mustafa Date: Tue, 8 Oct 2024 11:59:12 -0700 Subject: [PATCH] fix:send default and update consent paylaods on kit init --- packages/GA4Client/src/initialization.js | 3 +++ packages/GA4Client/test/src/tests.js | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/GA4Client/src/initialization.js b/packages/GA4Client/src/initialization.js index 90b9d57..79a4139 100644 --- a/packages/GA4Client/src/initialization.js +++ b/packages/GA4Client/src/initialization.js @@ -116,8 +116,11 @@ var initialization = { ); if (!common.isEmpty(defaultConsentPayload)) { + // If a default consent payload exists (as selected in the mParticle UI), set it as the default common.sendDefaultConsentPayloadToGoogle(defaultConsentPayload); } else if (!common.isEmpty(updatedDefaultConsentPayload)) { + // If a default consent payload does not exist, but the user currently has updated their consent, + // send that as the default because a default must be sent common.sendDefaultConsentPayloadToGoogle( updatedDefaultConsentPayload ); diff --git a/packages/GA4Client/test/src/tests.js b/packages/GA4Client/test/src/tests.js index f02163f..2c0b998 100644 --- a/packages/GA4Client/test/src/tests.js +++ b/packages/GA4Client/test/src/tests.js @@ -2914,7 +2914,8 @@ describe('Google Analytics 4 Event', function () { ]; // Initial elements of Data Layer are setup for gtag. - // Consent state should be on the bottom + // Default Consent payload from default settings should be index 3 + // Update Consent payload from mappings should be on the bottom (index 4) window.dataLayer.length.should.eql(5); window.dataLayer[3][0].should.equal('consent'); window.dataLayer[3][1].should.equal('default'); @@ -2978,7 +2979,8 @@ describe('Google Analytics 4 Event', function () { // Initial elements of Data Layer are setup for gtag. // Consent Default is index 3 - // Consent Update is index 5 + // Initial Consent Update from mappings is index 4 + // Consent Update #2 is index 5 // Event is index 6 window.dataLayer.length.should.eql(7); window.dataLayer[5][0].should.equal('consent'); @@ -3050,9 +3052,10 @@ describe('Google Analytics 4 Event', function () { // Initial elements of Data Layer are setup for gtag. // Consent Default is index 3 - // Consent Update is index 5 + // Initial Consent Update from mappings is index 4 + // Consent Update #2 is index 5 // Event is index 6 - // Consent Update #2 is index 7 + // Consent Update #3 is index 7 // Event #2 is index 8 window.dataLayer.length.should.eql(9); window.dataLayer[7][0].should.equal('consent');