forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics.utils.ts
More file actions
43 lines (40 loc) · 1.03 KB
/
analytics.utils.ts
File metadata and controls
43 lines (40 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*!
* @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.');
}
}
};