angular/adev/shared-docs/utils/analytics.utils.ts
Alan Agius e8cfa44b10 refactor: ensure modules with 'declare global' are correctly handled by Rollup
Explicitly adding an `export {}` to modules containing declare global fixes an issue where Rollup would incorrectly claim that the global variable is not defined in the emitted .d.ts files.

Needed to land the latest rules_angular.
2026-03-13 13:07:28 -06:00

46 lines
1.1 KiB
TypeScript

/*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
declare global {
interface Window {
gtag?(...args: any[]): void;
}
}
export const setCookieConsent = (state: 'denied' | 'granted'): void => {
try {
if (window.gtag) {
const consentOptions = {
ad_user_data: state,
ad_personalization: state,
ad_storage: state,
analytics_storage: state,
};
if (state === 'denied') {
window.gtag('consent', 'default', {
...consentOptions,
wait_for_update: 500,
});
} else if (state === 'granted') {
window.gtag('consent', 'update', {
...consentOptions,
});
}
}
} catch {
if (state === 'denied') {
console.error('Unable to set default cookie consent.');
} else if (state === 'granted') {
console.error('Unable to grant cookie consent.');
}
}
};
// This fixes the RollupError: Exported variable "global" is not defined.
export {};