@hagicode/hagilight-core 0.18.0 → 0.19.1-dev.185.1.a85e2a8

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.
Files changed (69) hide show
  1. package/Analytics51LA.astro +19 -3
  2. package/CookieConsent.astro +402 -0
  3. package/Footer.astro +31 -5
  4. package/FooterBrand.astro +23 -3
  5. package/GoogleAnalytics.astro +17 -2
  6. package/PostHog.astro +55 -3
  7. package/PromotoBanner.astro +3 -3
  8. package/README.md +102 -8
  9. package/dist/analytics-events.d.ts +15 -0
  10. package/dist/analytics-events.js +25 -15
  11. package/dist/consent-copy/de-DE.d.ts +2 -0
  12. package/dist/consent-copy/de-DE.js +21 -0
  13. package/dist/consent-copy/en-US.d.ts +2 -0
  14. package/dist/consent-copy/en-US.js +21 -0
  15. package/dist/consent-copy/es-ES.d.ts +2 -0
  16. package/dist/consent-copy/es-ES.js +21 -0
  17. package/dist/consent-copy/fr-FR.d.ts +2 -0
  18. package/dist/consent-copy/fr-FR.js +21 -0
  19. package/dist/consent-copy/index.d.ts +7 -0
  20. package/dist/consent-copy/index.js +31 -0
  21. package/dist/consent-copy/ja-JP.d.ts +2 -0
  22. package/dist/consent-copy/ja-JP.js +21 -0
  23. package/dist/consent-copy/ko-KR.d.ts +2 -0
  24. package/dist/consent-copy/ko-KR.js +21 -0
  25. package/dist/consent-copy/pt-BR.d.ts +2 -0
  26. package/dist/consent-copy/pt-BR.js +21 -0
  27. package/dist/consent-copy/ru-RU.d.ts +2 -0
  28. package/dist/consent-copy/ru-RU.js +21 -0
  29. package/dist/consent-copy/types.d.ts +22 -0
  30. package/dist/consent-copy/types.js +1 -0
  31. package/dist/consent-copy/zh-CN.d.ts +2 -0
  32. package/dist/consent-copy/zh-CN.js +21 -0
  33. package/dist/consent-copy/zh-Hant.d.ts +2 -0
  34. package/dist/consent-copy/zh-Hant.js +21 -0
  35. package/dist/consent-details.d.ts +29 -0
  36. package/dist/consent-details.js +41 -0
  37. package/dist/consent-gate.d.ts +47 -0
  38. package/dist/consent-gate.js +243 -0
  39. package/dist/consent-markup.d.ts +33 -0
  40. package/dist/consent-markup.js +113 -0
  41. package/dist/consent-mount.d.ts +26 -0
  42. package/dist/consent-mount.js +81 -0
  43. package/dist/consent-popup.d.ts +6 -0
  44. package/dist/consent-popup.js +203 -0
  45. package/dist/consent.d.ts +65 -0
  46. package/dist/consent.js +314 -0
  47. package/dist/entity-definition.d.ts +19 -0
  48. package/dist/entity-definition.js +23 -0
  49. package/dist/link-policy.d.ts +7 -2
  50. package/dist/link-policy.js +8 -1
  51. package/dist/links.d.ts +12 -4
  52. package/dist/links.js +16 -10
  53. package/dist/posthog-events.d.ts +95 -0
  54. package/dist/posthog-events.js +263 -0
  55. package/dist/posthog-interactions.d.ts +85 -0
  56. package/dist/posthog-interactions.js +280 -0
  57. package/dist/posthog.d.ts +25 -3
  58. package/dist/posthog.js +64 -6
  59. package/dist/promoto-analytics.d.ts +45 -0
  60. package/dist/promoto-analytics.js +92 -0
  61. package/dist/promoto-banner.js +62 -4
  62. package/dist/related-sites.json +2 -2
  63. package/dist/root-transit.d.ts +7 -1
  64. package/dist/root-transit.js +42 -1
  65. package/dist/seo.d.ts +30 -1
  66. package/dist/seo.js +93 -1
  67. package/dist/site-metadata.d.ts +11 -6
  68. package/dist/site-metadata.js +21 -8
  69. package/package.json +42 -1
@@ -1,17 +1,33 @@
1
1
  ---
2
2
  interface Props {
3
3
  siteId: string;
4
+ /**
5
+ * When true, the page carries only an inert descriptor and the consent gate loads the SDK after a grant.
6
+ * When false (the default), the SDK and `LA.init` are rendered as before.
7
+ */
8
+ consent?: boolean;
4
9
  }
5
10
 
