added /dist
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
||||
function toSignals(state) {
|
||||
const g = (b)=>b ? 'granted' : 'denied';
|
||||
return {
|
||||
ad_personalization: g(state.marketing),
|
||||
ad_storage: g(state.marketing),
|
||||
ad_user_data: g(state.marketing),
|
||||
analytics_storage: g(state.analytics),
|
||||
functionality_storage: g(state.functional),
|
||||
personalization_storage: g(state.functional),
|
||||
security_storage: 'granted'
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Mirrors Google's canonical snippet: `function gtag(){dataLayer.push(arguments)}`.
|
||||
*
|
||||
* Pushing `arguments` rather than a plain array is not a stylistic detail.
|
||||
* Google's tags recognise a consent command by the Arguments object it arrives
|
||||
* in; a real array lands in the dataLayer as ordinary data and the command is
|
||||
* silently ignored — the tag loads, but consent never updates and analytics
|
||||
* stays denied. The rest parameter exists only to type the call sites.
|
||||
*
|
||||
* Exported for the analytics module (which needs `js`/`config` commands) —
|
||||
* intentionally not re-exported from the package's public API.
|
||||
*/ export function gtag(..._args) {
|
||||
if (typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
// eslint-disable-next-line prefer-rest-params
|
||||
window.dataLayer.push(arguments);
|
||||
}
|
||||
/** Sets the default consent state (call before Google tags load). */ export function setDefaultConsent(state) {
|
||||
gtag('consent', 'default', {
|
||||
...toSignals(state),
|
||||
wait_for_update: 500
|
||||
});
|
||||
}
|
||||
/** Updates consent after the user decides. */ export function updateConsent(state) {
|
||||
gtag('consent', 'update', toSignals(state));
|
||||
}
|
||||
|
||||
//# sourceMappingURL=googleConsent.js.map
|
||||
Reference in New Issue
Block a user