Skip to content

Commit

Permalink
Listen for consent state changes
Browse files Browse the repository at this point in the history
  • Loading branch information
martynmjones committed May 16, 2024
1 parent d1e3592 commit 3e10ac4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions assets/js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,20 @@ function warnIfDataMissing() {
);
}
}

document.addEventListener( 'wp_listen_for_consent_change', function ( event ) {
const consentUpdate = {};

const types = consentMap[ Object.keys( event.detail )[0] ];

Check failure on line 67 in assets/js/src/index.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript

[prettier/prettier] Replace `0` with `·0·`
const state = Object.values( event.detail )[0] === 'allow' ? 'granted' : 'deny';

Check failure on line 68 in assets/js/src/index.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript

[prettier/prettier] Replace `·Object.values(·event.detail·)[0` with `⏎↹↹Object.values(·event.detail·)[·0·`

if ( types !== undefined ) {
types.forEach( type => {

Check failure on line 71 in assets/js/src/index.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript

[prettier/prettier] Replace `type` with `(·type·)`
consentUpdate[ type ] = state;
} );

if ( Object.keys( consentUpdate ).length > 0 ) {
gtag( 'consent', 'update', consentUpdate );

Check failure on line 76 in assets/js/src/index.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript

[no-undef] 'gtag' is not defined.
}
}
});

0 comments on commit 3e10ac4

Please sign in to comment.