6
- const { siteId } = Astro.props;
11
+ const { siteId, consent = false } = Astro.props;
7
12
  if (!siteId?.trim()) throw new Error('Analytics51LA requires a siteId prop.');
13
+ // Inert data for the consent gate: the site ID only, never the SDK URL or an initialization call.
14
+ const descriptor = JSON.stringify({ siteId }).replace(/</g, '\\u003c');
8
15
  ---
9
16
 
10
- {import.meta.env.PROD && (
17
+ {import.meta.env.PROD && consent && (
18
+ <script is:inline type="application/json" data-hagilight-analytics="fiftyOneLa" set:html={descriptor}></script>
19
+ )}
20
+ {import.meta.env.PROD && !consent && (
11
21
  <>
12
22
  <script is:inline charset="UTF-8" id="LA_COLLECT" src="https://sdk.51.la/js-sdk-pro.min.js"></script>
13
23
  <script is:inline define:vars={{ siteId }}>
14
- LA.init({ id: siteId, ck: siteId, autoTrack: true, hashMode: true, screenRecord: true });
24
+ LA.init({ id: siteId, ck: siteId, autoTrack: true, hashMode: true });
15
25
  </script>
16
26
  </>
17
27
  )}
28
+
29
+ <script>
30
+ if (document.querySelector('script[data-hagilight-analytics]')) {
31
+ import('./dist/consent-gate.js').then((gate) => gate.mountConsentGate());
32
+ }
33
+ </script>
@@ -0,0 +1,402 @@
1
+ ---
2
+ import { CONSENT_DESCRIPTOR_ID, consentDescriptor, renderConsentMarkup, type ConsentPopupOptions } from './dist/consent-markup.js';
3
+
4
+ interface Props {
5
+ /** The analytics providers this site enables. Mount the popup only when at least one is enabled. */
6
+ providers: ConsentPopupOptions['providers'];
7
+ /** An absolute HTTP(S) URL or a site-relative path. Omitted means the details have no privacy link. */
8
+ privacyUrl?: string;
9
+ /** Defaults to `1`. Changing it asks every visitor again. */
10
+ policyVersion?: string;
11
+ /** The page locale. Defaults to Astro's current locale, then `en-US`. */
12
+ locale?: string;
13
+ }
14
+
15
+ const { providers, privacyUrl, policyVersion, locale = Astro.currentLocale ?? 'en-US' } = Astro.props;
16
+ const options: ConsentPopupOptions = { providers, privacyUrl, policyVersion, locale };
17
+ const markup = renderConsentMarkup(options);
18
+ const descriptor = consentDescriptor(options);
19
+ ---
20
+
21
+ <script is:inline type="application/json" id={CONSENT_DESCRIPTOR_ID} set:html={descriptor}></script>
22
+ <div class="hagilight-consent-host" set:html={markup}></div>
23
+
24
+ <script>
25
+ import { mountConsentPopup } from './dist/consent-popup.js';
26
+
27
+ mountConsentPopup(document);
28
+ </script>
29
+
30
+ <style is:global>
31
+ /* Tokens follow Starlight's --sl-color-* variables and fall back to light values where a theme omits them. */
32
+ .hagilight-consent {
33
+ --hc-accent: var(--sl-color-accent, #2563eb);
34
+ --hc-bg: var(--sl-color-bg, #ffffff);
35
+ --hc-text: var(--sl-color-text, #1f2937);
36
+ --hc-muted: var(--sl-color-gray-2, color-mix(in srgb, var(--hc-text) 72%, transparent));
37
+ --hc-border: var(--sl-color-gray-5, #cbd5e1);
38
+ --hc-action-bg: var(--sl-color-text-accent, var(--sl-color-accent, #2563eb));
39
+ --hc-action-fg: var(--sl-color-black, #ffffff);
40
+ --hc-focus: var(--sl-color-accent-high, var(--sl-color-accent, #2563eb));
41
+ /* Derived: a surface tinted toward the brand, hairlines from the theme border, motion curves. */
42
+ --hc-surface: color-mix(in srgb, var(--hc-accent) 5%, var(--hc-bg));
43
+ --hc-hairline: color-mix(in srgb, var(--hc-border) 70%, transparent);
44
+ --hc-ease: cubic-bezier(0.22, 1, 0.36, 1);
45
+ --hc-spring: cubic-bezier(0.22, 1, 0.36, 1);
46
+
47
+ position: fixed;
48
+ z-index: 45;
49
+ inset-block-end: max(1rem, env(safe-area-inset-bottom, 0px));
50
+ inset-inline-end: max(1rem, env(safe-area-inset-right, 0px));
51
+ box-sizing: border-box;
52
+ width: min(24rem, calc(100vw - 2rem - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
53
+ max-height: calc(100dvh - 2rem);
54
+ overflow-y: auto;
55
+ overscroll-behavior: contain;
56
+ scrollbar-width: thin;
57
+ scrollbar-color: color-mix(in srgb, var(--hc-text) 28%, transparent) transparent;
58
+ padding: 1.25rem 1.25rem 0.5rem;
59
+ border: 0;
60
+ border-radius: 0.875rem;
61
+ background: var(--hc-surface);
62
+ color: var(--hc-text);
63
+ /* Elevation is declared once, as a shadow: a tight contact shadow under a long, soft one. */
64
+ box-shadow: 0 1px 2px rgb(0 0 0 / 0.08), 0 18px 44px -14px rgb(0 0 0 / 0.4);
65
+ font-size: 0.875rem;
66
+ line-height: 1.5;
67
+ }
68
+
69
+ /* A damped spring where linear() exists (the same curve as the promotion banner), a long ease-out elsewhere. */
70
+ @supports (animation-timing-function: linear(0, 1)) {
71
+ .hagilight-consent {
72
+ --hc-spring: linear(0, 0.066, 0.22, 0.409, 0.597, 0.761, 0.89, 0.983, 1.042, 1.073, 1.083, 1.079, 1.067, 1.052, 1.036, 1.022, 1.011, 1.002, 0.997, 0.994, 0.993, 0.993, 1);
73
+ }
74
+ }
75
+
76
+ /* Below about 36rem the panel attaches to the bottom edge, full width, with its top corners rounded. */
77
+ @media (max-width: 36rem) {
78
+ .hagilight-consent {
79
+ inset-inline: 0;
80
+ inset-block-end: 0;
81
+ width: auto;
82
+ max-width: none;
83
+ max-height: min(85dvh, calc(100dvh - 1rem));
84
+ border-radius: 0.875rem 0.875rem 0 0;
85
+ padding: 1.125rem 1rem max(0.25rem, env(safe-area-inset-bottom, 0px));
86
+ box-shadow: 0 -1px 2px rgb(0 0 0 / 0.06), 0 -14px 36px -14px rgb(0 0 0 / 0.4);
87
+ }
88
+ }
89
+
90
+ .hagilight-consent[hidden],
91
+ .hagilight-consent [hidden] {
92
+ display: none;
93
+ }
94
+
95
+ /* While the panel fades out its buttons no longer take clicks. */
96
+ .hagilight-consent[data-leaving] {
97
+ pointer-events: none;
98
+ }
99
+
100
+ .hagilight-consent ::selection {
101
+ background: color-mix(in srgb, var(--hc-accent) 28%, transparent);
102
+ color: inherit;
103
+ }
104
+
105
+ /* The one authored moment: the panel springs up, then its parts settle in order. */
106
+ .hagilight-consent:not([hidden]) {
107
+ animation: hagilight-consent-rise 0.7s var(--hc-spring) backwards;
108
+ }
109
+
110
+ .hagilight-consent:not([hidden]) .hagilight-consent__title,
111
+ .hagilight-consent:not([hidden]) .hagilight-consent__intro,
112
+ .hagilight-consent:not([hidden]) .hagilight-consent__actions,
113
+ .hagilight-consent:not([hidden]) .hagilight-consent__toggle {
114
+ animation: hagilight-consent-settle 0.55s var(--hc-ease) backwards;
115
+ }
116
+
117
+ .hagilight-consent:not([hidden]) .hagilight-consent__title { animation-delay: 0.1s; }
118
+ .hagilight-consent:not([hidden]) .hagilight-consent__intro { animation-delay: 0.16s; }
119
+ .hagilight-consent:not([hidden]) .hagilight-consent__actions { animation-delay: 0.22s; }
120
+ .hagilight-consent:not([hidden]) .hagilight-consent__toggle { animation-delay: 0.28s; }
121
+
122
+ @keyframes hagilight-consent-rise {
123
+ from { opacity: 0; transform: translateY(1.5rem) scale(0.97); }
124
+ to { opacity: 1; transform: none; }
125
+ }
126
+
127
+ @keyframes hagilight-consent-settle {
128
+ from { opacity: 0; transform: translateY(0.5rem); }
129
+ to { opacity: 1; transform: none; }
130
+ }
131
+
132
+ .hagilight-consent__title {
133
+ margin: 0;
134
+ color: var(--hc-text);
135
+ font-size: 1.0625rem;
136
+ font-weight: 600;
137
+ line-height: 1.3;
138
+ text-wrap: balance;
139
+ }
140
+
141
+ .hagilight-consent__intro {
142
+ margin: 0.375rem 0 0;
143
+ color: var(--hc-muted);
144
+ line-height: 1.55;
145
+ text-wrap: pretty;
146
+ }
147
+
148
+ /* The current choice only shows once there is one, as a small status chip beside the actions. */
149
+ .hagilight-consent__choice {
150
+ display: inline-flex;
151
+ align-items: center;
152
+ gap: 0.4375rem;
153
+ margin: 0.75rem 0 0;
154
+ padding: 0.1875rem 0.625rem 0.1875rem 0.5rem;
155
+ border-radius: 999px;
156
+ background: color-mix(in srgb, var(--hc-text) 7%, transparent);
157
+ color: var(--hc-text);
158
+ font-size: 0.75rem;
159
+ line-height: 1.4;
160
+ }
161
+
162
+ .hagilight-consent[data-state='undecided'] .hagilight-consent__choice {
163
+ display: none;
164
+ }
165
+
166
+ .hagilight-consent__choice::before {
167
+ content: '';
168
+ flex: none;
169
+ width: 0.4375rem;
170
+ height: 0.4375rem;
171
+ border-radius: 50%;
172
+ background: var(--hc-muted);
173
+ }
174
+
175
+ .hagilight-consent[data-state='granted'] .hagilight-consent__choice::before {
176
+ background: var(--hc-accent);
177
+ }
178
+
179
+ .hagilight-consent__actions {
180
+ display: grid;
181
+ grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
182
+ gap: 0.5rem;
183
+ margin-top: 1rem;
184
+ }
185
+
186
+ /* Accept and Reject share every property, so neither reads as the primary choice. Both rest as a tint and fill on hover. */
187
+ .hagilight-consent__button {
188
+ min-height: 2.75rem;
189
+ margin: 0;
190
+ padding: 0.5rem 0.875rem;
191
+ border: 1px solid color-mix(in srgb, var(--hc-action-bg) 55%, transparent);
192
+ border-radius: 0.625rem;
193
+ background: color-mix(in srgb, var(--hc-action-bg) 10%, transparent);
194
+ color: var(--hc-text);
195
+ font: inherit;
196
+ font-size: 0.875rem;
197
+ font-weight: 600;
198
+ line-height: 1.25;
199
+ text-wrap: balance;
200
+ cursor: pointer;
201
+ transition: background-color 0.18s var(--hc-ease), border-color 0.18s var(--hc-ease), color 0.18s var(--hc-ease), transform 0.18s var(--hc-ease);
202
+ }
203
+
204
+ @media (hover: hover) {
205
+ .hagilight-consent__button:hover {
206
+ border-color: var(--hc-action-bg);
207
+ background: var(--hc-action-bg);
208
+ color: var(--hc-action-fg);
209
+ }
210
+ }
211
+
212
+ .hagilight-consent__button:active {
213
+ transform: scale(0.98);
214
+ }
215
+
216
+ /* A full-width disclosure row: the label on the left, a chevron that turns as the details open. */
217
+ .hagilight-consent__toggle {
218
+ display: flex;
219
+ align-items: center;
220
+ justify-content: space-between;
221
+ gap: 0.75rem;
222
+ box-sizing: border-box;
223
+ width: 100%;
224
+ min-height: 2.5rem;
225
+ margin: 0.75rem 0 0;
226
+ padding: 0.5rem 0;
227
+ border: 0;
228
+ border-top: 1px solid var(--hc-hairline);
229
+ border-radius: 0.25rem;
230
+ background: none;
231
+ color: var(--hc-muted);
232
+ font: inherit;
233
+ font-size: 0.8125rem;
234
+ font-weight: 500;
235
+ text-align: start;
236
+ cursor: pointer;
237
+ transition: color 0.18s var(--hc-ease);
238
+ }
239
+
240
+ .hagilight-consent__toggle::after {
241
+ content: '';
242
+ flex: none;
243
+ width: 0.4375rem;
244
+ height: 0.4375rem;
245
+ border: solid currentColor;
246
+ border-width: 0 1.5px 1.5px 0;
247
+ transform: translateY(-0.125rem) rotate(45deg);
248
+ transition: transform 0.3s var(--hc-ease);
249
+ }
250
+
251
+ .hagilight-consent__toggle[aria-expanded='true']::after {
252
+ transform: translateY(0.125rem) rotate(225deg);
253
+ }
254
+
255
+ @media (hover: hover) {
256
+ .hagilight-consent__toggle:hover {
257
+ color: var(--hc-text);
258
+ }
259
+ }
260
+
261
+ .hagilight-consent__button:focus-visible,
262
+ .hagilight-consent__toggle:focus-visible,
263
+ .hagilight-consent a:focus-visible {
264
+ outline: 2px solid var(--hc-focus);
265
+ outline-offset: 2px;
266
+ }
267
+
268
+ .hagilight-consent__details {
269
+ box-sizing: border-box;
270
+ margin: 0;
271
+ padding: 0 0 0.25rem;
272
+ }
273
+
274
+ /* Categories are open sections divided by hairlines, not boxes inside a box. */
275
+ .hagilight-consent__category {
276
+ margin: 0;
277
+ padding: 0.875rem 0;
278
+ border-top: 1px solid var(--hc-hairline);
279
+ }
280
+
281
+ .hagilight-consent__category:first-child {
282
+ padding-top: 0.5rem;
283
+ border-top: 0;
284
+ }
285
+
286
+ .hagilight-consent__category h3 {
287
+ display: flex;
288
+ align-items: center;
289
+ gap: 0.5rem;
290
+ margin: 0;
291
+ color: var(--hc-text);
292
+ font-size: 0.8125rem;
293
+ font-weight: 600;
294
+ line-height: 1.3;
295
+ }
296
+
297
+ /* A filled dot is on, a hollow one is off; the analytics dot follows the visitor's choice. */
298
+ .hagilight-consent__category h3::before {
299
+ content: '';
300
+ flex: none;
301
+ box-sizing: border-box;
302
+ width: 0.5rem;
303
+ height: 0.5rem;
304
+ border: 1.5px solid var(--hc-muted);
305
+ border-radius: 50%;
306
+ }
307
+
308
+ .hagilight-consent__category--necessary h3::before,
309
+ .hagilight-consent[data-state='granted'] .hagilight-consent__category--analytics h3::before {
310
+ border-color: var(--hc-accent);
311
+ background: var(--hc-accent);
312
+ }
313
+
314
+ .hagilight-consent__category p,
315
+ .hagilight-consent__category ul {
316
+ margin: 0.375rem 0 0;
317
+ padding-inline-start: 1rem;
318
+ }
319
+
320
+ .hagilight-consent__category p,
321
+ .hagilight-consent__withdraw {
322
+ color: var(--hc-muted);
323
+ font-size: 0.8125rem;
324
+ line-height: 1.5;
325
+ text-wrap: pretty;
326
+ }
327
+
328
+ .hagilight-consent ul {
329
+ list-style: none;
330
+ }
331
+
332
+ /* Storage names are code: monospace, with the kind pushed to the far edge. */
333
+ .hagilight-consent li {
334
+ display: flex;
335
+ align-items: baseline;
336
+ justify-content: space-between;
337
+ gap: 0.75rem;
338
+ margin: 0;
339
+ padding: 0.1875rem 0;
340
+ color: var(--hc-muted);
341
+ font-size: 0.75rem;
342
+ }
343
+
344
+ .hagilight-consent li span {
345
+ flex: 0 1 auto;
346
+ text-align: end;
347
+ }
348
+
349
+ .hagilight-consent code {
350
+ color: var(--hc-text);
351
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
352
+ font-size: 0.75rem;
353
+ overflow-wrap: anywhere;
354
+ }
355
+
356
+ .hagilight-consent__withdraw {
357
+ margin: 0;
358
+ padding: 0.875rem 0 0;
359
+ border-top: 1px solid var(--hc-hairline);
360
+ }
361
+
362
+ .hagilight-consent a {
363
+ color: var(--hc-text);
364
+ font-weight: 600;
365
+ text-decoration-thickness: 1px;
366
+ text-underline-offset: 0.2em;
367
+ }
368
+
369
+ .hagilight-consent a:hover {
370
+ text-decoration-thickness: 2px;
371
+ }
372
+
373
+ .hagilight-consent__privacy {
374
+ margin: 0.5rem 0 0.5rem;
375
+ font-size: 0.8125rem;
376
+ }
377
+
378
+ /* Forced colors drop the shadow and the fills, so the panel and the dots get system-colored edges. */
379
+ @media (forced-colors: active) {
380
+ .hagilight-consent {
381
+ border: 1px solid CanvasText;
382
+ }
383
+
384
+ .hagilight-consent__button {
385
+ border-color: ButtonText;
386
+ }
387
+
388
+ .hagilight-consent__category--necessary h3::before,
389
+ .hagilight-consent[data-state='granted'] .hagilight-consent__category--analytics h3::before {
390
+ border-color: CanvasText;
391
+ background: CanvasText;
392
+ }
393
+ }
394
+
395
+ @media (prefers-reduced-motion: reduce) {
396
+ .hagilight-consent,
397
+ .hagilight-consent * {
398
+ animation: none !important;
399
+ transition: none !important;
400
+ }
401
+ }
402
+ </style>
package/Footer.astro CHANGED
@@ -5,6 +5,7 @@ import { siteLinkGaAttributes } from './dist/analytics-events.js';
5
5
  import { resolveSiteLinks, type SiteLinksOptions } from './dist/links.js';
6
6
  import { resolveRssFooterLinks } from './dist/rss-footer-context.js';
7
7
  import { buildInfoFromLocals, buildInfoItems, type BuildInfo } from './dist/build-info.js';
8
+ import { resolveConsentCopy } from './dist/consent-copy/index.js';
8
9
 
9
10
  interface Props {
10
11
  locale?: string;
@@ -14,17 +15,21 @@ interface Props {
14
15
  avatar?: boolean;
15
16
  /** Swap the avatar for one random pool entry per page view. Defaults to `true`. */
16
17
  randomAvatar?: boolean;
18
+ /** Adds the "Cookie settings" entry. Set only when the site mounts the consent popup. Defaults to `false`. */
19
+ consent?: boolean;
17
20
  }
18
21
 
19
- const { locale: propLocale, links, buildInfo: propBuildInfo, avatar, randomAvatar } = Astro.props;
22
+ const { locale: propLocale, links, buildInfo: propBuildInfo, avatar, randomAvatar, consent = false } = Astro.props;
20
23
  const locale = propLocale ?? Astro.currentLocale ?? 'en-US';
21
24
  const footerLinks = resolveRssFooterLinks(Astro.locals, locale, links);
22
25
  const buildItems = buildInfoItems(propBuildInfo ?? buildInfoFromLocals(Astro.locals));
26
+ const consentCopy = resolveConsentCopy(propLocale ?? Astro.currentLocale ?? 'en-US');
23
27
  const sitemapOverride = footerLinks.overrides?.sitemap;
28
+ // Without a declared siteUrl, the page's own Astro site excludes its catalog entry.
29
+ const siteUrl = footerLinks.siteUrl ?? Astro.site?.href;
24
30
  const resolvedLinks = resolveSiteLinks(locale, {
25
31
  ...footerLinks,
26
- // Without a declared siteUrl, the page's own Astro site excludes its catalog entry.
27
- siteUrl: footerLinks.siteUrl ?? Astro.site?.href,
32
+ siteUrl,
28
33
  overrides: {
29
34
  ...footerLinks.overrides,
30
35
  sitemap: {
@@ -36,7 +41,14 @@ const resolvedLinks = resolveSiteLinks(locale, {
36
41
  ---
37
42
 
38
43
  <footer class="hagilight-footer">
39
- <FooterBrand locale={resolvedLinks.locale} links={resolvedLinks.quick} avatar={avatar} randomAvatar={randomAvatar} />
44
+ <FooterBrand
45
+ locale={resolvedLinks.locale}
46
+ links={resolvedLinks.quick}
47
+ avatar={avatar}
48
+ randomAvatar={randomAvatar}
49
+ siteId={links?.siteId}
50
+ siteUrl={siteUrl}
51
+ />
40
52
  <div class="hagilight-footer__sections">
41
53
  {resolvedLinks.relatedSites.length > 0 && (
42
54
  <section>
@@ -98,6 +110,9 @@ const resolvedLinks = resolveSiteLinks(locale, {
98
110
  aria-label={link.ariaLabel}
99
111
  >{link.label}</a>
100
112
  ))}
113
+ {consent && (
114
+ <button type="button" class="hagilight-footer__consent" data-consent-preferences>{consentCopy.footerEntry}</button>
115
+ )}
101
116
  </nav>
102
117
  <p class="hagilight-footer__copyright">
103
118
  <Copyright name="HagiCode" />
@@ -125,7 +140,7 @@ const resolvedLinks = resolveSiteLinks(locale, {
125
140
  .hagilight-footer {
126
141
  border-top: 1px solid var(--hagilight-footer-border, currentColor);
127
142
  color: var(--hagilight-footer-color, inherit);
128
- padding: 1.5rem 1rem 1rem;
143
+ padding: 1.5rem 1rem calc(1rem + var(--hagilight-consent-clearance, 0px));
129
144
  }
130
145
 
131
146
  .hagilight-footer__sections {
@@ -170,6 +185,17 @@ const resolvedLinks = resolveSiteLinks(locale, {
170
185
  outline-offset: 0.2rem;
171
186
  }
172
187
 
188
+ .hagilight-footer__consent {
189
+ margin: 0;
190
+ padding: 0;
191
+ border: 0;
192
+ background: none;
193
+ color: inherit;
194
+ font: inherit;
195
+ text-decoration: underline;
196
+ cursor: pointer;
197
+ }
198
+
173
199
  .hagilight-footer__filings {
174
200
  display: flex;
175
201
  flex-wrap: wrap;
package/FooterBrand.astro CHANGED
@@ -2,6 +2,7 @@
2
2
  import { siteLinkGaAttributes } from './dist/analytics-events.js';
3
3
  import type { SiteLink } from './dist/links.js';
4
4
  import { pickFooterBrandLinks, resolveFooterBrand } from './dist/footer-brand.js';
5
+ import { withCampaignUtm } from './dist/link-policy.js';
5
6
  import { footerAvatarImageAttributes, resolveFooterAvatarOptions } from './dist/footer-avatar.js';
6
7
  import { randomPoolAttribute, randomPoolFromManifest } from './dist/random-image.js';
7
8
  import avatarAvif from './assets/footer/avatar.avif';
@@ -18,11 +19,30 @@ interface Props {
18
19
  avatar?: boolean;
19
20
  /** Deal the avatar as a fan of three random cat heads that turns through six per page view. Defaults to `true`. */
20
21
  randomAvatar?: boolean;
22
+ /** Identifies the hosting site in campaign tags; without it the brand links stay untagged. */
23
+ siteId?: string;
24
+ /** The hosting site's URL, used only to recognise same-origin destinations that must stay untagged. */
25
+ siteUrl?: string;
21
26
  }
22
27
 
23
- const { locale, links, avatar, randomAvatar } = Astro.props;
28
+ const { locale, links, avatar, randomAvatar, siteId, siteUrl } = Astro.props;
24
29
  const brand = resolveFooterBrand(locale);
25
30
  const { primary, secondary } = pickFooterBrandLinks(links);
31
+ const siteOrigin = (() => {
32
+ try {
33
+ return siteUrl ? new URL(siteUrl).origin : undefined;
34
+ } catch {
35
+ return undefined;
36
+ }
37
+ })();
38
+ // Re-tagged from the untagged destination, so the brand block's content reads `footer_brand`, not `footer`.
39
+ const brandHref = (link: (typeof primary) | undefined) => link && withCampaignUtm(link.untaggedHref ?? link.href, {
40
+ siteId,
41
+ medium: 'footer',
42
+ campaign: link.id,
43
+ content: 'footer_brand',
44
+ origin: siteOrigin,
45
+ });
26
46
  const avatarOptions = resolveFooterAvatarOptions({ avatar, randomAvatar });
27
47
  const avatarPool = avatarOptions.randomAvatar ? randomPoolFromManifest(avatarManifest.pool) : undefined;
28
48
  ---
@@ -46,7 +66,7 @@ const avatarPool = avatarOptions.randomAvatar ? randomPoolFromManifest(avatarMan
46
66
  {primary && (
47
67
  <a
48
68
  class="hagilight-brand__primary"
49
- href={primary.href}
69
+ href={brandHref(primary)}
50
70
  target={primary.target}
51
71
  rel={primary.rel}
52
72
  aria-label={primary.ariaLabel}
@@ -61,7 +81,7 @@ const avatarPool = avatarOptions.randomAvatar ? randomPoolFromManifest(avatarMan
61
81
  {secondary && (
62
82
  <a
63
83
  class="hagilight-brand__secondary"
64
- href={secondary.href}
84
+ href={brandHref(secondary)}
65
85
  target={secondary.target}
66
86
  rel={secondary.rel}
67
87
  aria-label={secondary.ariaLabel}
@@ -1,9 +1,14 @@
1
1
  ---
2
2
  interface Props {
3
3
  measurementId: string;
4
+ /**
5
+ * When true, the page carries only an inert descriptor and the consent gate loads gtag.js after a grant.
6
+ * When false (the default), the static loader is rendered as before.
7
+ */
8
+ consent?: boolean;
4
9
  }
5
10
 
6
- const { measurementId } = Astro.props;
11
+ const { measurementId, consent = false } = Astro.props;
7
12
  if (!measurementId?.trim()) throw new Error('GoogleAnalytics requires a measurementId prop.');
8
13
  const scriptUrl = `https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(measurementId)}`;
9
14
  // Astro wraps a script that receives template variables in an IIFE, which would keep gtag out of
@@ -14,9 +19,14 @@ const initScript = [
14
19
  "window.gtag('js', new Date());",
15
20
  `window.gtag('config', ${JSON.stringify(measurementId).replace(/</g, '\\u003c')});`,
16
21
  ].join('\n');
22
+ // Inert data for the consent gate: the ID only, never an executable loader or a provider URL.
23
+ const descriptor = JSON.stringify({ measurementId }).replace(/</g, '\\u003c');
17
24
  ---
18
25
 
19
- {import.meta.env.PROD && (
26
+ {import.meta.env.PROD && consent && (
27
+ <script is:inline type="application/json" data-hagilight-analytics="googleAnalytics" set:html={descriptor}></script>
28
+ )}
29
+ {import.meta.env.PROD && !consent && (
20
30
  <>
21
31
  <script async src={scriptUrl}></script>
22
32
  <script is:inline set:html={initScript}></script>
@@ -27,4 +37,9 @@ const initScript = [
27
37
  import { installGaEventTracking } from './dist/analytics-events.js';
28
38
 
29
39
  installGaEventTracking();
40
+ // Silent while gtag is undefined (before a grant): a tracked click is navigated, never sent.
41
+ // Consent-on pages carry descriptors; the gate starts from the grant, never from page load.
42
+ if (document.querySelector('script[data-hagilight-analytics]')) {
43
+ import('./dist/consent-gate.js').then((gate) => gate.mountConsentGate());
44
+ }
30
45
  </script>
package/PostHog.astro CHANGED
@@ -1,11 +1,63 @@
1
1
  ---
2
- import { posthogInitScript } from './dist/posthog.js';
2
+ import corePackage from './package.json';
3
+ import { DEFAULT_POSTHOG_API_KEY, posthogInitScript } from './dist/posthog.js';
3
4
 
4
5
  interface Props {
5
6
  apiKey?: string;
7
+ /** Defaults to the site URL's hostname. Starlight passes `links.siteId` when it is set. */
8
+ siteId?: string;
9
+ /** The integration that renders this component. */
10
+ framework?: 'astro' | 'starlight' | 'docusaurus';
11
+ /** The integration's package version. Defaults to this package's version. */
12
+ version?: string;
13
+ /** A build-time page type from the page's vocabulary; absent falls back to the page-type meta element. */
14
+ pageType?: 'home' | 'docs' | 'blog' | 'compare' | '404' | 'other';
15
+ /**
16
+ * When true, the page carries only an inert descriptor and the consent gate injects the same loader after a grant.
17
+ * The click listener is installed from the post-grant hook. When false (the default), PostHog renders as before.
18
+ */
19
+ consent?: boolean;
20
+ /** `zero-results` allows the search text to be sent for searches with no results. Defaults to `off`. */
21
+ searchQuery?: 'off' | 'zero-results';
6
22
  }
7
23
 
8
- const script = posthogInitScript(Astro.props.apiKey);
24
+ const { apiKey, siteId, framework = 'astro', version = corePackage.version, pageType, consent = false, searchQuery } = Astro.props;
25
+ const script = posthogInitScript(apiKey, {
26
+ siteId: siteId ?? Astro.site?.hostname,
27
+ framework,
28
+ version,
29
+ pageType,
30
+ }, { searchQuery });
31
+ // Inert data for the consent gate: the key and the unchanged loader, which runs only after a grant.
32
+ const descriptor = JSON.stringify({ apiKey: apiKey ?? DEFAULT_POSTHOG_API_KEY, loader: script }).replace(/</g, '\\u003c');
9
33
  ---
10
34
 
11
- {import.meta.env.PROD && <script is:inline set:html={script}></script>}
35
+ {import.meta.env.PROD && consent && (
36
+ <script is:inline type="application/json" data-hagilight-analytics="posthog" set:html={descriptor}></script>
37
+ )}
38
+ {import.meta.env.PROD && !consent && <script is:inline set:html={script}></script>}
39
+
40
+ <script>
41
+ import { installPostHogClickTracking } from './dist/posthog-events.js';
42
+ import { installPostHogInteractions, installPromotionImpression } from './dist/posthog-interactions.js';
43
+
44
+ // Every listener that reports to PostHog installs together, and only once PostHog may start.
45
+ const installPostHogListeners = () => {
46
+ installPostHogClickTracking();
47
+ installPostHogInteractions();
48
+ // The end-of-article card is in the body; module scripts run after parsing, so it exists here.
49
+ installPromotionImpression();
50
+ };
51
+
52
+ if (import.meta.env.PROD) {
53
+ if (document.querySelector('script[data-hagilight-analytics="posthog"]')) {
54
+ // Listeners that need PostHog install only from the post-grant seam, never while undecided.
55
+ import('./dist/consent-gate.js').then((gate) => {
56
+ gate.onPostHogStarted(installPostHogListeners);
57
+ gate.mountConsentGate();
58
+ });
59
+ } else {
60
+ installPostHogListeners();
61
+ }
62
+ }
63
+ </script>