@leancodepl/cookie-consent 9.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file. See
4
+ [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [9.5.3](https://github.com/leancodepl/js_corelibrary/compare/v9.5.2...v9.5.3) (2025-08-26)
7
+
8
+ ### Bug Fixes
9
+
10
+ - adjust default language handling
11
+ ([33fe746](https://github.com/leancodepl/js_corelibrary/commit/33fe74637f790b4476fed3f8015ae49e7eee5ce8))
12
+ - adjust types ([5de20ba](https://github.com/leancodepl/js_corelibrary/commit/5de20bacc553ba0724bb44cb851469b274326a8d))
13
+ - gtag package version
14
+ ([938e5c0](https://github.com/leancodepl/js_corelibrary/commit/938e5c0056d6063c280aeac080ffff60faccfc93))
15
+
16
+ ### Features
17
+
18
+ - create basic cookie consent setup
19
+ ([edb082a](https://github.com/leancodepl/js_corelibrary/commit/edb082a93d07205366279f4819b9e0d7e1abefa2))
20
+ - create default consent config
21
+ ([4f49ad2](https://github.com/leancodepl/js_corelibrary/commit/4f49ad2526b27c4f954eb41943ef03c2ff377906))
package/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # @leancodepl/cookie-consent
2
+
3
+ Cookie consent helper that wires `vanilla-cookieconsent` with Google Consent Mode via `"@leancodepl/gtag"`.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @leancodepl/cookie-consent
9
+ # or
10
+ yarn add @leancodepl/cookie-consent
11
+ ```
12
+
13
+ ## API
14
+
15
+ ### `getDefaultConsentConfig(options)`
16
+
17
+ Creates a default cookie consent configuration with configurable languages and categories.
18
+
19
+ - **Parameters**
20
+ - `options: DefaultConsentOptions` – Configuration options for languages and enabled categories
21
+ - `language: ("en" | "pl")[]` – Supported languages array
22
+ - `advertisement?: boolean` – Enable advertisement category
23
+ - `analytics?: boolean` – Enable analytics category
24
+ - `security?: boolean` – Enable security category
25
+ - `functionality?: boolean` – Enable functionality category
26
+ - **Returns**
27
+ - `CookieConsentConfig` – Complete cookie consent configuration ready for `runCookieConsent`
28
+
29
+ ### `runCookieConsent(config)`
30
+
31
+ Runs cookie consent and synchronizes consent state with Google via `"@leancodepl/gtag"`.
32
+
33
+ - **Parameters**
34
+ - `config: CookieConsentConfig` – Cookie consent configuration mirroring `vanilla-cookieconsent` options, with a
35
+ strongly-typed `categories` shape for Google Consent Mode services.
36
+ - **Returns**
37
+ - `Promise<typeof CookieConsent>` – The `vanilla-cookieconsent` module instance after initialization
38
+
39
+ ## Usage Examples
40
+
41
+ ### Using Default Configuration
42
+
43
+ ```jsx
44
+ import "vanilla-cookieconsent/dist/cookieconsent.css"
45
+ import { getDefaultConsentConfig, runCookieConsent } from "@leancodepl/cookie-consent"
46
+
47
+ useEffect(() => {
48
+ const config = getDefaultConsentConfig({
49
+ language: ["en", "pl"], // English as default
50
+ analytics: true,
51
+ advertisement: true,
52
+ functionality: true,
53
+ })
54
+
55
+ runCookieConsent(config)
56
+ }, [])
57
+ ```
58
+
59
+ ### Custom Configuration
60
+
61
+ ```jsx
62
+ import "vanilla-cookieconsent/dist/cookieconsent.css"
63
+ import "yourCustomStyles.css" // custom optional styles
64
+
65
+ useEffect(() => {
66
+ runCookieConsent({
67
+ categories: {
68
+ analytics: {
69
+ services: {
70
+ analytics_storage: {
71
+ label: "Enables storage (such as cookies) related to analytics e.g. visit duration.",
72
+ },
73
+ },
74
+ },
75
+ },
76
+ guiOptions: {
77
+ consentModal: {
78
+ layout: "box wide",
79
+ position: "bottom right",
80
+ },
81
+ preferencesModal: {
82
+ layout: "box",
83
+ },
84
+ },
85
+ language: {
86
+ default: "en",
87
+ translations: {
88
+ en: {
89
+ consentModal: {
90
+ title: "We use cookies",
91
+ description:
92
+ "This website uses essential cookies to ensure its proper operation and tracking cookies to understand how you interact with it. The latter will be set only after consent.",
93
+ acceptAllBtn: "Accept all",
94
+ acceptNecessaryBtn: "Reject all",
95
+ showPreferencesBtn: "Manage Individual preferences",
96
+ },
97
+ preferencesModal: {
98
+ title: "Manage cookie preferences",
99
+ acceptAllBtn: "Accept all",
100
+ acceptNecessaryBtn: "Reject all",
101
+ savePreferencesBtn: "Accept current selection",
102
+ closeIconLabel: "Close modal",
103
+ sections: [
104
+ {
105
+ title: "Cookie usage",
106
+ description:
107
+ "We use cookies to ensure the basic functionalities of the website and to enhance your online experience.",
108
+ },
109
+ {
110
+ title: "Strictly necessary cookies",
111
+ description:
112
+ "These cookies are essential for the proper functioning of the website, for example for user authentication.",
113
+ linkedCategory: "necessary",
114
+ },
115
+ {
116
+ title: "Analytics",
117
+ description:
118
+ "Cookies used for analytics help collect data that allows services to understand how users interact with a particular service. These insights allow services both to improve content and to build better features that improve the user’s experience.",
119
+ linkedCategory: "analytics",
120
+ cookieTable: {
121
+ headers: {
122
+ name: "Name",
123
+ domain: "Service",
124
+ description: "Description",
125
+ expiration: "Expiration",
126
+ },
127
+ body: [
128
+ {
129
+ name: "_ga",
130
+ domain: "Google Analytics",
131
+ description:
132
+ 'Cookie set by <a href="https://business.safety.google/adscookies/">Google Analytics</a>',
133
+ expiration: "Expires after 12 days",
134
+ },
135
+ {
136
+ name: "_gid",
137
+ domain: "Google Analytics",
138
+ description:
139
+ 'Cookie set by <a href="https://business.safety.google/adscookies/">Google Analytics</a>',
140
+ expiration: "Session",
141
+ },
142
+ ],
143
+ },
144
+ },
145
+ {
146
+ title: "Advertising",
147
+ description:
148
+ 'Google uses cookies for advertising, including serving and rendering ads, personalizing ads (depending on your ad settings at <a href=\"https://g.co/adsettings\">g.co/adsettings</a>), limiting the number of times an ad is shown to a user, muting ads you have chosen to stop seeing, and measuring the effectiveness of ads.',
149
+ linkedCategory: "advertising",
150
+ },
151
+ {
152
+ title: "Functionality",
153
+ description:
154
+ "Cookies used for functionality allow users to interact with a service or site to access features that are fundamental to that service. Things considered fundamental to the service include preferences like the user’s choice of language, product optimizations that help maintain and improve a service, and maintaining information relating to a user’s session, such as the content of a shopping cart.",
155
+ linkedCategory: "functionality",
156
+ },
157
+ {
158
+ title: "Security",
159
+ description:
160
+ "Cookies used for security authenticate users, prevent fraud, and protect users as they interact with a service.",
161
+ linkedCategory: "security",
162
+ },
163
+ {
164
+ title: "More information",
165
+ description:
166
+ 'For any queries in relation to the policy on cookies and your choices, please <a href="https://www.example.com/contacts">contact us</a>.',
167
+ },
168
+ ],
169
+ },
170
+ },
171
+ },
172
+ },
173
+ })
174
+ }, [])
175
+ ```
176
+
177
+ For advanced configuration and UI customization, refer to the official vanilla-cookieconsent documentation:
178
+ https://cookieconsent.orestbida.com/
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@leancodepl/cookie-consent",
3
+ "version": "9.5.3",
4
+ "license": "Apache-2.0",
5
+ "type": "module",
6
+ "dependencies": {
7
+ "@leancodepl/gtag": "9.5.3",
8
+ "vanilla-cookieconsent": "^3.1.0"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public",
12
+ "registry": "https://registry.npmjs.org/"
13
+ },
14
+ "engines": {
15
+ "node": ">=18.0.0"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/leancodepl/js_corelibrary.git",
20
+ "directory": "packages/cookie-consent"
21
+ },
22
+ "homepage": "https://github.com/leancodepl/js_corelibrary",
23
+ "bugs": {
24
+ "url": "https://github.com/leancodepl/js_corelibrary/issues"
25
+ },
26
+ "description": "Cookie consent library with Google Consent Mode support",
27
+ "keywords": [
28
+ "cookie-consent",
29
+ "google-consent-mode",
30
+ "javascript",
31
+ "typescript",
32
+ "leancode",
33
+ "vanilla-cookieconsent"
34
+ ],
35
+ "author": {
36
+ "name": "LeanCode",
37
+ "url": "https://leancode.co"
38
+ },
39
+ "sideEffects": false,
40
+ "types": "./src/index.d.ts",
41
+ "module": "./src/index.js",
42
+ "main": "./src/index.js"
43
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./lib/runCookieConsent";
2
+ export * from "./lib/getDefaultConsentConfig";
package/src/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./lib/runCookieConsent";
2
+ export * from "./lib/getDefaultConsentConfig";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/cookie-consent/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,+BAA+B,CAAA"}
@@ -0,0 +1,208 @@
1
+ export declare const config: {
2
+ en: {
3
+ language: {
4
+ consentModal: {
5
+ title: string;
6
+ description: string;
7
+ acceptAllBtn: string;
8
+ acceptNecessaryBtn: string;
9
+ showPreferencesBtn: string;
10
+ };
11
+ preferencesModal: {
12
+ title: string;
13
+ acceptAllBtn: string;
14
+ acceptNecessaryBtn: string;
15
+ savePreferencesBtn: string;
16
+ closeIconLabel: string;
17
+ baseSection: {
18
+ title: string;
19
+ description: string;
20
+ };
21
+ necessarySection: {
22
+ title: string;
23
+ description: string;
24
+ };
25
+ };
26
+ categoryPreferenceLabels: {
27
+ analytics: {
28
+ title: string;
29
+ description: string;
30
+ cookieTable: {
31
+ headers: {
32
+ name: string;
33
+ domain: string;
34
+ description: string;
35
+ expiration: string;
36
+ };
37
+ body: {
38
+ name: string;
39
+ domain: string;
40
+ description: string;
41
+ expiration: string;
42
+ }[];
43
+ };
44
+ };
45
+ advertisement: {
46
+ title: string;
47
+ description: string;
48
+ };
49
+ functionality: {
50
+ title: string;
51
+ description: string;
52
+ };
53
+ security: {
54
+ title: string;
55
+ description: string;
56
+ };
57
+ };
58
+ };
59
+ categories: {
60
+ analytics: {
61
+ services: {
62
+ analytics_storage: {
63
+ label: string;
64
+ };
65
+ };
66
+ };
67
+ advertisement: {
68
+ enabled: boolean;
69
+ readOnly: boolean;
70
+ services: {
71
+ ad_storage: {
72
+ label: string;
73
+ };
74
+ ad_user_data: {
75
+ label: string;
76
+ };
77
+ ad_personalization: {
78
+ label: string;
79
+ };
80
+ };
81
+ };
82
+ functionality: {
83
+ enabled: boolean;
84
+ readOnly: boolean;
85
+ services: {
86
+ functionality_storage: {
87
+ label: string;
88
+ };
89
+ personalization_storage: {
90
+ label: string;
91
+ };
92
+ };
93
+ };
94
+ security: {
95
+ enabled: boolean;
96
+ readOnly: boolean;
97
+ services: {
98
+ security_storage: {
99
+ label: string;
100
+ };
101
+ };
102
+ };
103
+ };
104
+ };
105
+ pl: {
106
+ language: {
107
+ consentModal: {
108
+ title: string;
109
+ description: string;
110
+ acceptAllBtn: string;
111
+ acceptNecessaryBtn: string;
112
+ showPreferencesBtn: string;
113
+ };
114
+ preferencesModal: {
115
+ title: string;
116
+ acceptAllBtn: string;
117
+ acceptNecessaryBtn: string;
118
+ savePreferencesBtn: string;
119
+ closeIconLabel: string;
120
+ baseSection: {
121
+ title: string;
122
+ description: string;
123
+ };
124
+ necessarySection: {
125
+ title: string;
126
+ description: string;
127
+ };
128
+ };
129
+ categoryPreferenceLabels: {
130
+ analytics: {
131
+ title: string;
132
+ description: string;
133
+ cookieTable: {
134
+ headers: {
135
+ name: string;
136
+ domain: string;
137
+ description: string;
138
+ expiration: string;
139
+ };
140
+ body: {
141
+ name: string;
142
+ domain: string;
143
+ description: string;
144
+ expiration: string;
145
+ }[];
146
+ };
147
+ };
148
+ advertisement: {
149
+ title: string;
150
+ description: string;
151
+ };
152
+ functionality: {
153
+ title: string;
154
+ description: string;
155
+ };
156
+ security: {
157
+ title: string;
158
+ description: string;
159
+ };
160
+ };
161
+ };
162
+ categories: {
163
+ analytics: {
164
+ services: {
165
+ analytics_storage: {
166
+ label: string;
167
+ };
168
+ };
169
+ };
170
+ advertisement: {
171
+ enabled: boolean;
172
+ readOnly: boolean;
173
+ services: {
174
+ ad_storage: {
175
+ label: string;
176
+ };
177
+ ad_user_data: {
178
+ label: string;
179
+ };
180
+ ad_personalization: {
181
+ label: string;
182
+ };
183
+ };
184
+ };
185
+ functionality: {
186
+ enabled: boolean;
187
+ readOnly: boolean;
188
+ services: {
189
+ functionality_storage: {
190
+ label: string;
191
+ };
192
+ personalization_storage: {
193
+ label: string;
194
+ };
195
+ };
196
+ };
197
+ security: {
198
+ enabled: boolean;
199
+ readOnly: boolean;
200
+ services: {
201
+ security_storage: {
202
+ label: string;
203
+ };
204
+ };
205
+ };
206
+ };
207
+ };
208
+ };
@@ -0,0 +1,218 @@
1
+ import { catAdvertisement, catAnalytics, catFunctionality, catSecurity, serviceAdPersonalization, serviceAdStorage, serviceAdUserData, serviceAnalyticsStorage, serviceFunctionalityStorage, servicePersonalizationStorage, serviceSecurityStorage, } from "./getGoogleConsent";
2
+ const googleAnalyticsCookieName = "_ga";
3
+ const googleAnalyticsSessionCookieName = "_gid";
4
+ export const config = {
5
+ en: {
6
+ language: {
7
+ consentModal: {
8
+ title: "We use cookies",
9
+ description: "This website uses essential cookies to ensure its proper operation and tracking cookies to understand how you interact with it. The latter will be set only after consent.",
10
+ acceptAllBtn: "Accept all",
11
+ acceptNecessaryBtn: "Reject all",
12
+ showPreferencesBtn: "Manage Individual preferences",
13
+ },
14
+ preferencesModal: {
15
+ title: "Manage cookie preferences",
16
+ acceptAllBtn: "Accept all",
17
+ acceptNecessaryBtn: "Reject all",
18
+ savePreferencesBtn: "Accept current selection",
19
+ closeIconLabel: "Close modal",
20
+ baseSection: {
21
+ title: "Cookie usage",
22
+ description: "We use cookies to ensure the basic functionalities of the website and to enhance your online experience.",
23
+ },
24
+ necessarySection: {
25
+ title: "Strictly necessary cookies",
26
+ description: "These cookies are essential for the proper functioning of the website, for example for user authentication.",
27
+ },
28
+ },
29
+ categoryPreferenceLabels: {
30
+ analytics: {
31
+ title: "Analytics",
32
+ description: "Cookies used for analytics help collect data that allows services to understand how users interact with a particular service. These insights allow services both to improve content and to build better features that improve the user's experience.",
33
+ cookieTable: {
34
+ headers: { name: "Name", domain: "Service", description: "Description", expiration: "Expiration" },
35
+ body: [
36
+ {
37
+ name: googleAnalyticsCookieName,
38
+ domain: "Google Analytics",
39
+ description: 'Cookie set by <a href="https://business.safety.google/adscookies/">Google Analytics</a>',
40
+ expiration: "Expires after 12 days",
41
+ },
42
+ {
43
+ name: googleAnalyticsSessionCookieName,
44
+ domain: "Google Analytics",
45
+ description: 'Cookie set by <a href="https://business.safety.google/adscookies/">Google Analytics</a>',
46
+ expiration: "Session",
47
+ },
48
+ ],
49
+ },
50
+ },
51
+ advertisement: {
52
+ title: "Advertising",
53
+ description: 'Google uses cookies for advertising, including serving and rendering ads, personalizing ads (depending on your ad settings at <a href="https://g.co/adsettings">g.co/adsettings</a>), limiting the number of times an ad is shown to a user, muting ads you have chosen to stop seeing, and measuring the effectiveness of ads.',
54
+ },
55
+ functionality: {
56
+ title: "Functionality",
57
+ description: "Cookies used for functionality allow users to interact with a service or site to access features that are fundamental to that service. Things considered fundamental to the service include preferences like the user's choice of language, product optimizations that help maintain and improve a service, and maintaining information relating to a user's session, such as the content of a shopping cart.",
58
+ },
59
+ security: {
60
+ title: "Security",
61
+ description: "Cookies used for security authenticate users, prevent fraud, and protect users as they interact with a service.",
62
+ },
63
+ },
64
+ },
65
+ categories: {
66
+ [catAnalytics]: {
67
+ services: {
68
+ [serviceAnalyticsStorage]: {
69
+ label: "Enables storage (such as cookies) related to analytics e.g. visit duration.",
70
+ },
71
+ },
72
+ },
73
+ [catAdvertisement]: {
74
+ enabled: true,
75
+ readOnly: false,
76
+ services: {
77
+ [serviceAdStorage]: {
78
+ label: "Enables storage (such as cookies) related to advertising.",
79
+ },
80
+ [serviceAdUserData]: {
81
+ label: "Sets consent for sending user data related to advertising to Google.",
82
+ },
83
+ [serviceAdPersonalization]: {
84
+ label: "Sets consent for personalized advertising.",
85
+ },
86
+ },
87
+ },
88
+ [catFunctionality]: {
89
+ enabled: true,
90
+ readOnly: false,
91
+ services: {
92
+ [serviceFunctionalityStorage]: {
93
+ label: "Enables storage that supports the functionality of the website or app e.g. language settings.",
94
+ },
95
+ [servicePersonalizationStorage]: {
96
+ label: "Enables storage related to personalization e.g. video recommendations.",
97
+ },
98
+ },
99
+ },
100
+ [catSecurity]: {
101
+ enabled: true,
102
+ readOnly: false,
103
+ services: {
104
+ [serviceSecurityStorage]: {
105
+ label: "Enables storage related to security such as authentication functionality, fraud prevention, and other user protection.",
106
+ },
107
+ },
108
+ },
109
+ },
110
+ },
111
+ pl: {
112
+ language: {
113
+ consentModal: {
114
+ title: "Używamy plików cookie",
115
+ description: "Ta strona internetowa wykorzystuje niezbędne pliki cookie w celu zapewnienia jej prawidłowego działania oraz pliki cookie śledzące w celu zrozumienia sposobu interakcji użytkowników z witryną. Te ostatnie będą ustawione tylko po wyrażeniu zgody.",
116
+ acceptAllBtn: "Zaakceptuj wszystkie",
117
+ acceptNecessaryBtn: "Odrzuć wszystkie",
118
+ showPreferencesBtn: "Zarządzaj indywidualnymi preferencjami",
119
+ },
120
+ preferencesModal: {
121
+ title: "Zarządzaj preferencjami plików cookie",
122
+ acceptAllBtn: "Zaakceptuj wszystkie",
123
+ acceptNecessaryBtn: "Odrzuć wszystkie",
124
+ savePreferencesBtn: "Zaakceptuj bieżący wybór",
125
+ closeIconLabel: "Zamknij okno",
126
+ baseSection: {
127
+ title: "Używanie plików cookie",
128
+ description: "Używamy plików cookie w celu zapewnienia podstawowej funkcjonalności strony internetowej oraz poprawy Twojego doświadczenia online.",
129
+ },
130
+ necessarySection: {
131
+ title: "Ściśle niezbędne pliki cookie",
132
+ description: "Te pliki cookie są niezbędne do prawidłowego funkcjonowania strony internetowej, na przykład do uwierzytelniania użytkowników.",
133
+ },
134
+ },
135
+ categoryPreferenceLabels: {
136
+ analytics: {
137
+ title: "Analityka",
138
+ description: "Pliki cookie używane do analityki pomagają zbierać dane, które umożliwiają usługom zrozumienie sposobu interakcji użytkowników z określoną usługą. Te informacje pozwalają usługom zarówno poprawić treść, jak i tworzyć lepsze funkcje, które poprawiają doświadczenie użytkownika.",
139
+ cookieTable: {
140
+ headers: { name: "Nazwa", domain: "Usługa", description: "Opis", expiration: "Wygaśnięcie" },
141
+ body: [
142
+ {
143
+ name: googleAnalyticsCookieName,
144
+ domain: "Google Analytics",
145
+ description: 'Plik cookie ustawiony przez <a href="https://business.safety.google/adscookies/">Google Analytics</a>',
146
+ expiration: "Wygasa po 12 dniach",
147
+ },
148
+ {
149
+ name: googleAnalyticsSessionCookieName,
150
+ domain: "Google Analytics",
151
+ description: 'Plik cookie ustawiony przez <a href="https://business.safety.google/adscookies/">Google Analytics</a>',
152
+ expiration: "Sesja",
153
+ },
154
+ ],
155
+ },
156
+ },
157
+ advertisement: {
158
+ title: "Reklama",
159
+ description: 'Google używa plików cookie do reklam, w tym do wyświetlania i renderowania reklam, personalizacji reklam (w zależności od Twoich ustawień reklam na <a href="https://g.co/adsettings">g.co/adsettings</a>), ograniczania liczby wyświetleń reklamy użytkownikowi, wyciszania reklam, które zdecydowałeś się przestać oglądać, oraz mierzenia skuteczności reklam.',
160
+ },
161
+ functionality: {
162
+ title: "Funkcjonalność",
163
+ description: "Pliki cookie używane do funkcjonalności umożliwiają użytkownikom interakcję z usługą lub stroną w celu uzyskania dostępu do funkcji, które są fundamentalne dla tej usługi. Do rzeczy uznawanych za fundamentalne dla usługi należą preferencje takie jak wybór języka przez użytkownika, optymalizacje produktu, które pomagają utrzymać i poprawić usługę, oraz utrzymywanie informacji dotyczących sesji użytkownika, takich jak zawartość koszyka zakupów.",
164
+ },
165
+ security: {
166
+ title: "Bezpieczeństwo",
167
+ description: "Pliki cookie używane do bezpieczeństwa uwierzytelniają użytkowników, zapobiegają oszustwom i chronią użytkowników podczas interakcji z usługą.",
168
+ },
169
+ },
170
+ },
171
+ categories: {
172
+ [catAnalytics]: {
173
+ services: {
174
+ [serviceAnalyticsStorage]: {
175
+ label: "Umożliwia przechowywanie (np. plików cookie) związane z analityką, np. czas trwania wizyty.",
176
+ },
177
+ },
178
+ },
179
+ [catAdvertisement]: {
180
+ enabled: true,
181
+ readOnly: false,
182
+ services: {
183
+ [serviceAdStorage]: {
184
+ label: "Umożliwia przechowywanie (np. plików cookie) związane z reklamą.",
185
+ },
186
+ [serviceAdUserData]: {
187
+ label: "Ustawia zgodę na wysyłanie danych użytkownika związanych z reklamą do Google.",
188
+ },
189
+ [serviceAdPersonalization]: {
190
+ label: "Ustawia zgodę na personalizację reklam.",
191
+ },
192
+ },
193
+ },
194
+ [catFunctionality]: {
195
+ enabled: true,
196
+ readOnly: false,
197
+ services: {
198
+ [serviceFunctionalityStorage]: {
199
+ label: "Umożliwia przechowywanie, które wspiera funkcjonalność strony internetowej lub aplikacji, np. ustawienia języka.",
200
+ },
201
+ [servicePersonalizationStorage]: {
202
+ label: "Umożliwia przechowywanie związane z personalizacją, np. rekomendacje wideo.",
203
+ },
204
+ },
205
+ },
206
+ [catSecurity]: {
207
+ enabled: true,
208
+ readOnly: false,
209
+ services: {
210
+ [serviceSecurityStorage]: {
211
+ label: "Umożliwia przechowywanie związane z bezpieczeństwem, takie jak funkcjonalność uwierzytelniania, zapobieganie oszustwom i inna ochrona użytkowników.",
212
+ },
213
+ },
214
+ },
215
+ },
216
+ },
217
+ };
218
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../../packages/cookie-consent/src/lib/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,uBAAuB,EACvB,2BAA2B,EAC3B,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,oBAAoB,CAAA;AAE3B,MAAM,yBAAyB,GAAG,KAAK,CAAA;AACvC,MAAM,gCAAgC,GAAG,MAAM,CAAA;AAE/C,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,EAAE,EAAE;QACF,QAAQ,EAAE;YACR,YAAY,EAAE;gBACZ,KAAK,EAAE,gBAAgB;gBACvB,WAAW,EACT,4K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AAC,EAAE;wBACnB,KAAK,EAAE,+EAA+E;qBACvF;oBACD,CAAC,wBAAwB,CAAC,EAAE;wBAC1B,KAAK,EAAE,yCAAyC;qBACjD;iBACF;aACF;YACD,CAAC,gBAAgB,CAAC,EAAE;gBAClB,OAAO,EAAE,IAAI;gBACb,QAAQ,EAAE,KAAK;gBACf,QAAQ,EAAE;oBACR,CAAC,2BAA2B,CAAC,EAAE;wBAC7B,KAAK,EACH,kHAAkH;qBACrH;oBACD,CAAC,6BAA6B,CAAC,EAAE;wBAC/B,KAAK,EAAE,6EAA6E;qBACrF;iBACF;aACF;YACD,CAAC,WAAW,CAAC,EAAE;gBACb,OAAO,EAAE,IAAI;gBACb,QAAQ,EAAE,KAAK;gBACf,QAAQ,EAAE;oBACR,CAAC,sBAAsB,CAAC,EAAE;wBACxB,KAAK,EACH,qJAAqJ;qBACxJ;iBACF;aACF;SACF;KACF;CACF,CAAA"}
@@ -0,0 +1,29 @@
1
+ import type { CookieConsentConfig } from "./runCookieConsent";
2
+ type Language = "en" | "pl";
3
+ export interface DefaultConsentOptions {
4
+ language: Language[];
5
+ advertisement?: boolean;
6
+ analytics?: boolean;
7
+ security?: boolean;
8
+ functionality?: boolean;
9
+ }
10
+ /**
11
+ * Creates a default cookie consent configuration with configurable languages and categories.
12
+ *
13
+ * @param options - Configuration options for languages and enabled categories
14
+ * @returns Complete cookie consent configuration ready for runCookieConsent
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const config = getDefaultConsentConfig({
19
+ * language: ["en", "pl"],
20
+ * advertisement: true,
21
+ * analytics: true,
22
+ * security: true
23
+ * })
24
+ *
25
+ * runCookieConsent(config)
26
+ * ```
27
+ */
28
+ export declare function getDefaultConsentConfig({ language, advertisement, analytics, security, functionality, }: DefaultConsentOptions): CookieConsentConfig;
29
+ export {};
@@ -0,0 +1,70 @@
1
+ import { config } from "./config";
2
+ import { catAdvertisement, catAnalytics, catFunctionality, catSecurity } from "./getGoogleConsent";
3
+ const categories = [catAnalytics, catAdvertisement, catFunctionality, catSecurity];
4
+ function buildPreferencesSections(langConfig, options) {
5
+ const sections = [
6
+ langConfig.language.preferencesModal.baseSection,
7
+ {
8
+ ...langConfig.language.preferencesModal.necessarySection,
9
+ linkedCategory: "necessary",
10
+ },
11
+ ];
12
+ for (const key of categories) {
13
+ if (options[key]) {
14
+ sections.push({
15
+ ...langConfig.language.categoryPreferenceLabels[key],
16
+ linkedCategory: key,
17
+ });
18
+ }
19
+ }
20
+ return sections;
21
+ }
22
+ const fallbackLanguage = "en";
23
+ /**
24
+ * Creates a default cookie consent configuration with configurable languages and categories.
25
+ *
26
+ * @param options - Configuration options for languages and enabled categories
27
+ * @returns Complete cookie consent configuration ready for runCookieConsent
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const config = getDefaultConsentConfig({
32
+ * language: ["en", "pl"],
33
+ * advertisement: true,
34
+ * analytics: true,
35
+ * security: true
36
+ * })
37
+ *
38
+ * runCookieConsent(config)
39
+ * ```
40
+ */
41
+ export function getDefaultConsentConfig({ language = [fallbackLanguage], advertisement = false, analytics = false, security = false, functionality = false, }) {
42
+ const categoryOptions = { analytics, advertisement, functionality, security };
43
+ const defaultLanguage = language.at(0) ?? fallbackLanguage;
44
+ const defaultLanguageConfig = config[defaultLanguage];
45
+ const supportedCategories = {};
46
+ for (const key of categories) {
47
+ if (categoryOptions[key]) {
48
+ supportedCategories[key] = defaultLanguageConfig.categories[key];
49
+ }
50
+ }
51
+ const languageTranslations = {};
52
+ for (const lang of language) {
53
+ const langConfig = config[lang];
54
+ languageTranslations[lang] = {
55
+ consentModal: langConfig.language.consentModal,
56
+ preferencesModal: {
57
+ ...langConfig.language.preferencesModal,
58
+ sections: buildPreferencesSections(langConfig, categoryOptions),
59
+ },
60
+ };
61
+ }
62
+ return {
63
+ categories: supportedCategories,
64
+ language: {
65
+ default: defaultLanguage,
66
+ translations: languageTranslations,
67
+ },
68
+ };
69
+ }
70
+ //# sourceMappingURL=getDefaultConsentConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDefaultConsentConfig.js","sourceRoot":"","sources":["../../../../../packages/cookie-consent/src/lib/getDefaultConsentConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAYlG,MAAM,UAAU,GAAG,CAAC,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,CAAU,CAAA;AAE3F,SAAS,wBAAwB,CAC/B,UAAqC,EACrC,OAAsG;IAEtG,MAAM,QAAQ,GAAG;QACf,UAAU,CAAC,QAAQ,CAAC,gBAAgB,CAAC,WAAW;QAChD;YACE,GAAG,UAAU,CAAC,QAAQ,CAAC,gBAAgB,CAAC,gBAAgB;YACxD,cAAc,EAAE,WAAW;SAC5B;KACF,CAAA;IAED,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAC7B,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YACjB,QAAQ,CAAC,IAAI,CAAC;gBACZ,GAAG,UAAU,CAAC,QAAQ,CAAC,wBAAwB,CAAC,GAAG,CAAC;gBACpD,cAAc,EAAE,GAAG;aACpB,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,MAAM,gBAAgB,GAAa,IAAI,CAAA;AACvC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,uBAAuB,CAAC,EACtC,QAAQ,GAAG,CAAC,gBAAgB,CAAC,EAC7B,aAAa,GAAG,KAAK,EACrB,SAAS,GAAG,KAAK,EACjB,QAAQ,GAAG,KAAK,EAChB,aAAa,GAAG,KAAK,GACC;IACtB,MAAM,eAAe,GAAG,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAA;IAE7E,MAAM,eAAe,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAA;IAC1D,MAAM,qBAAqB,GAAG,MAAM,CAAC,eAAe,CAAC,CAAA;IAErD,MAAM,mBAAmB,GAAsC,EAAE,CAAA;IACjE,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;QAC7B,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,mBAAmB,CAAC,GAAG,CAAC,GAAG,qBAAqB,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;QAClE,CAAC;IACH,CAAC;IAED,MAAM,oBAAoB,GAAgC,EAAE,CAAA;IAE5D,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC5B,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;QAE/B,oBAAoB,CAAC,IAAI,CAAC,GAAG;YAC3B,YAAY,EAAE,UAAU,CAAC,QAAQ,CAAC,YAAY;YAC9C,gBAAgB,EAAE;gBAChB,GAAG,UAAU,CAAC,QAAQ,CAAC,gBAAgB;gBACvC,QAAQ,EAAE,wBAAwB,CAAC,UAAU,EAAE,eAAe,CAAC;aAChE;SACF,CAAA;IACH,CAAC;IAED,OAAO;QACL,UAAU,EAAE,mBAAmB;QAC/B,QAAQ,EAAE;YACR,OAAO,EAAE,eAAe;YACxB,YAAY,EAAE,oBAAoB;SACnC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,20 @@
1
+ export declare const catNecessary = "necessary";
2
+ export declare const catAnalytics = "analytics";
3
+ export declare const catAdvertisement = "advertisement";
4
+ export declare const catFunctionality = "functionality";
5
+ export declare const catSecurity = "security";
6
+ export declare const serviceAdStorage = "ad_storage";
7
+ export declare const serviceAdUserData = "ad_user_data";
8
+ export declare const serviceAdPersonalization = "ad_personalization";
9
+ export declare const serviceAnalyticsStorage = "analytics_storage";
10
+ export declare const serviceFunctionalityStorage = "functionality_storage";
11
+ export declare const servicePersonalizationStorage = "personalization_storage";
12
+ export declare const serviceSecurityStorage = "security_storage";
13
+ export type ServiceKey = typeof serviceAdPersonalization | typeof serviceAdStorage | typeof serviceAdUserData | typeof serviceAnalyticsStorage | typeof serviceFunctionalityStorage | typeof servicePersonalizationStorage | typeof serviceSecurityStorage;
14
+ export type CategoryKey = typeof catAdvertisement | typeof catAnalytics | typeof catFunctionality | typeof catNecessary | typeof catSecurity;
15
+ export declare const serviceKeyCategoriesMap: Record<ServiceKey, CategoryKey>;
16
+ export declare function getGoogleConsent(): {
17
+ setDefaultConsent: (serviceKeys: ServiceKey[]) => void;
18
+ updateConsent: (serviceKeys: ServiceKey[]) => void;
19
+ };
20
+ export declare function getServiceValue(serviceName: ServiceKey, categoryName: CategoryKey): "denied" | "granted";
@@ -0,0 +1,43 @@
1
+ import * as CookieConsent from "vanilla-cookieconsent";
2
+ import { mkgtag } from "@leancodepl/gtag";
3
+ export const catNecessary = "necessary";
4
+ export const catAnalytics = "analytics";
5
+ export const catAdvertisement = "advertisement";
6
+ export const catFunctionality = "functionality";
7
+ export const catSecurity = "security";
8
+ export const serviceAdStorage = "ad_storage";
9
+ export const serviceAdUserData = "ad_user_data";
10
+ export const serviceAdPersonalization = "ad_personalization";
11
+ export const serviceAnalyticsStorage = "analytics_storage";
12
+ export const serviceFunctionalityStorage = "functionality_storage";
13
+ export const servicePersonalizationStorage = "personalization_storage";
14
+ export const serviceSecurityStorage = "security_storage";
15
+ export const serviceKeyCategoriesMap = {
16
+ [serviceAdStorage]: catAdvertisement,
17
+ [serviceAnalyticsStorage]: catAnalytics,
18
+ [serviceFunctionalityStorage]: catFunctionality,
19
+ [servicePersonalizationStorage]: catFunctionality,
20
+ [serviceSecurityStorage]: catSecurity,
21
+ [serviceAdUserData]: catAdvertisement,
22
+ [serviceAdPersonalization]: catAdvertisement,
23
+ };
24
+ export function getGoogleConsent() {
25
+ const gtag = mkgtag();
26
+ function setDefaultConsent(serviceKeys) {
27
+ gtag({
28
+ event: "default_cookie_consent",
29
+ settings: Object.fromEntries(serviceKeys.map(serviceName => [serviceName, "denied"])),
30
+ });
31
+ }
32
+ function updateConsent(serviceKeys) {
33
+ gtag({
34
+ event: "cookie_consent_update",
35
+ settings: Object.fromEntries(serviceKeys.map(serviceKey => [serviceKey, getServiceValue(serviceKey, serviceKeyCategoriesMap[serviceKey])])),
36
+ });
37
+ }
38
+ return { setDefaultConsent, updateConsent };
39
+ }
40
+ export function getServiceValue(serviceName, categoryName) {
41
+ return CookieConsent.acceptedService(serviceName, categoryName) ? "granted" : "denied";
42
+ }
43
+ //# sourceMappingURL=getGoogleConsent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getGoogleConsent.js","sourceRoot":"","sources":["../../../../../packages/cookie-consent/src/lib/getGoogleConsent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAA;AACvC,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAA;AACvC,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAA;AAC/C,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAA;AAC/C,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAA;AAErC,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAA;AAC5C,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAA;AAC/C,MAAM,CAAC,MAAM,wBAAwB,GAAG,oBAAoB,CAAA;AAC5D,MAAM,CAAC,MAAM,uBAAuB,GAAG,mBAAmB,CAAA;AAC1D,MAAM,CAAC,MAAM,2BAA2B,GAAG,uBAAuB,CAAA;AAClE,MAAM,CAAC,MAAM,6BAA6B,GAAG,yBAAyB,CAAA;AACtE,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAA;AAqBxD,MAAM,CAAC,MAAM,uBAAuB,G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yCategoriesMap } from "./getGoogleConsent";
3
+ type ServiceKeysByCategory<C extends CategoryKey> = Extract<{
4
+ [K in keyof typeof serviceKeyCategoriesMap]: (typeof serviceKeyCategoriesMap)[K] extends C ? K : never;
5
+ }[keyof typeof serviceKeyCategoriesMap], ServiceKey>;
6
+ type CategoryWithServices<C extends CategoryKey> = Omit<CookieConsent.Category, "services"> & {
7
+ services?: Partial<Record<ServiceKeysByCategory<C>, CookieConsent.Service>>;
8
+ };
9
+ type Categories = Partial<{
10
+ [K in CategoryKey]: CategoryWithServices<K>;
11
+ }>;
12
+ export type CookieConsentConfig = Omit<CookieConsent.CookieConsentConfig, "categories"> & {
13
+ categories: Categories;
14
+ };
15
+ /**
16
+ * Runs cookie consent and synchronizes consent state with Google via `"@leancodepl/gtag"`.
17
+ *
18
+ * This function derives supported Google consent services from the provided `categories.services`
19
+ * and automatically calls Google consent APIs on first consent, consent, and change events while
20
+ * preserving any user-provided handlers.
21
+ *
22
+ * @param config - Cookie consent configuration that mirrors `vanilla-cookieconsent` options, with a strongly-typed
23
+ * `categories` shape. All non-`categories` fields pass through to `vanilla-cookieconsent` unchanged.
24
+ * For complete configuration details, see the vanilla-cookieconsent documentation: https://cookieconsent.orestbida.com/
25
+ * @returns The `vanilla-cookieconsent` module instance after initialization
26
+ * @example
27
+ * ```typescript
28
+ runCookieConsent({
29
+ categories: {
30
+ analytics: {
31
+ services: {
32
+ analytics_storage: {
33
+ label:
34
+ 'Enables storage (such as cookies) related to analytics e.g. visit duration.'
35
+ }
36
+ }
37
+ }
38
+ },
39
+ guiOptions: {
40
+ consentModal: {
41
+ layout: 'box wide',
42
+ position: 'bottom right'
43
+ },
44
+ preferencesModal: {
45
+ layout: 'box'
46
+ }
47
+ },
48
+ language: {
49
+ default: 'en',
50
+ translations: {
51
+ en: {
52
+ consentModal: {
53
+ title: 'We use cookies',
54
+ description:
55
+ 'This website uses essential cookies to ensure its proper operation and tracking cookies to understand how you interact with it. The latter will be set only after consent.',
56
+ acceptAllBtn: 'Accept all',
57
+ acceptNecessaryBtn: 'Reject all',
58
+ showPreferencesBtn: 'Manage Individual preferences'
59
+ },
60
+ preferencesModal: {
61
+ title: 'Manage cookie preferences',
62
+ acceptAllBtn: 'Accept all',
63
+ acceptNecessaryBtn: 'Reject all',
64
+ savePreferencesBtn: 'Accept current selection',
65
+ closeIconLabel: 'Close modal',
66
+ sections: [
67
+ {
68
+ title: 'Cookie usage',
69
+ description:
70
+ 'We use cookies to ensure the basic functionalities of the website and to enhance your online experience.'
71
+ },
72
+ {
73
+ title: 'Strictly necessary cookies',
74
+ description:
75
+ 'These cookies are essential for the proper functioning of the website, for example for user authentication.',
76
+ linkedCategory: 'necessary'
77
+ },
78
+ {
79
+ title: 'Analytics',
80
+ description:
81
+ 'Cookies used for analytics help collect data that allows services to understand how users interact with a particular service. These insights allow services both to improve content and to build better features that improve the user’s experience.',
82
+ linkedCategory: 'analytics',
83
+ cookieTable: {
84
+ headers: {
85
+ name: 'Name',
86
+ domain: 'Service',
87
+ description: 'Description',
88
+ expiration: 'Expiration'
89
+ },
90
+ body: [
91
+ {
92
+ name: '_ga',
93
+ domain: 'Google Analytics',
94
+ description:
95
+ 'Cookie set by <a href="https://business.safety.google/adscookies/">Google Analytics</a>',
96
+ expiration: 'Expires after 12 days'
97
+ },
98
+ {
99
+ name: '_gid',
100
+ domain: 'Google Analytics',
101
+ description:
102
+ 'Cookie set by <a href="https://business.safety.google/adscookies/">Google Analytics</a>',
103
+ expiration: 'Session'
104
+ }
105
+ ]
106
+ }
107
+ },
108
+ {
109
+ title: 'Advertising',
110
+ description:
111
+ 'Google uses cookies for advertising, including serving and rendering ads, personalizing ads (depending on your ad settings at <a href=\"https://g.co/adsettings\">g.co/adsettings</a>), limiting the number of times an ad is shown to a user, muting ads you have chosen to stop seeing, and measuring the effectiveness of ads.',
112
+ linkedCategory: 'advertising'
113
+ },
114
+ {
115
+ title: 'Functionality',
116
+ description:
117
+ 'Cookies used for functionality allow users to interact with a service or site to access features that are fundamental to that service. Things considered fundamental to the service include preferences like the user’s choice of language, product optimizations that help maintain and improve a service, and maintaining information relating to a user’s session, such as the content of a shopping cart.',
118
+ linkedCategory: 'functionality'
119
+ },
120
+ {
121
+ title: 'Security',
122
+ description:
123
+ 'Cookies used for security authenticate users, prevent fraud, and protect users as they interact with a service.',
124
+ linkedCategory: 'security'
125
+ },
126
+ {
127
+ title: 'More information',
128
+ description:
129
+ 'For any queries in relation to the policy on cookies and your choices, please <a href="https://www.example.com/contacts">contact us</a>.'
130
+ }
131
+ ]
132
+ }
133
+ }
134
+ }
135
+ }
136
+ })
137
+ * ```
138
+ */
139
+ export declare function runCookieConsent(config: CookieConsentConfig): Promise<typeof CookieConsent>;
140
+ export {};
@@ -0,0 +1,169 @@
1
+ import * as CookieConsent from "vanilla-cookieconsent";
2
+ import { catAnalytics, catNecessary, getGoogleConsent, } from "./getGoogleConsent";
3
+ function getCookieConsentConfig(config) {
4
+ const { categories, onFirstConsent, onChange, onConsent, ...rest } = config;
5
+ const supportedServices = Object.values(categories).flatMap(category => Object.keys(category.services ?? {}));
6
+ const { setDefaultConsent, updateConsent } = getGoogleConsent();
7
+ setDefaultConsent(supportedServices);
8
+ const cookieConsentConfig = {
9
+ onFirstConsent: params => {
10
+ updateConsent(supportedServices);
11
+ onFirstConsent?.(params);
12
+ },
13
+ onConsent: params => {
14
+ updateConsent(supportedServices);
15
+ onConsent?.(params);
16
+ },
17
+ onChange: params => {
18
+ updateConsent(supportedServices);
19
+ onChange?.(params);
20
+ },
21
+ categories: {
22
+ [catNecessary]: {
23
+ enabled: true,
24
+ readOnly: true,
25
+ ...(categories[catNecessary] ?? {}),
26
+ },
27
+ [catAnalytics]: {
28
+ autoClear: {
29
+ cookies: [{ name: /^_ga/ }, { name: "_gid" }],
30
+ },
31
+ ...(categories[catAnalytics] ?? {}),
32
+ },
33
+ ...categories,
34
+ },
35
+ ...rest,
36
+ };
37
+ return cookieConsentConfig;
38
+ }
39
+ /**
40
+ * Runs cookie consent and synchronizes consent state with Google via `"@leancodepl/gtag"`.
41
+ *
42
+ * This function derives supported Google consent services from the provided `categories.services`
43
+ * and automatically calls Google consent APIs on first consent, consent, and change events while
44
+ * preserving any user-provided handlers.
45
+ *
46
+ * @param config - Cookie consent configuration that mirrors `vanilla-cookieconsent` options, with a strongly-typed
47
+ * `categories` shape. All non-`categories` fields pass through to `vanilla-cookieconsent` unchanged.
48
+ * For complete configuration details, see the vanilla-cookieconsent documentation: https://cookieconsent.orestbida.com/
49
+ * @returns The `vanilla-cookieconsent` module instance after initialization
50
+ * @example
51
+ * ```typescript
52
+ runCookieConsent({
53
+ categories: {
54
+ analytics: {
55
+ services: {
56
+ analytics_storage: {
57
+ label:
58
+ 'Enables storage (such as cookies) related to analytics e.g. visit duration.'
59
+ }
60
+ }
61
+ }
62
+ },
63
+ guiOptions: {
64
+ consentModal: {
65
+ layout: 'box wide',
66
+ position: 'bottom right'
67
+ },
68
+ preferencesModal: {
69
+ layout: 'box'
70
+ }
71
+ },
72
+ language: {
73
+ default: 'en',
74
+ translations: {
75
+ en: {
76
+ consentModal: {
77
+ title: 'We use cookies',
78
+ description:
79
+ 'This website uses essential cookies to ensure its proper operation and tracking cookies to understand how you interact with it. The latter will be set only after consent.',
80
+ acceptAllBtn: 'Accept all',
81
+ acceptNecessaryBtn: 'Reject all',
82
+ showPreferencesBtn: 'Manage Individual preferences'
83
+ },
84
+ preferencesModal: {
85
+ title: 'Manage cookie preferences',
86
+ acceptAllBtn: 'Accept all',
87
+ acceptNecessaryBtn: 'Reject all',
88
+ savePreferencesBtn: 'Accept current selection',
89
+ closeIconLabel: 'Close modal',
90
+ sections: [
91
+ {
92
+ title: 'Cookie usage',
93
+ description:
94
+ 'We use cookies to ensure the basic functionalities of the website and to enhance your online experience.'
95
+ },
96
+ {
97
+ title: 'Strictly necessary cookies',
98
+ description:
99
+ 'These cookies are essential for the proper functioning of the website, for example for user authentication.',
100
+ linkedCategory: 'necessary'
101
+ },
102
+ {
103
+ title: 'Analytics',
104
+ description:
105
+ 'Cookies used for analytics help collect data that allows services to understand how users interact with a particular service. These insights allow services both to improve content and to build better features that improve the user’s experience.',
106
+ linkedCategory: 'analytics',
107
+ cookieTable: {
108
+ headers: {
109
+ name: 'Name',
110
+ domain: 'Service',
111
+ description: 'Description',
112
+ expiration: 'Expiration'
113
+ },
114
+ body: [
115
+ {
116
+ name: '_ga',
117
+ domain: 'Google Analytics',
118
+ description:
119
+ 'Cookie set by <a href="https://business.safety.google/adscookies/">Google Analytics</a>',
120
+ expiration: 'Expires after 12 days'
121
+ },
122
+ {
123
+ name: '_gid',
124
+ domain: 'Google Analytics',
125
+ description:
126
+ 'Cookie set by <a href="https://business.safety.google/adscookies/">Google Analytics</a>',
127
+ expiration: 'Session'
128
+ }
129
+ ]
130
+ }
131
+ },
132
+ {
133
+ title: 'Advertising',
134
+ description:
135
+ 'Google uses cookies for advertising, including serving and rendering ads, personalizing ads (depending on your ad settings at <a href=\"https://g.co/adsettings\">g.co/adsettings</a>), limiting the number of times an ad is shown to a user, muting ads you have chosen to stop seeing, and measuring the effectiveness of ads.',
136
+ linkedCategory: 'advertising'
137
+ },
138
+ {
139
+ title: 'Functionality',
140
+ description:
141
+ 'Cookies used for functionality allow users to interact with a service or site to access features that are fundamental to that service. Things considered fundamental to the service include preferences like the user’s choice of language, product optimizations that help maintain and improve a service, and maintaining information relating to a user’s session, such as the content of a shopping cart.',
142
+ linkedCategory: 'functionality'
143
+ },
144
+ {
145
+ title: 'Security',
146
+ description:
147
+ 'Cookies used for security authenticate users, prevent fraud, and protect users as they interact with a service.',
148
+ linkedCategory: 'security'
149
+ },
150
+ {
151
+ title: 'More information',
152
+ description:
153
+ 'For any queries in relation to the policy on cookies and your choices, please <a href="https://www.example.com/contacts">contact us</a>.'
154
+ }
155
+ ]
156
+ }
157
+ }
158
+ }
159
+ }
160
+ })
161
+ * ```
162
+ */
163
+ export async function runCookieConsent(config) {
164
+ const cookieConsent = CookieConsent;
165
+ const cookieConsentConfig = getCookieConsentConfig(config);
166
+ await cookieConsent.run(cookieConsentConfig);
167
+ return cookieConsent;
168
+ }
169
+ //# sourceMappingURL=runCookieConsent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runCookieConsent.js","sourceRoot":"","sources":["../../../../../packages/cookie-consent/src/lib/runCookieConsent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,uBAAuB,CAAA;AACtD,OAAO,EACL,YAAY,EAEZ,YAAY,EACZ,gBAAgB,GAGjB,MAAM,oBAAoB,CAAA;AAqB3B,SAAS,sBAAsB,CAAC,MAA2B;IACzD,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAA;IAC3E,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CACrE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,IAAI,EAAE,CAAC,CACrB,CAAA;IAEjB,MAAM,EAAE,iBAAiB,EAAE,aAAa,EAAE,GAAG,gBAAgB,EAAE,CAAA;IAC/D,iBAAiB,CAAC,iBAAiB,CAAC,CAAA;IAEpC,MAAM,mBAAmB,GAAsC;QAC7D,cAAc,EAAE,MAAM,CAAC,EAAE;YACvB,aAAa,CAAC,iBAAiB,CAAC,CAAA;YAChC,cAAc,EAAE,CAAC,MAAM,CAAC,CAAA;QAC1B,CAAC;QACD,SAAS,EAAE,MAAM,CAAC,EAAE;YAClB,aAAa,CAAC,iBAAiB,CAAC,CAAA;YAChC,SAAS,EAAE,CAAC,MAAM,CAAC,CAAA;QACrB,CAAC;QACD,QAAQ,EAAE,MAAM,CAAC,EAAE;YACjB,aAAa,CAAC,iBAAiB,CAAC,CAAA;YAChC,QAAQ,EAAE,CAAC,MAAM,CAAC,CAAA;QACpB,CAAC;QACD,UAAU,EAAE;YACV,CAAC,YAAY,CA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