@generazioneai/analytics-web 0.0.0-stage → 0.3.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/CHANGELOG.md +29 -0
- package/LICENSE +201 -0
- package/README.md +191 -2
- package/bin/analytics-web.cjs +76 -0
- package/dist/autocapture.d.ts +57 -0
- package/dist/browser.d.ts +3 -0
- package/dist/cmp.d.ts +7 -0
- package/dist/cmp.js +1 -0
- package/dist/consent/cookiebot.d.ts +11 -0
- package/dist/consent/gcm.d.ts +10 -0
- package/dist/consent/index.d.ts +6 -0
- package/dist/consent/iubenda.d.ts +20 -0
- package/dist/consent/onetrust.d.ts +12 -0
- package/dist/consent/tcf.d.ts +43 -0
- package/dist/consent/test-env.d.ts +13 -0
- package/dist/consent/types.d.ts +60 -0
- package/dist/core.d.ts +165 -0
- package/dist/errors.d.ts +60 -0
- package/dist/extensions.d.ts +1 -0
- package/dist/flags.d.ts +96 -0
- package/dist/frustration.d.ts +62 -0
- package/dist/index.cjs +1380 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +1359 -0
- package/dist/plugins.d.ts +16 -0
- package/dist/s.js +1 -0
- package/dist/scrub.d.ts +7 -0
- package/dist/snippet.d.ts +1 -0
- package/dist/vitals.d.ts +28 -0
- package/dist/x.js +3 -0
- package/package.json +45 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Novità
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
- Consenso nel modello di **Google Consent Mode v2**: stati `analytics_storage`, `ad_storage`, `ad_user_data`, `ad_personalization`
|
|
6
|
+
(di serie tutti negati); opzioni `consentDefaults`, `withoutConsent: 'cookieless' | 'none'`, `cookieMaxAgeDays` (1..395, di serie 395 =
|
|
7
|
+
13 mesi), `cmp`; metodi `consentUpdate()` e `consentState()`. `consent('granted' | 'denied')` resta e vale per `analytics_storage`.
|
|
8
|
+
- Evento `$consent` a ogni cambio, con i quattro stati. Gli stati pubblicitari si registrano soltanto: Auralytics non fa pubblicità.
|
|
9
|
+
- Adattatori delle CMP: `tcf()` (IAB TCF 2.2), `iubenda()`, `cookiebot()`, `onetrust()`, `googleConsentMode()`. Ognuno aspetta la CMP
|
|
10
|
+
se arriva dopo e non lancia mai. Scelte prudenti: con TCF `gdprApplies: false` non concede niente senza `trustGdprApplies: true`;
|
|
11
|
+
un `default` di Consent Mode può solo negare; iubenda con `perPurposeConsent` e stato illeggibile resta negato.
|
|
12
|
+
- `withoutConsent: 'none'`: senza consenso non parte niente; al consenso parte il `page_view` della pagina, alla revoca la coda si butta.
|
|
13
|
+
- Snippet: `data-without-consent`, `data-cmp` (carica `cmp.js`, gli adattatori, dalla stessa origine dello snippet). Snippet e `cmp.js`
|
|
14
|
+
compilati per ES2022 (i browser di Next 16).
|
|
15
|
+
- Errori JavaScript (`errors: { release }`): `$exception` con stack normalizzato, impronta stabile, messaggio ripulito, campionamento e
|
|
16
|
+
tetto per pagina; `auralytics.plugins.captureException(err)` per quelli gestiti.
|
|
17
|
+
- Web Vitals (`webVitals: { sampleRate }`, di serie 10%): LCP, INP, CLS, TTFB in un evento `$web_vitals` per pagina.
|
|
18
|
+
- Misurazione avanzata (`enhanced`): scorrimento 25/50/75/90, clic in uscita, download, ricerca nel sito, moduli (mai i valori), video HTML5.
|
|
19
|
+
- Autocattura dei clic (`autocapture`): `$autocapture` con selettore, tag e testo ripulito; `data-au-no-capture` esclude un ramo.
|
|
20
|
+
- `x.js` per chi usa lo snippet (che resta ≤ 3 KB): `data-errors`, `data-vitals`, `data-enhanced`, `data-autocapture`, `data-release`.
|
|
21
|
+
- CLI `npx @generazioneai/analytics-web upload-sourcemaps --release <r> --dir dist` (chiave `AURALYTICS_SECRET_KEY`, `sk_`).
|
|
22
|
+
|
|
23
|
+
## 0.2.0
|
|
24
|
+
|
|
25
|
+
- Prima versione pubblica (Apache-2.0).
|
|
26
|
+
- Identità verificata: `identityToken()` e opzione `identityToken` (campo `idt` del lotto); `workforceTicket()` deprecato.
|
|
27
|
+
- L'identità è legata all'evento: ogni evento parte col token (`idt`/`wt`) attivo quando è nato, il lotto si spezza dove cambia; `reset()` e un nuovo token non spostano la coda di prima. La coda del `localStorage` non contiene token, e ripresa in un'altra pagina parte senza identità. `shutdown()` manda tutti i lotti.
|
|
28
|
+
- `sanitizeUrl`, `pageTitle`, `module` come funzione, `appName`, `shutdown()`.
|
|
29
|
+
- Pacchetto con ESM, CommonJS e tipi; lo snippet `s.js` incluso.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,192 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @generazioneai/analytics-web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
SDK web di **Auralytics** (GenAI Analytics): eventi, pagine, consenso (Google Consent Mode v2, IAB TCF 2.2, iubenda, Cookiebot,
|
|
4
|
+
OneTrust), identità verificata, invio a lotti. Nessuna dipendenza. Licenza Apache-2.0.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm install @generazioneai/analytics-web
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { init } from '@generazioneai/analytics-web';
|
|
12
|
+
|
|
13
|
+
const auralytics = init({
|
|
14
|
+
stream: 'pk_…', // chiave pubblica dello stream WEB
|
|
15
|
+
endpoint: 'https://api.auralytics.it', // o il dominio di prima parte del collector
|
|
16
|
+
consent: 'unknown', // dal banner: 'granted' | 'denied' | 'unknown' (vedi «Consenso»)
|
|
17
|
+
sanitizeUrl: (url) => modelloDellaRotta(url), // facoltativa, vedi sotto
|
|
18
|
+
});
|
|
19
|
+
auralytics.track('signup', { plan: 'pro' });
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
In alternativa lo snippet senza npm: `<script defer src="https://api.auralytics.it/s.js" data-stream="pk_…"></script>` (circa 3,3 KB
|
|
23
|
+
compressi; opzioni `data-endpoint`, `data-consent`, `data-without-consent`, `data-cmp`, `data-auto`, `data-debug`; lo stesso file è nel
|
|
24
|
+
pacchetto come `@generazioneai/analytics-web/s.js`). Le chiamate fatte prima del caricamento vanno in coda:
|
|
25
|
+
`window.auralytics = window.auralytics || []; auralytics.push(['consentUpdate', { analytics_storage: 'granted' }]);`.
|
|
26
|
+
|
|
27
|
+
## Consenso
|
|
28
|
+
|
|
29
|
+
Il consenso segue **Google Consent Mode v2**: quattro stati, ciascuno `'granted'` o `'denied'`, di serie **tutti negati**.
|
|
30
|
+
|
|
31
|
+
| Stato | Effetto in Auralytics |
|
|
32
|
+
|---|---|
|
|
33
|
+
| `analytics_storage` | decide la modalità (sotto) |
|
|
34
|
+
| `ad_storage`, `ad_user_data`, `ad_personalization` | nessuno: Auralytics non fa pubblicità. Si registrano e partono nell'evento `$consent`, per integrazioni future |
|
|
35
|
+
|
|
36
|
+
### Le modalità
|
|
37
|
+
|
|
38
|
+
| | Senza consenso, `withoutConsent: 'cookieless'` (di serie) | Senza consenso, `withoutConsent: 'none'` | Con `analytics_storage` concesso |
|
|
39
|
+
|---|---|---|---|
|
|
40
|
+
| Invii | sì, eventi senza identificativi | **nessuno** (nemmeno in memoria) | sì |
|
|
41
|
+
| Cookie, `localStorage`, `sessionStorage` | no | no | cookie di prima parte `_au_id`, sessione e coda offline in `localStorage` |
|
|
42
|
+
| Visitatore | id giornaliero calcolato dal collector (sale ruotato ogni 24 ore e cancellato): non riconosce il ritorno | — | `_au_id`: riconosce il ritorno |
|
|
43
|
+
| Sessione | ricalcolata dal collector nel giorno | — | 30 minuti di inattività |
|
|
44
|
+
| `identify()`, `user_id` | ignorati | ignorati | sì (mai un'email: rifiutata) |
|
|
45
|
+
|
|
46
|
+
**Cosa non facciamo senza consenso**: nessun cookie e nessun archivio del browser, nessun id persistente del dispositivo, niente
|
|
47
|
+
`identify`/`user_id`, niente User-Provided Data, niente session replay; IP sempre troncato (IPv4 /24, IPv6 /48) e mai salvato, user
|
|
48
|
+
agent ridotto a famiglie; solo statistiche aggregate, nessun incrocio con altri dati, nessuna profilazione. È la configurazione pensata
|
|
49
|
+
per stare nel perimetro dei cookie analitici assimilati ai tecnici delle Linee guida del Garante (provv. 231 del 10 giugno 2021).
|
|
50
|
+
|
|
51
|
+
**Durata del cookie** `_au_id`: `cookieMaxAgeDays`, da 1 a 395 giorni, di serie **395 (13 mesi)**. Puoi accorciarla, non allungarla:
|
|
52
|
+
un valore più alto si taglia a 395. Ogni visita con il consenso ne rinnova la durata.
|
|
53
|
+
|
|
54
|
+
**Cambio di stato**: alla concessione nascono cookie e sessione (con `withoutConsent: 'none'` parte anche il `page_view` della pagina
|
|
55
|
+
aperta); alla **revoca** l'SDK cancella il cookie, la sessione e la coda offline del browser e torna alla modalità senza cookie (con
|
|
56
|
+
`'none'` smette di inviare e butta la coda in memoria). Ogni cambio manda l'evento `$consent` con i quattro stati (proprietà
|
|
57
|
+
`analytics_storage`, `ad_storage`, `ad_user_data`, `ad_personalization`, e `state` = `analytics_storage`).
|
|
58
|
+
|
|
59
|
+
**La valutazione resta tua**: sei tu, titolare del trattamento, a decidere se e quando chiedere il consenso, con quale banner e con
|
|
60
|
+
quale informativa. Auralytics (responsabile del trattamento, art. 28 GDPR) applica le regole qui sopra e ti aiuta nella valutazione, ma
|
|
61
|
+
non la sostituisce.
|
|
62
|
+
|
|
63
|
+
**Dipendenti.** Sulle app di lavoro (proprietà `workforce`) il consenso del dipendente non è una base valida: lì valgono le regole
|
|
64
|
+
dell'art. 4 dello Statuto dei Lavoratori (solo aggregati di almeno 5 persone, persona solo come pseudonimo), indipendentemente da
|
|
65
|
+
questi stati.
|
|
66
|
+
|
|
67
|
+
### API
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
const auralytics = init({
|
|
71
|
+
stream: 'pk_…',
|
|
72
|
+
consentDefaults: { analytics_storage: 'denied' }, // come gtag('consent', 'default', …); di serie tutto 'denied'
|
|
73
|
+
withoutConsent: 'cookieless', // o 'none'
|
|
74
|
+
cookieMaxAgeDays: 180, // 1..395, di serie 395
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
auralytics.consentUpdate({ analytics_storage: 'granted', ad_storage: 'denied' }); // come gtag('consent', 'update', …)
|
|
78
|
+
auralytics.consent('granted'); // scorciatoia per analytics_storage ('granted' | 'denied' | 'unknown' = nessuna scelta, negato)
|
|
79
|
+
auralytics.consentState(); // { analytics_storage, ad_storage, ad_user_data, ad_personalization, mode: 'full' | 'cookieless' | 'none' }
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`consent` (opzione d'avvio) vince su `consentDefaults.analytics_storage`. Do Not Track e Global Privacy Control sono rispettati
|
|
83
|
+
(`respectDnt`, di serie sì): niente invii.
|
|
84
|
+
|
|
85
|
+
### Banner (CMP): gli adattatori
|
|
86
|
+
|
|
87
|
+
Un adattatore ascolta il tuo banner e aggiorna gli stati da solo (opzione `cmp`, anche più d'uno). Ognuno aspetta la CMP se arriva
|
|
88
|
+
dopo l'SDK e non lancia mai: se la CMP non c'è si resta senza consenso.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { init, tcf, iubenda, cookiebot, onetrust, googleConsentMode } from '@generazioneai/analytics-web';
|
|
92
|
+
|
|
93
|
+
init({ stream: 'pk_…', cmp: tcf() });
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
| CMP | Adattatore | Mappatura |
|
|
97
|
+
|---|---|---|
|
|
98
|
+
| **IAB TCF 2.2** (qualunque CMP certificata: `__tcfapi`) | `tcf({ vendorId?, analyticsPurposes?, trustGdprApplies? })` | `analytics_storage` solo se **tutte** le finalità di `analyticsPurposes` (di serie 1, 8, 9) sono concesse; `ad_storage` ← finalità 1, `ad_user_data` ← 1 e 7, `ad_personalization` ← 3 e 4. `gdprApplies: false` di serie non concede niente; `trustGdprApplies: true` = tutto concesso, come fa Google. Solo gli eventi `tcloaded` e `useractioncomplete`; attesa di `__tcfapi` fino a 10 s (`timeoutMs`) |
|
|
99
|
+
| **iubenda** | `iubenda({ analyticsPurpose?: 4, adsPurpose?: 5 })` | finalità 4 (misurazione) → `analytics_storage`, 5 (marketing) → stati pubblicitari; senza consenso per finalità, tutti seguono il consenso unico (con `perPurposeConsent` e stato illeggibile: negato). Callback di `_iub.csConfiguration` (le tue restano) più una rilettura dello stato ogni 2 s (`pollMs`) |
|
|
100
|
+
| **Cookiebot** | `cookiebot({ analyticsCategory?: 'statistics', adsCategory?: 'marketing' })` | `Cookiebot.consent.statistics` → `analytics_storage`, `marketing` → stati pubblicitari; eventi `CookiebotOnConsentReady`, `…OnAccept`, `…OnDecline`, `…OnLoad` |
|
|
101
|
+
| **OneTrust** | `onetrust({ analyticsGroup?: 'C0002', adsGroup?: 'C0004' })` | gruppo C0002 (prestazioni) → `analytics_storage`, C0004 (pubblicità) → stati pubblicitari; evento `OneTrustGroupsUpdated` |
|
|
102
|
+
| **Google Consent Mode** (gtag o Google Tag Manager) | `googleConsentMode()` | legge i comandi `consent` `default` e `update` di `dataLayer` (anche quelli già presenti); i `default` con `region` si ignorano, un `default` può solo negare (un concesso vale solo da un `update`), e dopo il primo `update` i `default` non contano più |
|
|
103
|
+
|
|
104
|
+
**Gli adattatori si fidano della pagina.** Leggono le variabili che la CMP mette nella pagina (`__tcfapi`, `_iub`, `Cookiebot`,
|
|
105
|
+
`OnetrustActiveGroups`, `dataLayer`): chi controlla gli script della pagina può cambiare lo stato del consenso. Carica solo script di
|
|
106
|
+
cui ti fidi; per questo l'SDK sceglie sempre il lato prudente (`gdprApplies: false` non concede niente se non lo chiedi, un `default` di
|
|
107
|
+
Consent Mode può solo negare).
|
|
108
|
+
|
|
109
|
+
**TCF, con o senza `vendorId`.** Auralytics non è nella Global Vendor List dell'IAB: è uno strumento di prima parte del sito. Per questo,
|
|
110
|
+
**senza `vendorId`** valgono le **finalità del publisher** (`publisher.consents`, le «publisher purposes» del TCF 2.2), e solo se la tua
|
|
111
|
+
CMP non ne espone nessuna il consenso alle finalità (`purpose.consents`). Se nella tua CMP hai registrato Auralytics come vendor
|
|
112
|
+
personalizzato con un id, passalo: `tcf({ vendorId: 1234 })`; allora servono le finalità (`purpose.consents`) **e** il consenso del vendor.
|
|
113
|
+
|
|
114
|
+
Esempi:
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
init({ stream: 'pk_…', cmp: tcf() }); // IAB TCF 2.2, finalità del publisher
|
|
118
|
+
init({ stream: 'pk_…', cmp: tcf({ vendorId: 1234, analyticsPurposes: [1, 8, 9] }) });
|
|
119
|
+
init({ stream: 'pk_…', cmp: iubenda() }); // prima o dopo lo script di iubenda: va bene uguale
|
|
120
|
+
init({ stream: 'pk_…', cmp: cookiebot() });
|
|
121
|
+
init({ stream: 'pk_…', cmp: onetrust({ analyticsGroup: 'C0002' }) });
|
|
122
|
+
init({ stream: 'pk_…', cmp: googleConsentMode() }); // il tuo gtag('consent', …) o il modello di GTM
|
|
123
|
+
init({ stream: 'pk_…', withoutConsent: 'none', cmp: [tcf(), googleConsentMode()] });
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Con lo snippet: `data-cmp="tcf"` (o `iubenda`, `cookiebot`, `onetrust`, `gcm`, anche più d'uno separati da virgola) e
|
|
127
|
+
`data-without-consent="none"`. Gli adattatori non stanno dentro `s.js` (per tenerlo piccolo): con `data-cmp` lo snippet carica `cmp.js`
|
|
128
|
+
dalla sua stessa origine, con le opzioni di serie; se `cmp.js` non arriva si resta senza consenso. Per opzioni diverse (es. `vendorId`)
|
|
129
|
+
usa il pacchetto npm, o chiama tu `auralytics.consentUpdate(…)` dalla callback del banner.
|
|
130
|
+
|
|
131
|
+
```html
|
|
132
|
+
<script defer src="https://stats.tuosito.it/s.js" data-stream="pk_…" data-cmp="iubenda" data-without-consent="cookieless"></script>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Un banner tuo, senza adattatore: chiama `auralytics.consentUpdate({ analytics_storage: 'granted' })` quando la persona accetta e
|
|
136
|
+
`auralytics.consentUpdate({ analytics_storage: 'denied' })` quando rifiuta o revoca.
|
|
137
|
+
|
|
138
|
+
## Identità verificata
|
|
139
|
+
Il backend dell'app firma per lo stream un token d'identità `it1.<payload>.<firma>` (chi è la persona, per quale gruppo, fino a quando) e
|
|
140
|
+
l'app lo passa all'SDK:
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
auralytics.identityToken(token); // o l'opzione d'avvio `identityToken`; null lo toglie, reset() anche
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Resta solo in memoria e va in ogni lotto come `idt` (stringa ≤ 1024 che comincia con `it1.`, altrimenti ignorata). Si manda anche senza
|
|
147
|
+
consenso: lo verifica il collector e applica le regole della proprietà. `workforceTicket()` (campo `wt`) è **deprecato**: il collector lo
|
|
148
|
+
accetta fino al passaggio all'identità verificata, poi si toglie.
|
|
149
|
+
|
|
150
|
+
## Indirizzi senza dati: `sanitizeUrl`
|
|
151
|
+
`sanitizeUrl(url) => string | null` ripulisce `url` di ogni evento e `referrer` del `page_view` prima dell'invio: tiene fuori id, token
|
|
152
|
+
e query (`https://app.it/dipendenti/123?tab=2` → `https://app.it/dipendenti/:id`). `null` = indirizzo da non mandare: `page()` non manda
|
|
153
|
+
niente, gli altri eventi partono con `url` vuoto. Con `pageTitle: false` il titolo della pagina non si manda; `module` può essere una
|
|
154
|
+
funzione dell'indirizzo già ripulito.
|
|
155
|
+
|
|
156
|
+
## Altre opzioni
|
|
157
|
+
`autoPageviews` (di serie sì: `page_view` al caricamento e ai cambi di pagina delle SPA), `debug` (DebugView, fuori dai report),
|
|
158
|
+
`product`, `appName` (`app_name`). `shutdown()` manda la coda e ferma l'istanza. L'ambiente del browser (`Env`) si può sostituire nei test.
|
|
159
|
+
|
|
160
|
+
Per React e Next.js: [`@generazioneai/analytics-react`](../react).
|
|
161
|
+
|
|
162
|
+
## Errori, Web Vitals, misurazione avanzata e autocattura (0.3.0)
|
|
163
|
+
|
|
164
|
+
Tutto spento di serie, si accende una funzione alla volta:
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
const auralytics = init({
|
|
168
|
+
stream: 'pk_…',
|
|
169
|
+
errors: { release: '1.4.2' }, // $exception, al più 10 per pagina, uno per impronta
|
|
170
|
+
webVitals: { sampleRate: 0.1 }, // $web_vitals: LCP, INP, CLS, TTFB
|
|
171
|
+
enhanced: true, // scorrimento, clic in uscita, download, ricerca, moduli, video
|
|
172
|
+
autocapture: true, // $autocapture sui clic di pulsanti e link
|
|
173
|
+
});
|
|
174
|
+
try { … } catch (e) { auralytics.plugins.captureException(e); }
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Con lo snippet: `<script defer src="https://api.auralytics.it/x.js" data-errors="true" data-release="1.4.2" data-vitals="0.1"
|
|
178
|
+
data-enhanced="true" data-autocapture="true"></script>` dopo `s.js`.
|
|
179
|
+
|
|
180
|
+
Privacy: i valori dei campi non si leggono mai; messaggi, testi dei pulsanti e termini di ricerca si ripuliscono (email, numeri lunghi,
|
|
181
|
+
token); gli indirizzi perdono query e frammento; `data-au-no-capture` su un elemento esclude lui e tutto ciò che contiene.
|
|
182
|
+
|
|
183
|
+
### Source map dalla CI
|
|
184
|
+
|
|
185
|
+
```yaml
|
|
186
|
+
# GitHub Actions, dopo la build
|
|
187
|
+
- run: npx @generazioneai/analytics-web upload-sourcemaps --release "${GITHUB_SHA::7}" --dir dist --delete
|
|
188
|
+
env:
|
|
189
|
+
AURALYTICS_SECRET_KEY: ${{ secrets.AURALYTICS_SECRET_KEY }} # la chiave sk_ di uno stream server della proprietà
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
La stessa release va nell'SDK (`errors: { release }`). Le mappe restano su Auralytics (le ultime 20 release), non vanno pubblicate col sito.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Auralytics: caricamento delle source map dalla CI (W2).
|
|
3
|
+
//
|
|
4
|
+
// AURALYTICS_SECRET_KEY=sk_… npx @generazioneai/analytics-web upload-sourcemaps --release 1.4.2 --dir dist [--endpoint https://api.auralytics.it]
|
|
5
|
+
//
|
|
6
|
+
// Manda ogni file `*.map` della cartella (ricorsivo) a `POST <endpoint>/sm/v1/upload?release=<release>&file=<nome>` con la chiave segreta
|
|
7
|
+
// di uno stream server della proprietà. La stessa `release` va passata all'SDK (`init({ errors: { release } })`). Le mappe non vanno
|
|
8
|
+
// pubblicate col sito: dopo il caricamento si possono cancellare dalla cartella (`--delete`).
|
|
9
|
+
'use strict';
|
|
10
|
+
const { readdirSync, readFileSync, statSync, unlinkSync } = require('node:fs');
|
|
11
|
+
const { basename, join } = require('node:path');
|
|
12
|
+
|
|
13
|
+
function arg(name, fallback) {
|
|
14
|
+
const i = process.argv.indexOf(`--${name}`);
|
|
15
|
+
return i > 0 && process.argv[i + 1] ? process.argv[i + 1] : fallback;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function maps(dir) {
|
|
19
|
+
const out = [];
|
|
20
|
+
for (const name of readdirSync(dir)) {
|
|
21
|
+
const p = join(dir, name);
|
|
22
|
+
const s = statSync(p);
|
|
23
|
+
if (s.isDirectory()) out.push(...maps(p));
|
|
24
|
+
else if (name.endsWith('.map')) out.push(p);
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function main() {
|
|
30
|
+
const cmd = process.argv[2];
|
|
31
|
+
if (cmd !== 'upload-sourcemaps') {
|
|
32
|
+
console.error(
|
|
33
|
+
'uso: analytics-web upload-sourcemaps --release <release> --dir <cartella> [--endpoint <url>] [--delete]',
|
|
34
|
+
);
|
|
35
|
+
process.exit(2);
|
|
36
|
+
}
|
|
37
|
+
const key = process.env.AURALYTICS_SECRET_KEY ?? '';
|
|
38
|
+
const release = arg('release', process.env.AURALYTICS_RELEASE ?? '');
|
|
39
|
+
const dir = arg('dir', 'dist');
|
|
40
|
+
const endpoint = arg('endpoint', process.env.AURALYTICS_ENDPOINT ?? 'https://api.auralytics.it').replace(/\/+$/, '');
|
|
41
|
+
if (!/^sk_/.test(key)) throw new Error('manca AURALYTICS_SECRET_KEY (sk_…)');
|
|
42
|
+
if (!/^[A-Za-z0-9._+@-]{1,100}$/.test(release)) throw new Error('release mancante o non valida');
|
|
43
|
+
if (!/^https:\/\//.test(endpoint) && !/^http:\/\/localhost[:/]/.test(endpoint))
|
|
44
|
+
throw new Error('endpoint: serve https');
|
|
45
|
+
const files = maps(dir);
|
|
46
|
+
let failed = 0;
|
|
47
|
+
for (const file of files) {
|
|
48
|
+
const name = basename(file);
|
|
49
|
+
const url = `${endpoint}/sm/v1/upload?release=${encodeURIComponent(release)}&file=${encodeURIComponent(name)}`;
|
|
50
|
+
let status = 0;
|
|
51
|
+
for (let attempt = 0; attempt < 4; attempt++) {
|
|
52
|
+
const res = await fetch(url, {
|
|
53
|
+
method: 'POST',
|
|
54
|
+
headers: { authorization: `Bearer ${key}`, 'content-type': 'application/json' },
|
|
55
|
+
body: readFileSync(file),
|
|
56
|
+
}).catch(() => null);
|
|
57
|
+
status = res?.status ?? 0;
|
|
58
|
+
if (status !== 429 && status !== 503 && status !== 0) break;
|
|
59
|
+
await new Promise((r) => setTimeout(r, 1000 * 2 ** attempt));
|
|
60
|
+
}
|
|
61
|
+
if (status === 201) {
|
|
62
|
+
console.log(`ok ${name}`);
|
|
63
|
+
if (process.argv.includes('--delete')) unlinkSync(file);
|
|
64
|
+
} else {
|
|
65
|
+
failed++;
|
|
66
|
+
console.error(`non caricata ${name}: HTTP ${status}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
console.log(`${files.length - failed}/${files.length} source map caricate (release ${release})`);
|
|
70
|
+
if (failed) process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
main().catch((e) => {
|
|
74
|
+
console.error(e.message);
|
|
75
|
+
process.exit(1);
|
|
76
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Tracker } from './errors';
|
|
2
|
+
/**
|
|
3
|
+
* Misurazione avanzata (W3, come quella di GA4) e autocattura dei clic. Regole di privacy:
|
|
4
|
+
* - i **valori** dei campi non si leggono mai (moduli: solo inizio e invio, con id/nome del modulo e destinazione senza query);
|
|
5
|
+
* - un elemento (o un suo antenato) con `data-au-no-capture` è invisibile a tutto ciò che sta qui;
|
|
6
|
+
* - il testo di pulsanti e link si prende solo da `button`, `a` e ruoli di pulsante, al più 64 caratteri, ripulito (email, numeri lunghi,
|
|
7
|
+
* token), mai da campi, aree di testo o elementi modificabili;
|
|
8
|
+
* - gli indirizzi si riducono a origine e percorso.
|
|
9
|
+
*/
|
|
10
|
+
export interface EnhancedOptions {
|
|
11
|
+
scroll?: boolean;
|
|
12
|
+
outbound?: boolean;
|
|
13
|
+
downloads?: boolean;
|
|
14
|
+
siteSearch?: boolean | {
|
|
15
|
+
params?: string[];
|
|
16
|
+
};
|
|
17
|
+
forms?: boolean;
|
|
18
|
+
video?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface AutocaptureOptions {
|
|
21
|
+
/** Selettori CSS da non catturare in più ad `[data-au-no-capture]`. */
|
|
22
|
+
ignore?: string[];
|
|
23
|
+
}
|
|
24
|
+
/** La parte dell'elemento DOM che serve qui (i test passano oggetti semplici). */
|
|
25
|
+
export interface ElLike {
|
|
26
|
+
tagName: string;
|
|
27
|
+
id?: string;
|
|
28
|
+
className?: unknown;
|
|
29
|
+
parentElement?: ElLike | null;
|
|
30
|
+
getAttribute(name: string): string | null;
|
|
31
|
+
hasAttribute?(name: string): boolean;
|
|
32
|
+
textContent?: string | null;
|
|
33
|
+
}
|
|
34
|
+
/** `true` se l'elemento o un suo antenato chiede di non essere catturato. */
|
|
35
|
+
export declare function optedOut(el: ElLike | null | undefined): boolean;
|
|
36
|
+
/** Un selettore corto e leggibile, dall'elemento verso l'alto (al più 4 livelli; si ferma a un id stabile). */
|
|
37
|
+
export declare function selectorOf(el: ElLike): string;
|
|
38
|
+
/** L'elemento «cliccabile» più vicino (al più 5 livelli sopra il bersaglio). */
|
|
39
|
+
export declare function clickableOf(target: ElLike | null): ElLike | null;
|
|
40
|
+
/** Le proprietà dell'evento `$autocapture` per un clic (o `null` se non si cattura). */
|
|
41
|
+
export declare function autocaptureProps(target: ElLike | null, base: string): Record<string, string> | null;
|
|
42
|
+
/** Un link verso un altro sito (o un file da scaricare): le proprietà dell'evento, o `null`. */
|
|
43
|
+
export declare function linkEvent(href: string, pageHref: string, opts: {
|
|
44
|
+
outbound: boolean;
|
|
45
|
+
downloads: boolean;
|
|
46
|
+
}): {
|
|
47
|
+
event: string;
|
|
48
|
+
props: Record<string, string>;
|
|
49
|
+
} | null;
|
|
50
|
+
/** Il termine di ricerca nel sito dall'indirizzo della pagina (parametri `q`, `s`, `search`, `query`), ripulito. */
|
|
51
|
+
export declare function siteSearchTerm(href: string, params?: string[]): string | null;
|
|
52
|
+
/** Le soglie di scorrimento raggiunte (25, 50, 75, 90) dato quanto si è visto della pagina (0–1). */
|
|
53
|
+
export declare function scrollMarks(fraction: number, already: Set<number>): number[];
|
|
54
|
+
/** Misurazione avanzata. Restituisce la funzione per spegnerla. */
|
|
55
|
+
export declare function installEnhanced(client: Tracker, win: Window, opts?: EnhancedOptions): () => void;
|
|
56
|
+
/** Autocattura dei clic su pulsanti e link (`$autocapture` con selettore, tag e testo ripulito). */
|
|
57
|
+
export declare function installAutocapture(client: Tracker, win: Window, opts?: AutocaptureOptions): () => void;
|
package/dist/cmp.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ConsentState } from './consent';
|
|
2
|
+
type Target = {
|
|
3
|
+
consentUpdate?: (s: Partial<ConsentState>) => void;
|
|
4
|
+
} | unknown[] | undefined;
|
|
5
|
+
/** Con lo snippet non ancora pronto (`window.auralytics` è la coda) l'aggiornamento entra in coda come le altre chiamate. */
|
|
6
|
+
export declare function startCmp(names: string, target: () => Target): void;
|
|
7
|
+
export {};
|
package/dist/cmp.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(()=>{var v=["analytics_storage","ad_storage","ad_user_data","ad_personalization"];function R(n,t){let o={};for(let e of v){let a=String(n?.[e]).toLowerCase();a==="granted"||a==="denied"?o[e]=a:t&&(o[e]=t)}return o}function m(n,t){let o=n?"granted":"denied",e=t?"granted":"denied";return{analytics_storage:o,ad_storage:e,ad_user_data:e,ad_personalization:e}}function l(n){return{win:n?.win??(typeof window<"u"?window:globalThis),setTimeout:n?.setTimeout??((t,o)=>globalThis.setTimeout(t,o)),clearTimeout:n?.clearTimeout??(t=>globalThis.clearTimeout(t))}}var F=1e4;function I(n,t,o,e=F){let a,r=!1,s=0,i=()=>{if(r)return;let c=!1;try{c=t()}catch{c=!1}if(c){r=!0;try{o()}catch{}return}s>=e||(s+=100,a=n.setTimeout(i,100))};return i(),()=>{r=!0,a!==void 0&&n.clearTimeout(a)}}function G(n,t=[1,8,9],o,e=!1){let a=u=>u?"granted":"denied";if(n.gdprApplies===!1&&e)return{analytics_storage:"granted",ad_storage:"granted",ad_user_data:"granted",ad_personalization:"granted"};let r=n.publisher?.consents,s=o===void 0&&!!r&&Object.keys(r).length>0,i=o===void 0||n.vendor?.consents?.[o]===!0,c=(...u)=>i&&u.every(d=>(s?r?.[d]:n.purpose?.consents?.[d])===!0);return{analytics_storage:a(t.length>0&&c(...t)),ad_storage:a(c(1)),ad_user_data:a(c(1,7)),ad_personalization:a(c(3,4))}}function _(n={}){let t=n.analyticsPurposes?.length?n.analyticsPurposes:[1,8,9];return{name:"tcf",subscribe(o,e){let a=l(e),r,s,i=!1,c=(d,p)=>{i||!p||!d||(typeof d.listenerId=="number"&&(s=d.listenerId),!(d.eventStatus!=="tcloaded"&&d.eventStatus!=="useractioncomplete")&&o(G(d,t,n.vendorId,n.trustGdprApplies===!0)))},u=I(a,()=>typeof a.win.__tcfapi=="function",()=>{r=a.win.__tcfapi,r("addEventListener",2,c)},n.timeoutMs);return()=>{if(i=!0,u(),r&&s!==void 0)try{r("removeEventListener",2,()=>{},s)}catch{}}}}}function k(n,t=4,o=5){if(!n||typeof n!="object")return null;let e=n;return e.purposes&&typeof e.purposes=="object"&&Object.keys(e.purposes).length>0?m(e.purposes[t]===!0,e.purposes[o]===!0):typeof e.consent=="boolean"?m(e.consent,e.consent):null}var T=["onPreferenceExpressed","onConsentRead","onConsentGiven","onConsentRejected"];function h(n={}){let t=n.analyticsPurpose??4,o=n.adsPurpose??5,e=n.pollMs??2e3;return{name:"iubenda",subscribe(a,r){let s=l(r),i="",c=!1,u,d=f=>{if(c||!f)return;let y=JSON.stringify(f);y!==i&&(i=y,a(f))},p=()=>{let f=s.win._iub?.cs;try{let y=f?.api?.getPreferences?.();if(y)return y}catch{}return f?.consent},b={},C;try{let f=s.win._iub=s.win._iub||[],y=f.csConfiguration=f.csConfiguration||{},O=C=y.callback=y.callback||{};b=Object.fromEntries(T.map(g=>[g,O[g]]));for(let g of T){let S=b[g];O[g]=function(...P){try{if(g==="onPreferenceExpressed")d(k(P[0],t,o)??k(p(),t,o));else if(g==="onConsentRead")d(k(p(),t,o));else{let D=s.win._iub?.csConfiguration?.perPurposeConsent===!0,L=g==="onConsentGiven"&&!D;d(k(p(),t,o)??m(L,L))}}catch{}return typeof S=="function"?S.apply(this,P):void 0}}}catch{}let w=()=>{if(!c){try{d(k(p(),t,o))}catch{}e>0&&(u=s.setTimeout(w,e))}};return w(),()=>{if(c=!0,u!==void 0&&s.clearTimeout(u),C)for(let f of T)C[f]=b[f]}}}}var M=["CookiebotOnConsentReady","CookiebotOnAccept","CookiebotOnDecline","CookiebotOnLoad"];function x(n={}){let t=n.analyticsCategory??"statistics",o=n.adsCategory??"marketing";return{name:"cookiebot",subscribe(e,a){let r=l(a),s=()=>{try{let i=r.win.Cookiebot?.consent;i&&typeof i=="object"&&e(m(i[t]===!0,i[o]===!0))}catch{}};try{for(let i of M)r.win.addEventListener?.(i,s)}catch{}return s(),()=>{try{for(let i of M)r.win.removeEventListener?.(i,s)}catch{}}}}}function V(n){return Array.isArray(n)?n.filter(t=>typeof t=="string"):typeof n=="string"?n.split(",").filter(Boolean):[]}function A(n={}){let t=n.analyticsGroup??"C0002",o=n.adsGroup??"C0004";return{name:"onetrust",subscribe(e,a){let r=l(a),s=c=>{let u=V(c);u.length&&e(m(u.includes(t),u.includes(o)))},i=c=>{try{let u=c.detail;s(Array.isArray(u)?u:r.win.OnetrustActiveGroups)}catch{}};try{r.win.addEventListener?.("OneTrustGroupsUpdated",i),r.win.OneTrust&&s(r.win.OnetrustActiveGroups)}catch{}return()=>{try{r.win.removeEventListener?.("OneTrustGroupsUpdated",i)}catch{}}}}}function E(){return{name:"gcm",subscribe(n,t){let o=l(t),e=!1,a=!1,r=u=>{if(e||!u||typeof u!="object")return;let d=u;if(d[0]!=="consent")return;let p=d[1],b=d[2];if(p!=="default"&&p!=="update"||!b||typeof b!="object"||p==="default"&&(a||b.region!==void 0))return;p==="update"&&(a=!0);let C=R(b);if(p==="default")for(let w of v)C[w]==="granted"&&delete C[w];Object.keys(C).length&&n(C)},s;try{s=o.win.dataLayer=Array.isArray(o.win.dataLayer)?o.win.dataLayer:[]}catch{return()=>{}}for(let u of Array.from(s))r(u);let i=s.push,c=function(...u){let d=i.apply(this,u);for(let p of u)try{r(p)}catch{}return d};return s.push=c,()=>{e=!0,s.push===c&&(s.push=i)}}}}var N={tcf:()=>_(),iubenda:()=>h(),cookiebot:()=>x(),onetrust:()=>A(),gcm:()=>E()};function z(n,t){for(let o of n.split(",")){let e=N[o.trim().toLowerCase()];if(e)try{e().subscribe(a=>{let r=t();Array.isArray(r)?r.push(["consentUpdate",a]):r?.consentUpdate?.(a)})}catch{}}}var j=typeof document<"u"?document.currentScript:null;j?.dataset.cmp&&z(j.dataset.cmp,()=>window.auralytics);})();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ConsentAdapter } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Cookiebot (Usercentrics). Legge `window.Cookiebot.consent` (categorie `necessary`, `preferences`, `statistics`, `marketing`) al
|
|
4
|
+
* caricamento e a ogni evento `CookiebotOnConsentReady`, `CookiebotOnAccept`, `CookiebotOnDecline`, `CookiebotOnLoad` della finestra:
|
|
5
|
+
* funziona anche se Cookiebot arriva dopo l'SDK. `analytics_storage` ← `statistics`, gli stati pubblicitari ← `marketing`.
|
|
6
|
+
*/
|
|
7
|
+
export interface CookiebotOptions {
|
|
8
|
+
analyticsCategory?: string;
|
|
9
|
+
adsCategory?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function cookiebot(opts?: CookiebotOptions): ConsentAdapter;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ConsentAdapter } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Google Consent Mode v2: legge i comandi `consent` di `window.dataLayer` (quelli di `gtag('consent', 'default'|'update', {...})` e
|
|
4
|
+
* di Google Tag Manager), prima quelli già presenti e poi i nuovi (avvolge `dataLayer.push`). Regole:
|
|
5
|
+
* - i `default` con `region` si ignorano (l'SDK non sa in che regione è la persona: la scelta prudente è non applicarli);
|
|
6
|
+
* - un `default` può solo negare: i suoi `granted` si ignorano, un concesso vale solo da un `update`;
|
|
7
|
+
* - dopo il primo `update` i `default` successivi non contano più (come in Consent Mode).
|
|
8
|
+
* Se `dataLayer` non esiste, lo crea vuoto (come fa `gtag.js`).
|
|
9
|
+
*/
|
|
10
|
+
export declare function googleConsentMode(): ConsentAdapter;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './types';
|
|
2
|
+
export { tcf, tcfState, type TcfOptions, type TCData } from './tcf';
|
|
3
|
+
export { iubenda, iubendaState, type IubendaOptions } from './iubenda';
|
|
4
|
+
export { cookiebot, type CookiebotOptions } from './cookiebot';
|
|
5
|
+
export { onetrust, onetrustGroups, type OneTrustOptions } from './onetrust';
|
|
6
|
+
export { googleConsentMode } from './gcm';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ConsentAdapter, type ConsentState } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* iubenda Privacy Controls and Cookie Solution. Le finalità di iubenda: 1 necessari, 2 funzionalità, 3 esperienza, **4 misurazione**,
|
|
4
|
+
* **5 marketing**. Con le finalità per categoria (`perPurposeConsent`) `analytics_storage` ← finalità 4 e gli stati pubblicitari ← 5;
|
|
5
|
+
* senza (un solo consenso sì/no) tutti e quattro seguono quel consenso.
|
|
6
|
+
*
|
|
7
|
+
* Con `perPurposeConsent` attivo e lo stato illeggibile, `onConsentGiven` non concede niente (non si sa quali finalità).
|
|
8
|
+
* Si aggancia alle callback di `_iub.csConfiguration.callback` (`onPreferenceExpressed`, `onConsentRead`, `onConsentGiven`,
|
|
9
|
+
* `onConsentRejected`, mantenendo quelle del cliente) e legge lo stato già espresso da `_iub.cs.api`/`_iub.cs.consent`. Come
|
|
10
|
+
* rete di sicurezza (configurazione scritta dopo l'SDK, callback copiate da iubenda all'avvio) rilegge lo stato ogni 2 s, e chiama
|
|
11
|
+
* `update` solo quando cambia.
|
|
12
|
+
*/
|
|
13
|
+
export interface IubendaOptions {
|
|
14
|
+
analyticsPurpose?: number;
|
|
15
|
+
adsPurpose?: number;
|
|
16
|
+
/** Intervallo della rilettura (ms, di serie 2000; 0 = mai). */
|
|
17
|
+
pollMs?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function iubendaState(pref: unknown, analyticsPurpose?: number, adsPurpose?: number): ConsentState | null;
|
|
20
|
+
export declare function iubenda(opts?: IubendaOptions): ConsentAdapter;
|