Skip to content

Commit

Permalink
fix:send default and update consent paylaods on kit init
Browse files Browse the repository at this point in the history
  • Loading branch information
mmustafa-tse committed Oct 8, 2024
1 parent 53e479c commit 3c691a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/GA4Client/src/initialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
11 changes: 7 additions & 4 deletions packages/GA4Client/test/src/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 3c691a0

Please sign in to comment.