@smartgenie/cookie-consent 0.0.0-stage → 1.0.0
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/LICENSE +73 -0
- package/README.md +292 -2
- package/dist/blocking/attribute-blocker.d.ts +18 -0
- package/dist/blocking/gtm-consent-mode.d.ts +19 -0
- package/dist/blocking/uet-consent.d.ts +9 -0
- package/dist/capsules/banner-experiment.d.ts +2 -0
- package/dist/capsules/banner-experiment.js +1 -0
- package/dist/capsules/country-banners.d.ts +2 -0
- package/dist/capsules/country-banners.js +1 -0
- package/dist/capsules/loader.d.ts +8 -0
- package/dist/capsules/subdomain-consent.d.ts +5 -0
- package/dist/capsules/subdomain-consent.js +1 -0
- package/dist/config/schema.d.ts +19 -0
- package/dist/config/validator.d.ts +8 -0
- package/dist/core/consent-log.d.ts +14 -0
- package/dist/core/consent-manager.d.ts +13 -0
- package/dist/core/consent-stats.d.ts +13 -0
- package/dist/core/events.d.ts +5 -0
- package/dist/core/gpc.d.ts +5 -0
- package/dist/core/storage.d.ts +9 -0
- package/dist/geo/detector.d.ts +3 -0
- package/dist/i18n/langs/ar.d.ts +1 -0
- package/dist/i18n/langs/cs.d.ts +1 -0
- package/dist/i18n/langs/da.d.ts +1 -0
- package/dist/i18n/langs/de.d.ts +1 -0
- package/dist/i18n/langs/es.d.ts +1 -0
- package/dist/i18n/langs/fr.d.ts +1 -0
- package/dist/i18n/langs/hi.d.ts +1 -0
- package/dist/i18n/langs/it.d.ts +1 -0
- package/dist/i18n/langs/ja.d.ts +1 -0
- package/dist/i18n/langs/ko.d.ts +1 -0
- package/dist/i18n/langs/nl.d.ts +1 -0
- package/dist/i18n/langs/no.d.ts +1 -0
- package/dist/i18n/langs/pl.d.ts +1 -0
- package/dist/i18n/langs/pt.d.ts +1 -0
- package/dist/i18n/langs/ro.d.ts +1 -0
- package/dist/i18n/langs/ru.d.ts +1 -0
- package/dist/i18n/langs/sv.d.ts +1 -0
- package/dist/i18n/langs/tr.d.ts +1 -0
- package/dist/i18n/langs/zh.d.ts +1 -0
- package/dist/i18n/loader.d.ts +11 -0
- package/dist/i18n/remote.d.ts +23 -0
- package/dist/i18n/translations.d.ts +14 -0
- package/dist/index.d.ts +10 -0
- package/dist/lang/ar.json +1 -0
- package/dist/lang/cs.json +1 -0
- package/dist/lang/da.json +1 -0
- package/dist/lang/de.json +1 -0
- package/dist/lang/es.json +1 -0
- package/dist/lang/fr.json +1 -0
- package/dist/lang/hi.json +1 -0
- package/dist/lang/it.json +1 -0
- package/dist/lang/ja.json +1 -0
- package/dist/lang/ko.json +1 -0
- package/dist/lang/nl.json +1 -0
- package/dist/lang/no.json +1 -0
- package/dist/lang/pl.json +1 -0
- package/dist/lang/pt.json +1 -0
- package/dist/lang/ro.json +1 -0
- package/dist/lang/ru.json +1 -0
- package/dist/lang/sv.json +1 -0
- package/dist/lang/tr.json +1 -0
- package/dist/lang/zh.json +1 -0
- package/dist/react/SmartConsent.d.ts +14 -0
- package/dist/react/SmartConsent.js +2260 -0
- package/dist/react/SmartConsent.js.map +1 -0
- package/dist/regulations/loader.d.ts +3 -0
- package/dist/regulations/reasoner.d.ts +6 -0
- package/dist/regulations/schema.d.ts +8 -0
- package/dist/site/consent-records.d.ts +26 -0
- package/dist/site/settings.d.ts +48 -0
- package/dist/smartconsent.es.js +3063 -0
- package/dist/smartconsent.es.js.map +1 -0
- package/dist/smartconsent.js +3962 -0
- package/dist/smartconsent.js.map +1 -0
- package/dist/smartconsent.min.js +534 -0
- package/dist/smartconsent.min.js.map +1 -0
- package/dist/types.d.ts +377 -0
- package/dist/ui/a11y.d.ts +4 -0
- package/dist/ui/attribution-guard.d.ts +3 -0
- package/dist/ui/badge.d.ts +7 -0
- package/dist/ui/banner.d.ts +10 -0
- package/dist/ui/cookie-policy.d.ts +8 -0
- package/dist/ui/cookie-table.d.ts +7 -0
- package/dist/ui/credit.d.ts +15 -0
- package/dist/ui/embed-placeholder.d.ts +7 -0
- package/dist/ui/opt-out-notice.d.ts +7 -0
- package/dist/ui/styles.d.ts +3 -0
- package/dist/webhook.d.ts +5 -0
- package/package.json +100 -4
- package/templates/privacy-policy-template.md +135 -0
- package/templates/vanilla.html +116 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
Licensor: SmartGenie Ltd
|
|
4
|
+
Licensed Work: SmartConsent
|
|
5
|
+
The Licensed Work is (c) 2026 SmartGenie Ltd.
|
|
6
|
+
|
|
7
|
+
Additional Use Grant:
|
|
8
|
+
You may make use of the Licensed Work, provided that you do not use the
|
|
9
|
+
Licensed Work for a Cookie Consent Management Service.
|
|
10
|
+
|
|
11
|
+
A "Cookie Consent Management Service" is a commercial service offered to
|
|
12
|
+
third parties which provides cookie consent management functionality
|
|
13
|
+
substantially similar to the Licensed Work.
|
|
14
|
+
|
|
15
|
+
Change Date: Four years from the date the Licensed Work is published.
|
|
16
|
+
|
|
17
|
+
Change License: Apache License, Version 2.0
|
|
18
|
+
|
|
19
|
+
For information about alternative licensing arrangements for the Licensed Work,
|
|
20
|
+
please contact: hello@smartgenie.co.uk
|
|
21
|
+
|
|
22
|
+
Notice
|
|
23
|
+
|
|
24
|
+
Business Source License 1.1 (BSL 1.1) is not an Open Source license. However,
|
|
25
|
+
the Licensed Work will eventually be made available under an Open Source
|
|
26
|
+
License, as stated in this License.
|
|
27
|
+
|
|
28
|
+
The text of the BSL 1.1 is available at:
|
|
29
|
+
https://mariadb.com/bsl11/
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
Terms
|
|
34
|
+
|
|
35
|
+
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
36
|
+
works, redistribute, and make non-production use of the Licensed Work. The
|
|
37
|
+
Licensor may make an Additional Use Grant, above, permitting limited
|
|
38
|
+
production use.
|
|
39
|
+
|
|
40
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly
|
|
41
|
+
available distribution of a specific version of the Licensed Work under this
|
|
42
|
+
License, whichever comes first, the Licensor hereby grants you rights under
|
|
43
|
+
the terms of the Change License, and the rights granted in the paragraph
|
|
44
|
+
above terminate.
|
|
45
|
+
|
|
46
|
+
If your use of the Licensed Work does not comply with the requirements
|
|
47
|
+
currently in effect as described in this License, you must purchase a
|
|
48
|
+
commercial license from the Licensor, its affiliated entities, or authorized
|
|
49
|
+
resellers, or you must refrain from using the Licensed Work.
|
|
50
|
+
|
|
51
|
+
All copies of the original and modified Licensed Work, and derivative works
|
|
52
|
+
of the Licensed Work, are subject to this License. This License applies
|
|
53
|
+
separately for each version of the Licensed Work and the Change Date may vary
|
|
54
|
+
for each version of the Licensed Work released by Licensor.
|
|
55
|
+
|
|
56
|
+
You must conspicuously display this License on each original or modified copy
|
|
57
|
+
of the Licensed Work. If you receive the Licensed Work in original or
|
|
58
|
+
modified form from a third party, the terms and conditions set forth in this
|
|
59
|
+
License apply to your use of that work.
|
|
60
|
+
|
|
61
|
+
Any use of the Licensed Work in violation of this License will automatically
|
|
62
|
+
terminate your rights under this License for the current and all other
|
|
63
|
+
versions of the Licensed Work.
|
|
64
|
+
|
|
65
|
+
This License does not grant you any right in any trademark or logo of
|
|
66
|
+
Licensor or its affiliates (provided that you may use a trademark or logo of
|
|
67
|
+
Licensor as expressly required by this License).
|
|
68
|
+
|
|
69
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
|
|
70
|
+
AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
|
|
71
|
+
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
|
|
72
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
|
|
73
|
+
TITLE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,293 @@
|
|
|
1
|
-
#
|
|
1
|
+
# SmartConsent
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Cookie consent with built-in regulatory rules.**
|
|
4
|
+
|
|
5
|
+
SmartConsent shows every visitor the same ask-first cookie banner, holds back the scripts you mark until the visitor agrees, and sends Google Consent Mode v2 and Microsoft UET consent signals. A visitor whose browser sends Global Privacy Control or Do Not Track gets optional cookies rejected without a banner, in every region. It estimates the visitor's region from the device's time zone, with no network call; today that region decides only which rules the consent log names (see [Regulation rules](#regulation-rules)). Banners per region are planned for Pro. Zero runtime dependencies. Under 25 KB gzipped.
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<script>window.SmartConsentConfig = { version: 1 };</script>
|
|
11
|
+
<script src="smartconsent.min.js"></script>
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
That's it. SmartConsent shows its ask-first banner and holds back the scripts you mark (see [Script Blocking](#script-blocking)) until the visitor chooses. Installing it does not make a site compliant by itself: what the site does with consent matters.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
### npm (React / Next.js)
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @smartgenie/cookie-consent
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { SmartConsent } from '@smartgenie/cookie-consent/react';
|
|
26
|
+
|
|
27
|
+
export default function App() {
|
|
28
|
+
return (
|
|
29
|
+
<>
|
|
30
|
+
<SmartConsent version={1} />
|
|
31
|
+
{/* your app */}
|
|
32
|
+
</>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Next.js App Router: the component uses React hooks, so render it from a file that starts with `'use client';`
|
|
38
|
+
(for example a small `ConsentBanner.tsx` wrapper you place in your root layout).
|
|
39
|
+
|
|
40
|
+
### npm (Vanilla JS / Bundler)
|
|
41
|
+
|
|
42
|
+
The package runs in the browser only (it reads and sets `window` when imported). Set the config in a module
|
|
43
|
+
that is imported first, then import SmartConsent:
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
// consent-config.js
|
|
47
|
+
window.SmartConsentConfig = { version: 1 };
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
// main.js
|
|
52
|
+
import './consent-config.js';
|
|
53
|
+
import smartConsent from '@smartgenie/cookie-consent';
|
|
54
|
+
|
|
55
|
+
const api = await smartConsent; // resolves once geo-detection and setup finish
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The default export is a promise of the API; `window.SmartConsent` holds the same API once it resolves.
|
|
59
|
+
TypeScript types (`SmartConsentConfig`, `SmartConsentAPI`, …) are exported from `@smartgenie/cookie-consent`.
|
|
60
|
+
|
|
61
|
+
### Self-Hosted
|
|
62
|
+
|
|
63
|
+
Copy `node_modules/@smartgenie/cookie-consent/dist/smartconsent.min.js` (or download it from the CDN below) and
|
|
64
|
+
host it on your server:
|
|
65
|
+
|
|
66
|
+
```html
|
|
67
|
+
<script>window.SmartConsentConfig = { version: 1 };</script>
|
|
68
|
+
<script src="/js/smartconsent.min.js"></script>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### CDN with SRI
|
|
72
|
+
|
|
73
|
+
```html
|
|
74
|
+
<script>window.SmartConsentConfig = { version: 1 };</script>
|
|
75
|
+
<script src="https://cdn.smartgenie.co.uk/v1/smartconsent.min.js"
|
|
76
|
+
integrity="sha384-..."
|
|
77
|
+
crossorigin="anonymous"></script>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Generate the hash from the file you serve, then put `sha384-<hash>` in `integrity`:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
curl -s https://cdn.smartgenie.co.uk/v1/smartconsent.min.js | openssl dgst -sha384 -binary | openssl base64 -A
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The `/v1/` file is updated in place, and any update breaks a pinned hash (the browser then refuses to run
|
|
87
|
+
the script). SRI therefore suits a self-hosted copy best.
|
|
88
|
+
|
|
89
|
+
### CDN (Simple)
|
|
90
|
+
|
|
91
|
+
```html
|
|
92
|
+
<script>window.SmartConsentConfig = { version: 1 };</script>
|
|
93
|
+
<script src="https://cdn.smartgenie.co.uk/v1/smartconsent.min.js"></script>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Configuration
|
|
97
|
+
|
|
98
|
+
All settings are optional. Set `version` (it defaults to 1) and raise it when your cookie policy changes:
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
window.SmartConsentConfig = {
|
|
102
|
+
// Increment when you change your cookie policy (defaults to 1)
|
|
103
|
+
version: 1,
|
|
104
|
+
|
|
105
|
+
// Theme (CSS custom property overrides)
|
|
106
|
+
theme: {
|
|
107
|
+
bg: '#0a0f1a', // Banner background
|
|
108
|
+
text: '#e2e8f0', // Primary text
|
|
109
|
+
accent: '#3b82f6', // Links, active toggle
|
|
110
|
+
accept: '#10b981', // Accept button
|
|
111
|
+
reject: '#64748b', // Reject button
|
|
112
|
+
radius: '8px', // Border radius
|
|
113
|
+
font: 'system-ui, sans-serif', // Font family
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
// UI text overrides
|
|
117
|
+
texts: {
|
|
118
|
+
heading: 'Cookie Preferences',
|
|
119
|
+
description: 'We use cookies to improve your experience.',
|
|
120
|
+
acceptAll: 'Accept All',
|
|
121
|
+
rejectOptional: 'Reject Optional',
|
|
122
|
+
managePreferences: 'Manage Preferences',
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
// Webhook: POST consent proof to your endpoint
|
|
126
|
+
webhookUrl: 'https://your-api.com/consent',
|
|
127
|
+
|
|
128
|
+
// Banner position: 'bottom' or 'top'
|
|
129
|
+
position: 'bottom',
|
|
130
|
+
|
|
131
|
+
// Persistent badge (reopens preferences): 'bottom-right' or 'bottom-left'
|
|
132
|
+
showBadge: true,
|
|
133
|
+
badgePosition: 'bottom-right',
|
|
134
|
+
|
|
135
|
+
// Google Consent Mode v2
|
|
136
|
+
consentMode: true,
|
|
137
|
+
|
|
138
|
+
// Consent expiry in months (1 to 13)
|
|
139
|
+
expiry: 13,
|
|
140
|
+
};
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Script Blocking
|
|
144
|
+
|
|
145
|
+
Tag scripts with `data-consent-category` to block them until consent:
|
|
146
|
+
|
|
147
|
+
```html
|
|
148
|
+
<!-- Google Analytics — blocked until "analytics" consent -->
|
|
149
|
+
<script data-consent-category="analytics"
|
|
150
|
+
src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
|
|
151
|
+
|
|
152
|
+
<!-- Meta Pixel — blocked until "marketing" consent -->
|
|
153
|
+
<script data-consent-category="marketing">
|
|
154
|
+
!function(f,b,e,v,n,t,s){...}(window,document,'script','https://connect.facebook.net/en_US/fbevents.js');
|
|
155
|
+
</script>
|
|
156
|
+
|
|
157
|
+
<!-- Hotjar — blocked until "analytics" consent -->
|
|
158
|
+
<script data-consent-category="analytics">
|
|
159
|
+
(function(h,o,t,j,a,r){...})(window,document,'https://static.hotjar.com/c/hotjar-','','6');
|
|
160
|
+
</script>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Categories:** `essential`, `analytics`, `functional`, `marketing`. Any choice grants `essential`, but a script tagged `essential` still waits for the visitor's first choice, so leave essential scripts untagged.
|
|
164
|
+
|
|
165
|
+
**Recommended:** add `type="text/plain"` to every gated script, inline or external. It stays inert until the visitor consents (or until saved consent from an earlier visit is read), so nothing can run early:
|
|
166
|
+
|
|
167
|
+
```html
|
|
168
|
+
<script type="text/plain" data-consent-category="analytics"
|
|
169
|
+
src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Without `type="text/plain"`, a script the browser's parser executes can run before any script blocker has loaded. SmartConsent blocks such scripts as soon as it starts, but it cannot stop one that has already run.
|
|
173
|
+
|
|
174
|
+
Scripts without `data-consent-category` run normally (not blocked).
|
|
175
|
+
|
|
176
|
+
## Regulation rules
|
|
177
|
+
|
|
178
|
+
SmartConsent ships rule files for 11 jurisdictions (`src/regulations/data/*.json`). The visitor's region is
|
|
179
|
+
estimated from the device's time zone: `America/Los_Angeles` counts as California, other US time zones as a US
|
|
180
|
+
state with a general privacy law, and a time zone we do not recognise falls back to the default rules.
|
|
181
|
+
|
|
182
|
+
| Rules | Countries | Consent model in the file | GPC and Do Not Track honoured |
|
|
183
|
+
|---|---|---|---|
|
|
184
|
+
| UK GDPR & PECR | GB | Opt-in | Yes |
|
|
185
|
+
| EU GDPR & ePrivacy | 27 EU + 3 EEA | Opt-in | Yes |
|
|
186
|
+
| DPDP Act (India) | IN | Opt-in | Yes |
|
|
187
|
+
| LGPD (Brazil) | BR | Opt-in | Yes |
|
|
188
|
+
| POPIA (South Africa) | ZA | Opt-in | Yes |
|
|
189
|
+
| PIPEDA (Canada) | CA | Opt-in | Yes |
|
|
190
|
+
| PDPA (Singapore) | SG | Opt-in | Yes |
|
|
191
|
+
| PDPA (Thailand) | TH | Opt-in | Yes |
|
|
192
|
+
| CCPA/CPRA (California) | US (CA) | Opt-out | Yes |
|
|
193
|
+
| US State Privacy Laws | US (17 states) | Opt-out | Yes |
|
|
194
|
+
| Default | Everywhere else | Opt-in (GDPR equivalent) | Yes |
|
|
195
|
+
|
|
196
|
+
What the rules change today: which rules each consent record names. Every file honours Global Privacy Control and
|
|
197
|
+
Do Not Track (`navigator.doNotTrack === '1'`): either signal rejects optional cookies and shows the badge, not the
|
|
198
|
+
banner; the visitor can still opt in from the badge. The consent period comes out at 13 months in every region
|
|
199
|
+
(the files say 365 or 395 days; the engine caps consent at 13 months). The rules do not change the banner: every visitor, in every region, gets the same ask-first banner with Accept, Reject and
|
|
200
|
+
Manage. When more than one file matches, the strictest setting wins.
|
|
201
|
+
|
|
202
|
+
Adding a jurisdiction means adding a JSON file and one import line in `src/regulations/loader.ts`.
|
|
203
|
+
|
|
204
|
+
## JavaScript API
|
|
205
|
+
|
|
206
|
+
```js
|
|
207
|
+
// Check if a category has consent
|
|
208
|
+
SmartConsent.hasConsent('analytics') // boolean
|
|
209
|
+
|
|
210
|
+
// Get full consent state
|
|
211
|
+
SmartConsent.getConsent() // ConsentState | null
|
|
212
|
+
|
|
213
|
+
// Reopen the preferences banner
|
|
214
|
+
SmartConsent.show()
|
|
215
|
+
|
|
216
|
+
// Clear consent and re-show banner
|
|
217
|
+
SmartConsent.reset()
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Events
|
|
221
|
+
|
|
222
|
+
Listen for consent changes:
|
|
223
|
+
|
|
224
|
+
```js
|
|
225
|
+
window.addEventListener('smartconsent:update', (e) => {
|
|
226
|
+
console.log(e.detail.categories); // { essential: true, analytics: false, ... }
|
|
227
|
+
console.log(e.detail.action); // 'accept_all' | 'reject_optional' | 'custom' | 'withdraw'
|
|
228
|
+
});
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Google Consent Mode v2
|
|
232
|
+
|
|
233
|
+
SmartConsent fires GTM Consent Mode v2 signals automatically:
|
|
234
|
+
|
|
235
|
+
- On load: `gtag('consent', 'default', { ... })` with every optional type denied (`security_storage` stays granted)
|
|
236
|
+
- On consent: `gtag('consent', 'update', { ... })` with per-category grants
|
|
237
|
+
|
|
238
|
+
Place SmartConsent **before** Google Tag Manager in your `<head>`.
|
|
239
|
+
|
|
240
|
+
## Microsoft UET consent mode
|
|
241
|
+
|
|
242
|
+
With `consentMode` on (the default), SmartConsent also queues Microsoft Advertising UET consent signals on
|
|
243
|
+
`window.uetq`, following the marketing category:
|
|
244
|
+
|
|
245
|
+
- On load: `uetq.push('consent', 'default', { ad_storage: 'denied' })`
|
|
246
|
+
- On consent: `uetq.push('consent', 'update', { ad_storage: 'granted' })` or `'denied'`
|
|
247
|
+
|
|
248
|
+
Place SmartConsent **before** the UET tag.
|
|
249
|
+
|
|
250
|
+
## Theming
|
|
251
|
+
|
|
252
|
+
All styles use CSS custom properties scoped under `[data-smartconsent]`:
|
|
253
|
+
|
|
254
|
+
| Variable | Default | Purpose |
|
|
255
|
+
|---|---|---|
|
|
256
|
+
| `--sc-bg` | `#0a0f1a` | Banner background |
|
|
257
|
+
| `--sc-surface` | `#141b2d` | Category row hover |
|
|
258
|
+
| `--sc-border` | `#1e2a45` | Dividers |
|
|
259
|
+
| `--sc-text` | `#e2e8f0` | Primary text |
|
|
260
|
+
| `--sc-text-muted` | `#94a3b8` | Secondary text |
|
|
261
|
+
| `--sc-accent` | `#3b82f6` | Links, active toggle |
|
|
262
|
+
| `--sc-accept` | `#10b981` | Accept button |
|
|
263
|
+
| `--sc-reject` | `#64748b` | Reject button |
|
|
264
|
+
| `--sc-toggle-on` | `#3b82f6` | Toggle on |
|
|
265
|
+
| `--sc-toggle-off` | `#334155` | Toggle off |
|
|
266
|
+
| `--sc-radius` | `8px` | Border radius |
|
|
267
|
+
| `--sc-font` | `system-ui` | Font family |
|
|
268
|
+
|
|
269
|
+
## Bundle Size
|
|
270
|
+
|
|
271
|
+
- **IIFE (minified + gzipped):** under 25 KB, including the 11 rule files
|
|
272
|
+
- **Zero runtime dependencies**
|
|
273
|
+
- **ES module** also available for bundler tree-shaking
|
|
274
|
+
|
|
275
|
+
## Accessibility
|
|
276
|
+
|
|
277
|
+
- `role="dialog"`, `aria-modal`, `aria-label` on banner
|
|
278
|
+
- `role="switch"`, `aria-checked` on toggles
|
|
279
|
+
- Focus trapping within banner
|
|
280
|
+
- Escape rejects optional cookies and closes the banner
|
|
281
|
+
- Screen reader announcements
|
|
282
|
+
- Visible focus indicators
|
|
283
|
+
|
|
284
|
+
## Licence
|
|
285
|
+
|
|
286
|
+
Business Source License 1.1 (BSL 1.1). See [LICENSE](LICENSE) for details.
|
|
287
|
+
|
|
288
|
+
Free for any use except offering a competing cookie consent management service.
|
|
289
|
+
Converts to Apache 2.0 after four years.
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
Built by [SmartGenie Ltd](https://smartgenie.co.uk) | Engineering Intelligence
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ConsentManager } from '../core/consent-manager';
|
|
2
|
+
import type { BlockRule, SmartConsentTexts } from '../types';
|
|
3
|
+
export interface BlockerAPI {
|
|
4
|
+
init(): void;
|
|
5
|
+
/** Sets the consent manager after an early manager-less init(), then releases what saved consent grants. */
|
|
6
|
+
attach(manager: ConsentManager): void;
|
|
7
|
+
destroy(): void;
|
|
8
|
+
/**
|
|
9
|
+
* The known-tracker list (CR-035). Never called: only tagged scripts are held (today's behaviour). `null`: the list is
|
|
10
|
+
* not here yet, so every untagged third-party script that is async or added by code, and every third-party iframe,
|
|
11
|
+
* waits. A list: what waited and is not on it is released in order, and listed scripts and iframes are held under
|
|
12
|
+
* their category until it is granted.
|
|
13
|
+
*/
|
|
14
|
+
setRules(list: BlockRule[] | null): void;
|
|
15
|
+
/** The placeholder's strings (config texts, after the language pack); boxes already shown are relabelled. */
|
|
16
|
+
setTexts(texts: Pick<SmartConsentTexts, 'embedNotice' | 'embedLoad'>): void;
|
|
17
|
+
}
|
|
18
|
+
export declare function createBlocker(initialManager?: ConsentManager): BlockerAPI;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ConsentManager } from '../core/consent-manager';
|
|
2
|
+
import type { SmartConsentConfig } from '../types';
|
|
3
|
+
export interface GTMConsentModeAPI {
|
|
4
|
+
init(opts?: {
|
|
5
|
+
defaultSent?: boolean;
|
|
6
|
+
}): void;
|
|
7
|
+
destroy(): void;
|
|
8
|
+
}
|
|
9
|
+
declare global {
|
|
10
|
+
interface Window {
|
|
11
|
+
dataLayer: unknown[];
|
|
12
|
+
gtag: (...args: unknown[]) => void;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Sends the GTM default-deny. Called synchronously at engine start, before any async work. */
|
|
16
|
+
export declare function sendGtmDefaultDeny(): void;
|
|
17
|
+
/** Takes back any earlier grant: one update with every optional purpose denied. Used when boot fails. */
|
|
18
|
+
export declare function sendGtmDenyUpdate(): void;
|
|
19
|
+
export declare function createGTMConsentMode(config: SmartConsentConfig, manager: Pick<ConsentManager, 'getState'>): GTMConsentModeAPI;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
uetq?: unknown[];
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
/** Sends the UET default-deny. Called synchronously at engine start, before any async work. */
|
|
7
|
+
export declare function sendUetDefaultDeny(): void;
|
|
8
|
+
/** Sends a UET update from the marketing category. */
|
|
9
|
+
export declare function sendUetUpdate(marketing: boolean): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(()=>{function p(e,a){if(typeof e!="string"||!e)return Math.random()<.5?"a":"b";let r=e+":"+a,n=2166136261;for(let t=0;t<r.length;t++)n=Math.imul(n^r.charCodeAt(t),16777619);return n<0?"b":"a"}var s={v:1,pick:p};(window.SmartConsentCapsules??(window.SmartConsentCapsules={}))["banner-experiment"]=s;})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(()=>{var u=n=>!!n&&typeof n=="object"&&Array.isArray(n.ids);function e(n,o){if(!Array.isArray(o))return null;let i=o.filter(u),t=i.find(s=>s.ids.some(r=>n.includes(r)))??i.find(s=>s.ids.includes("default-global"));return t?t.look:null}var l={v:1,apply:e};(window.SmartConsentCapsules??(window.SmartConsentCapsules={}))["country-banners"]=l;})();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { EngineCapsule } from '../types';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
SmartConsentCapsules?: Record<string, object | undefined>;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
/** The capsule `id` from `<base>capsules/<id>.js` when `listed` (the settings file's `capsules`) names it; else null. */
|
|
8
|
+
export declare function loadCapsule<T extends object = EngineCapsule>(id: string, base: string, listed: unknown): Promise<T | null>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ConsentState } from '../types';
|
|
2
|
+
/** The saved choice in the `sc_consent` cookie, or null (a host off `domain`, none, malformed, or cookies refused). */
|
|
3
|
+
export declare function read(domain: string): ConsentState | null;
|
|
4
|
+
/** Sets the cookie on `domain` until the choice expires; null (or an expired choice) deletes it. Never throws. */
|
|
5
|
+
export declare function write(domain: string, state: ConsentState | null): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(()=>{var i="sc_consent",r=n=>{let t=n;return!!t&&typeof t=="object"&&typeof t.version=="number"&&!!t.categories&&typeof t.categories=="object"&&typeof t.timestamp=="string"&&typeof t.action=="string"&&typeof t.expiresAt=="string"};function c(n){try{let t=location.hostname;if(t!==n&&!t.endsWith("."+n))return null;let e=document.cookie.split("; ").find(s=>s.startsWith(i+"="));if(!e)return null;let o=JSON.parse(decodeURIComponent(e.slice(i.length+1)));return r(o)?o:null}catch{return null}}function a(n,t){try{let e=t?Math.floor((Date.parse(t.expiresAt)-Date.now())/1e3):0,o=t&&e>0?encodeURIComponent(JSON.stringify(t)):"",s=location.protocol==="https:"?"; Secure":"";document.cookie=`${i}=${o}; Domain=${n}; Path=/; Max-Age=${Math.max(0,e||0)}; SameSite=Lax${s}`}catch{}}var u={v:1,read:c,write:a};(window.SmartConsentCapsules??(window.SmartConsentCapsules={}))["subdomain-consent"]=u;})();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ConsentCategory, SmartConsentConfig, SmartConsentTexts, SmartConsentTheme } from '../types';
|
|
2
|
+
/** Four default cookie categories per ARCHITECTURE.md */
|
|
3
|
+
export declare const DEFAULT_CATEGORIES: ConsentCategory[];
|
|
4
|
+
/** Clean Light theme defaults (BRIEF-276, owner 1 Dec 2026) — maps to --sc-* CSS variables */
|
|
5
|
+
export declare const DEFAULT_THEME: SmartConsentTheme;
|
|
6
|
+
/** All user-facing strings — enables future localisation */
|
|
7
|
+
export declare const DEFAULT_TEXTS: SmartConsentTexts;
|
|
8
|
+
/**
|
|
9
|
+
* Where per-site settings files are hosted (CR-012): `<base>/v1/sites/<id>.json`.
|
|
10
|
+
* Deliberately not overridable from the page config: a page that could point the engine at its own
|
|
11
|
+
* settings file could declare itself Enterprise and drop the attribution link.
|
|
12
|
+
*/
|
|
13
|
+
export declare const DEFAULT_SETTINGS_BASE = "https://smartconsentsettings.blob.core.windows.net/$web";
|
|
14
|
+
/** Where the banner language packs load from when the engine cannot read its own script URL (CR-019); not overridable from the page config. */
|
|
15
|
+
export declare const DEFAULT_PACKS_BASE = "https://cdn.smartgenie.co.uk/v1/";
|
|
16
|
+
/** Where Pro sites send consent records (CR-019); not overridable from the page config. */
|
|
17
|
+
export declare const DEFAULT_API_BASE = "https://api.smartgenie.co.uk";
|
|
18
|
+
/** Full default config — version is 0 as a placeholder (user must provide) */
|
|
19
|
+
export declare const DEFAULT_CONFIG: SmartConsentConfig;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SmartConsentConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates and merges a raw user config with defaults.
|
|
4
|
+
* Throws if `version` is missing (the only required field).
|
|
5
|
+
* Clamps expiry to 1–13 range.
|
|
6
|
+
* Deep-merges `theme` and `texts`; replaces `categories` entirely if provided.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateConfig(raw: unknown): SmartConsentConfig;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ConsentAction, ConsentRecord } from '../types';
|
|
2
|
+
export interface ConsentLogAPI {
|
|
3
|
+
addRecord(action: ConsentAction, categories: Record<string, boolean>): ConsentRecord;
|
|
4
|
+
getLog(): ConsentRecord[];
|
|
5
|
+
getLatest(): ConsentRecord | null;
|
|
6
|
+
clear(): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function createConsentLog(options: {
|
|
9
|
+
visitorHash: string;
|
|
10
|
+
jurisdiction: string;
|
|
11
|
+
version: string;
|
|
12
|
+
}): ConsentLogAPI;
|
|
13
|
+
/** Compute a non-reversible visitor hash from browser signals (no PII) */
|
|
14
|
+
export declare function computeVisitorHash(): Promise<string>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ConsentEvent, ConsentState, SmartConsentConfig } from '../types';
|
|
2
|
+
export interface ConsentManager {
|
|
3
|
+
acceptAll(): void;
|
|
4
|
+
rejectOptional(): void;
|
|
5
|
+
saveCustom(categories: Record<string, boolean>): void;
|
|
6
|
+
withdraw(): void;
|
|
7
|
+
reset(): void;
|
|
8
|
+
getState(): ConsentState | null;
|
|
9
|
+
hasConsent(category: string): boolean;
|
|
10
|
+
needsConsent(): boolean;
|
|
11
|
+
onConsentChange(cb: (event: ConsentEvent) => void): () => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function createConsentManager(config: SmartConsentConfig): ConsentManager;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ConsentRecord } from '../types';
|
|
2
|
+
export interface ConsentStats {
|
|
3
|
+
totalActions: number;
|
|
4
|
+
acceptAllRate: number;
|
|
5
|
+
rejectAllRate: number;
|
|
6
|
+
customRate: number;
|
|
7
|
+
categoryBreakdown: Record<string, {
|
|
8
|
+
accepted: number;
|
|
9
|
+
rejected: number;
|
|
10
|
+
}>;
|
|
11
|
+
lastUpdated: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function computeConsentStats(log: ConsentRecord[]): ConsentStats;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ConsentEvent } from '../types';
|
|
2
|
+
/** Fires a smartconsent:update CustomEvent on window */
|
|
3
|
+
export declare function dispatchConsent(event: ConsentEvent): void;
|
|
4
|
+
/** Registers a listener for smartconsent:update. Returns an unsubscribe function. */
|
|
5
|
+
export declare function onConsentChange(callback: (event: ConsentEvent) => void): () => void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BannerConfiguration, SmartConsentConfig } from '../types';
|
|
2
|
+
import type { ConsentManager } from './consent-manager';
|
|
3
|
+
/** Returns true when GPC or Do Not Track is on and the regulation asks for it (the caller then shows the badge,
|
|
4
|
+
* not the banner). Every regulation file honours both (CR-019, BRIEF-176). */
|
|
5
|
+
export declare function applyGpc(manager: ConsentManager, config: SmartConsentConfig, bannerConfig: BannerConfiguration): boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ConsentState } from '../types';
|
|
2
|
+
export interface StorageAPI {
|
|
3
|
+
getConsent(): ConsentState | null;
|
|
4
|
+
saveConsent(state: ConsentState): void;
|
|
5
|
+
clearConsent(): void;
|
|
6
|
+
isExpired(): boolean;
|
|
7
|
+
isVersionMatch(version: number): boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function createStorage(): StorageAPI;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LanguageData } from '../types';
|
|
2
|
+
/** Returns language data for the given code, or null if not found. */
|
|
3
|
+
export declare function getLanguage(code: string): LanguageData | null;
|
|
4
|
+
/**
|
|
5
|
+
* Detects the active language.
|
|
6
|
+
* Priority: config override > navigator.language > 'en' fallback.
|
|
7
|
+
*/
|
|
8
|
+
export declare function detectLanguage(configOverride?: string): string;
|
|
9
|
+
/** Returns all available language codes. */
|
|
10
|
+
export declare function getAvailableLanguages(): string[];
|
|
11
|
+
export { registerLanguage } from './translations';
|