@prenta/sections-react 0.21.3 → 0.22.2
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 +56 -0
- package/dist/attribution-core.d.ts +29 -7
- package/dist/attribution-core.d.ts.map +1 -1
- package/dist/attribution-core.js +73 -23
- package/dist/attribution-core.js.map +1 -1
- package/dist/attribution.d.ts +21 -1
- package/dist/attribution.d.ts.map +1 -1
- package/dist/attribution.js +36 -13
- package/dist/attribution.js.map +1 -1
- package/package.json +9 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
# @actuate-media/sections-react
|
|
2
2
|
|
|
3
|
+
## 0.22.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [cb433dd]
|
|
8
|
+
- Updated dependencies [a8faa52]
|
|
9
|
+
- @prenta/core@8.25.0
|
|
10
|
+
|
|
11
|
+
## 0.22.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 1a0fa90: Scaffolded sites now record the page the visitor lands on (#1238). Only the form's own page captured attribution before, so a visitor who landed on `/?utm_source=google&utm_medium=cpc&gclid=…` and then opened `/contact` was recorded as **direct** (Astro and other multi-page sites) or **organic search** with the gclid lost (Next client-side navigation).
|
|
16
|
+
|
|
17
|
+
- The Next `(site)` layout mounts `<AttributionTracker />`.
|
|
18
|
+
- The Astro `BaseLayout.astro` calls the new `trackAttribution()` from `@prenta/sections-react/attribution` on every page.
|
|
19
|
+
- New `trackAttribution({ baseUrl?, consent? })` and `fetchAttributionConfig(baseUrl?)` in `@prenta/sections-react/attribution`. `AttributionTracker` uses the same config fetch.
|
|
20
|
+
|
|
21
|
+
Existing sites: add `<AttributionTracker />` to the public layout (Next), or `trackAttribution()` to the layout's `<script>` (Astro).
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [01f1949]
|
|
24
|
+
- Updated dependencies [453cedf]
|
|
25
|
+
- Updated dependencies [1c801d8]
|
|
26
|
+
- Updated dependencies [67669f4]
|
|
27
|
+
- Updated dependencies [42b136c]
|
|
28
|
+
- Updated dependencies [5b6d8cf]
|
|
29
|
+
- Updated dependencies [2c59934]
|
|
30
|
+
- Updated dependencies [6fe1d49]
|
|
31
|
+
- Updated dependencies [0c42fe1]
|
|
32
|
+
- @prenta/core@8.24.1
|
|
33
|
+
|
|
34
|
+
## 0.22.0
|
|
35
|
+
|
|
36
|
+
### Minor Changes
|
|
37
|
+
|
|
38
|
+
- 69c80c4: Astro form sections work again and post attribution (#1239).
|
|
39
|
+
|
|
40
|
+
- The scaffolded Astro catch-all and home page now prefetch the schema of every form section and pass it to `PageSections` (new `prefetchedForms` prop). Form sections then render as zero-JS HTML forms. Before, they rendered a React island that the page never hydrates, so visitors saw "Loading form…" forever.
|
|
41
|
+
- `BaseLayout.astro` runs `enhanceAttributionForms()` in a `<script>`, so those forms post UTMs, click IDs and the landing page.
|
|
42
|
+
- New client-safe entry `@prenta/sections-react/attribution` (no React, no consent import), for pages that do not hydrate React. Its `captureAttributionIfAllowed`, `attributionConsentAllowed` and `enhanceAttributionForms` take the consent plugin as an optional last argument, because importing the optional `@prenta/plugin-consent` there would fail a Vite build that does not have it. The functions exported from `@prenta/sections-react` itself are unchanged and still load the plugin when it is installed.
|
|
43
|
+
|
|
44
|
+
Existing Astro sites: add the same `prefetchPublicForms` call and `<script>` (see the scaffolded `[...path].astro` and `BaseLayout.astro`).
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- Updated dependencies [0b8d1b5]
|
|
49
|
+
- Updated dependencies [852c0f8]
|
|
50
|
+
- Updated dependencies [db09512]
|
|
51
|
+
- Updated dependencies [59bc714]
|
|
52
|
+
- Updated dependencies [36915ff]
|
|
53
|
+
- Updated dependencies [d27bc95]
|
|
54
|
+
- Updated dependencies [fe129f7]
|
|
55
|
+
- Updated dependencies [c198175]
|
|
56
|
+
- Updated dependencies [df649b0]
|
|
57
|
+
- @prenta/core@8.24.0
|
|
58
|
+
|
|
3
59
|
## 0.21.3
|
|
4
60
|
|
|
5
61
|
### Patch Changes
|
|
@@ -4,23 +4,45 @@ export interface AttributionCaptureOptions {
|
|
|
4
4
|
firstTouchDays?: number;
|
|
5
5
|
lastTouchHours?: number;
|
|
6
6
|
}
|
|
7
|
+
/** The part of `@prenta/plugin-consent` that attribution needs. */
|
|
8
|
+
export interface AttributionConsentApi {
|
|
9
|
+
readConsentState(): unknown;
|
|
10
|
+
waitForConsentState(): Promise<unknown>;
|
|
11
|
+
hasAnalyticsConsent(state: never): boolean;
|
|
12
|
+
}
|
|
13
|
+
/** The consent plugin, or a loader for it. `null` means it is not installed. */
|
|
14
|
+
export type AttributionConsentSource = AttributionConsentApi | (() => Promise<AttributionConsentApi | null>) | null | undefined;
|
|
7
15
|
/**
|
|
8
16
|
* Whether attribution may be captured under the site's consent state.
|
|
9
17
|
*
|
|
10
18
|
* - Plugin not installed → the site has no consent framework; resolve `true`.
|
|
11
19
|
* - Analytics already granted → resolve `true` immediately.
|
|
12
20
|
* - No decision yet → wait for the visitor's banner choice.
|
|
13
|
-
*
|
|
14
|
-
* Kept for callers that have not opted into `requireConsent`. The settings-aware
|
|
15
|
-
* path is {@link captureAttributionIfAllowed}.
|
|
16
21
|
*/
|
|
17
|
-
export declare function attributionConsentAllowed(): Promise<boolean>;
|
|
22
|
+
export declare function attributionConsentAllowed(consentSource?: AttributionConsentSource): Promise<boolean>;
|
|
18
23
|
/**
|
|
19
24
|
* Capture the current page as an attribution touch when the site settings and
|
|
20
25
|
* consent decision allow it. Resolves `false` without writing storage when
|
|
21
|
-
* recording is off or consent was not given.
|
|
26
|
+
* recording is off or consent was not given. With `requireConsent` and no
|
|
27
|
+
* consent plugin, nothing is captured.
|
|
28
|
+
*/
|
|
29
|
+
export declare function captureAttributionIfAllowed(options?: AttributionCaptureOptions, consentSource?: AttributionConsentSource): Promise<boolean>;
|
|
30
|
+
/**
|
|
31
|
+
* The site's attribution settings from `GET {baseUrl}/api/cms/public/attribution/config`
|
|
32
|
+
* (cached for 5 minutes by the CMS). `undefined` when the request fails, in
|
|
33
|
+
* which case capture uses the defaults (record on, no consent required).
|
|
34
|
+
*/
|
|
35
|
+
export declare function fetchAttributionConfig(baseUrl?: string): Promise<AttributionCaptureOptions | undefined>;
|
|
36
|
+
/**
|
|
37
|
+
* Record the current page view as an attribution touch under the site's
|
|
38
|
+
* settings. Call it on every page (once per load) so the page the visitor
|
|
39
|
+
* lands on is captured, not only the page with the form (#1238). Pages
|
|
40
|
+
* without acquisition signal never overwrite a stored touch.
|
|
22
41
|
*/
|
|
23
|
-
export declare function
|
|
42
|
+
export declare function trackAttribution(options?: {
|
|
43
|
+
baseUrl?: string;
|
|
44
|
+
consent?: AttributionConsentSource;
|
|
45
|
+
}): Promise<boolean>;
|
|
24
46
|
/**
|
|
25
47
|
* Progressive enhancement for zero-JS forms rendered by `PrentaFormHtml` /
|
|
26
48
|
* `renderPublicFormHtml`. For every `form[data-prenta-attribution]` under
|
|
@@ -28,5 +50,5 @@ export declare function captureAttributionIfAllowed(options?: AttributionCapture
|
|
|
28
50
|
* hidden `__attribution` and `__pageUrl` inputs. Without JS the form still
|
|
29
51
|
* posts, just without attribution. Safe to call more than once.
|
|
30
52
|
*/
|
|
31
|
-
export declare function enhanceAttributionForms(root?: ParentNode): void;
|
|
53
|
+
export declare function enhanceAttributionForms(root?: ParentNode, consentSource?: AttributionConsentSource): void;
|
|
32
54
|
//# sourceMappingURL=attribution-core.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attribution-core.d.ts","sourceRoot":"","sources":["../src/attribution-core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"attribution-core.d.ts","sourceRoot":"","sources":["../src/attribution-core.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,yBAAyB;IACxC,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,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|
2
|
+
* Framework-neutral attribution helpers (no React, no consent import).
|
|
3
|
+
* Published as `@prenta/sections-react/attribution` so a page that does not
|
|
4
|
+
* hydrate React (an Astro `<script>`) can call them.
|
|
5
|
+
*
|
|
6
|
+
* This module never imports `@prenta/plugin-consent`: a bundler fails the
|
|
7
|
+
* build on an import it cannot resolve, and the plugin is optional. Callers
|
|
8
|
+
* that have the plugin pass it in as {@link AttributionConsentApi}; the React
|
|
9
|
+
* entry (`attribution.ts`) does that for you.
|
|
5
10
|
*/
|
|
6
11
|
import { captureAttribution, getAttributionForSubmission } from '@prenta/core/forms/attribution';
|
|
7
12
|
import { shouldRecordAttribution } from '@prenta/core/forms/attribution-settings';
|
|
13
|
+
async function resolveConsent(source) {
|
|
14
|
+
if (!source)
|
|
15
|
+
return null;
|
|
16
|
+
if (typeof source === 'function') {
|
|
17
|
+
try {
|
|
18
|
+
return await source();
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return source;
|
|
25
|
+
}
|
|
26
|
+
async function analyticsGranted(consent) {
|
|
27
|
+
const has = consent.hasAnalyticsConsent;
|
|
28
|
+
const existing = consent.readConsentState();
|
|
29
|
+
if (existing)
|
|
30
|
+
return has(existing);
|
|
31
|
+
return has(await consent.waitForConsentState());
|
|
32
|
+
}
|
|
8
33
|
/**
|
|
9
34
|
* Whether attribution may be captured under the site's consent state.
|
|
10
35
|
*
|
|
11
36
|
* - Plugin not installed → the site has no consent framework; resolve `true`.
|
|
12
37
|
* - Analytics already granted → resolve `true` immediately.
|
|
13
38
|
* - No decision yet → wait for the visitor's banner choice.
|
|
14
|
-
*
|
|
15
|
-
* Kept for callers that have not opted into `requireConsent`. The settings-aware
|
|
16
|
-
* path is {@link captureAttributionIfAllowed}.
|
|
17
39
|
*/
|
|
18
|
-
export async function attributionConsentAllowed() {
|
|
40
|
+
export async function attributionConsentAllowed(consentSource) {
|
|
41
|
+
const consent = await resolveConsent(consentSource);
|
|
42
|
+
if (!consent)
|
|
43
|
+
return true;
|
|
19
44
|
try {
|
|
20
|
-
|
|
21
|
-
const existing = consent.readConsentState();
|
|
22
|
-
if (existing)
|
|
23
|
-
return consent.hasAnalyticsConsent(existing);
|
|
24
|
-
return consent.hasAnalyticsConsent(await consent.waitForConsentState());
|
|
45
|
+
return await analyticsGranted(consent);
|
|
25
46
|
}
|
|
26
47
|
catch {
|
|
27
48
|
return true;
|
|
28
49
|
}
|
|
29
50
|
}
|
|
30
|
-
async function consentGranted(requireConsent) {
|
|
51
|
+
async function consentGranted(requireConsent, consentSource) {
|
|
31
52
|
if (!requireConsent)
|
|
32
53
|
return true;
|
|
54
|
+
const consent = await resolveConsent(consentSource);
|
|
55
|
+
if (!consent)
|
|
56
|
+
return false;
|
|
33
57
|
try {
|
|
34
|
-
|
|
35
|
-
const existing = consent.readConsentState();
|
|
36
|
-
if (existing)
|
|
37
|
-
return consent.hasAnalyticsConsent(existing);
|
|
38
|
-
return consent.hasAnalyticsConsent(await consent.waitForConsentState());
|
|
58
|
+
return await analyticsGranted(consent);
|
|
39
59
|
}
|
|
40
60
|
catch {
|
|
41
61
|
return false;
|
|
@@ -44,14 +64,15 @@ async function consentGranted(requireConsent) {
|
|
|
44
64
|
/**
|
|
45
65
|
* Capture the current page as an attribution touch when the site settings and
|
|
46
66
|
* consent decision allow it. Resolves `false` without writing storage when
|
|
47
|
-
* recording is off or consent was not given.
|
|
67
|
+
* recording is off or consent was not given. With `requireConsent` and no
|
|
68
|
+
* consent plugin, nothing is captured.
|
|
48
69
|
*/
|
|
49
|
-
export async function captureAttributionIfAllowed(options) {
|
|
70
|
+
export async function captureAttributionIfAllowed(options, consentSource) {
|
|
50
71
|
if (typeof window === 'undefined')
|
|
51
72
|
return false;
|
|
52
73
|
const record = options?.record !== false;
|
|
53
74
|
const requireConsent = options?.requireConsent === true;
|
|
54
|
-
const granted = await consentGranted(requireConsent);
|
|
75
|
+
const granted = await consentGranted(requireConsent, consentSource);
|
|
55
76
|
if (!shouldRecordAttribution({ record, requireConsent, consentGranted: granted }))
|
|
56
77
|
return false;
|
|
57
78
|
captureAttribution({
|
|
@@ -61,6 +82,35 @@ export async function captureAttributionIfAllowed(options) {
|
|
|
61
82
|
});
|
|
62
83
|
return true;
|
|
63
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* The site's attribution settings from `GET {baseUrl}/api/cms/public/attribution/config`
|
|
87
|
+
* (cached for 5 minutes by the CMS). `undefined` when the request fails, in
|
|
88
|
+
* which case capture uses the defaults (record on, no consent required).
|
|
89
|
+
*/
|
|
90
|
+
export async function fetchAttributionConfig(baseUrl = '') {
|
|
91
|
+
try {
|
|
92
|
+
const response = await fetch(`${baseUrl}/api/cms/public/attribution/config`);
|
|
93
|
+
if (!response.ok)
|
|
94
|
+
return undefined;
|
|
95
|
+
const body = (await response.json());
|
|
96
|
+
return 'data' in body && body.data ? body.data : body;
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Record the current page view as an attribution touch under the site's
|
|
104
|
+
* settings. Call it on every page (once per load) so the page the visitor
|
|
105
|
+
* lands on is captured, not only the page with the form (#1238). Pages
|
|
106
|
+
* without acquisition signal never overwrite a stored touch.
|
|
107
|
+
*/
|
|
108
|
+
export async function trackAttribution(options = {}) {
|
|
109
|
+
if (typeof window === 'undefined')
|
|
110
|
+
return false;
|
|
111
|
+
const config = await fetchAttributionConfig(options.baseUrl);
|
|
112
|
+
return captureAttributionIfAllowed(config, options.consent);
|
|
113
|
+
}
|
|
64
114
|
function parseOptions(raw) {
|
|
65
115
|
if (!raw)
|
|
66
116
|
return undefined;
|
|
@@ -80,7 +130,7 @@ const BOUND_FLAG = 'prentaAttributionBound';
|
|
|
80
130
|
* hidden `__attribution` and `__pageUrl` inputs. Without JS the form still
|
|
81
131
|
* posts, just without attribution. Safe to call more than once.
|
|
82
132
|
*/
|
|
83
|
-
export function enhanceAttributionForms(root) {
|
|
133
|
+
export function enhanceAttributionForms(root, consentSource) {
|
|
84
134
|
if (typeof window === 'undefined' || typeof document === 'undefined')
|
|
85
135
|
return;
|
|
86
136
|
const scope = root ?? document;
|
|
@@ -91,7 +141,7 @@ export function enhanceAttributionForms(root) {
|
|
|
91
141
|
form.dataset[BOUND_FLAG] = '1';
|
|
92
142
|
const options = parseOptions(form.dataset.prentaAttribution);
|
|
93
143
|
let allowed = false;
|
|
94
|
-
void captureAttributionIfAllowed(options).then((ok) => {
|
|
144
|
+
void captureAttributionIfAllowed(options, consentSource).then((ok) => {
|
|
95
145
|
allowed = ok;
|
|
96
146
|
});
|
|
97
147
|
form.addEventListener('submit', () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attribution-core.js","sourceRoot":"","sources":["../src/attribution-core.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"attribution-core.js","sourceRoot":"","sources":["../src/attribution-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAA;AAChG,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAA;AAoBjF,KAAK,UAAU,cAAc,CAC3B,MAAgC;IAEhC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IACxB,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;QACjC,IAAI,CAAC;YACH,OAAO,MAAM,MAAM,EAAE,CAAA;QACvB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,OAA8B;IAC5D,MAAM,GAAG,GAAG,OAAO,CAAC,mBAAkD,CAAA;IACtE,MAAM,QAAQ,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAA;IAC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AAI,KAAK;gBAAE,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAC,CAAA;QAC/E,CAAC,CAAC,CAAA;IACJ,CAAC;AACH,CAAC"}
|
package/dist/attribution.d.ts
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
import { type AttributionCaptureOptions } from './attribution-core.js';
|
|
2
|
+
export type { AttributionCaptureOptions } from './attribution-core.js';
|
|
3
|
+
/**
|
|
4
|
+
* Whether attribution may be captured under the site's consent state.
|
|
5
|
+
* Plugin not installed → `true`; otherwise waits for an analytics decision.
|
|
6
|
+
* The settings-aware path is {@link captureAttributionIfAllowed}.
|
|
7
|
+
*/
|
|
8
|
+
export declare function attributionConsentAllowed(): Promise<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* Capture the current page as an attribution touch when the site settings and
|
|
11
|
+
* consent decision allow it. Resolves `false` without writing storage when
|
|
12
|
+
* recording is off or consent was not given.
|
|
13
|
+
*/
|
|
14
|
+
export declare function captureAttributionIfAllowed(options?: AttributionCaptureOptions): Promise<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* Progressive enhancement for zero-JS forms (`PrentaFormHtml`): records the
|
|
17
|
+
* page view and fills the hidden `__attribution` / `__pageUrl` inputs on
|
|
18
|
+
* submit, consent-aware. Pages without React import it from
|
|
19
|
+
* `@prenta/sections-react/attribution` instead.
|
|
20
|
+
*/
|
|
21
|
+
export declare function enhanceAttributionForms(root?: ParentNode): void;
|
|
2
22
|
/** Mounts the zero-JS form enhancer once the page hydrates. Renders nothing. */
|
|
3
23
|
export declare function FormAttributionEnhancer(): null;
|
|
4
24
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attribution.d.ts","sourceRoot":"","sources":["../src/attribution.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"attribution.d.ts","sourceRoot":"","sources":["../src/attribution.ts"],"names":[],"mappings":"AAWA,OAAO,EAKL,KAAK,yBAAyB,EAE/B,MAAM,uBAAuB,CAAA;AAE9B,YAAY,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAA;AAWtE;;;;GAIG;AACH,wBAAgB,yBAAyB,IAAI,OAAO,CAAC,OAAO,CAAC,CAE5D;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,OAAO,CAAC,OAAO,CAAC,CAEjG;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,CAE/D;AAED,gFAAgF;AAChF,wBAAgB,uBAAuB,IAAI,IAAI,CAK9C;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,OAAY,EAAE,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,IAAI,CAYpF"}
|
package/dist/attribution.js
CHANGED
|
@@ -8,8 +8,41 @@
|
|
|
8
8
|
* capture nothing when consent is required and the plugin is not installed.
|
|
9
9
|
*/
|
|
10
10
|
import { useEffect } from 'react';
|
|
11
|
-
import { captureAttributionIfAllowed, enhanceAttributionForms, } from './attribution-core.js';
|
|
12
|
-
|
|
11
|
+
import { attributionConsentAllowed as consentAllowedWith, captureAttributionIfAllowed as captureWith, enhanceAttributionForms as enhanceWith, fetchAttributionConfig, } from './attribution-core.js';
|
|
12
|
+
/** Loads the optional consent plugin; `null` when it is not installed. */
|
|
13
|
+
async function loadConsentPlugin() {
|
|
14
|
+
try {
|
|
15
|
+
return (await import('@prenta/plugin-consent'));
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Whether attribution may be captured under the site's consent state.
|
|
23
|
+
* Plugin not installed → `true`; otherwise waits for an analytics decision.
|
|
24
|
+
* The settings-aware path is {@link captureAttributionIfAllowed}.
|
|
25
|
+
*/
|
|
26
|
+
export function attributionConsentAllowed() {
|
|
27
|
+
return consentAllowedWith(loadConsentPlugin);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Capture the current page as an attribution touch when the site settings and
|
|
31
|
+
* consent decision allow it. Resolves `false` without writing storage when
|
|
32
|
+
* recording is off or consent was not given.
|
|
33
|
+
*/
|
|
34
|
+
export function captureAttributionIfAllowed(options) {
|
|
35
|
+
return captureWith(options, loadConsentPlugin);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Progressive enhancement for zero-JS forms (`PrentaFormHtml`): records the
|
|
39
|
+
* page view and fills the hidden `__attribution` / `__pageUrl` inputs on
|
|
40
|
+
* submit, consent-aware. Pages without React import it from
|
|
41
|
+
* `@prenta/sections-react/attribution` instead.
|
|
42
|
+
*/
|
|
43
|
+
export function enhanceAttributionForms(root) {
|
|
44
|
+
enhanceWith(root, loadConsentPlugin);
|
|
45
|
+
}
|
|
13
46
|
/** Mounts the zero-JS form enhancer once the page hydrates. Renders nothing. */
|
|
14
47
|
export function FormAttributionEnhancer() {
|
|
15
48
|
useEffect(() => {
|
|
@@ -26,17 +59,7 @@ export function AttributionTracker({ baseUrl = '' } = {}) {
|
|
|
26
59
|
useEffect(() => {
|
|
27
60
|
let cancelled = false;
|
|
28
61
|
void (async () => {
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
const response = await fetch(`${baseUrl}/api/cms/public/attribution/config`);
|
|
32
|
-
if (response.ok) {
|
|
33
|
-
const body = (await response.json());
|
|
34
|
-
options = 'data' in body && body.data ? body.data : body;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
options = undefined;
|
|
39
|
-
}
|
|
62
|
+
const options = await fetchAttributionConfig(baseUrl);
|
|
40
63
|
if (!cancelled)
|
|
41
64
|
await captureAttributionIfAllowed(options);
|
|
42
65
|
})();
|
package/dist/attribution.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attribution.js","sourceRoot":"","sources":["../src/attribution.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ;;;;;;;GAOG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"attribution.js","sourceRoot":"","sources":["../src/attribution.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ;;;;;;;GAOG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EACL,yBAAyB,IAAI,kBAAkB,EAC/C,2BAA2B,IAAI,WAAW,EAC1C,uBAAuB,IAAI,WAAW,EACtC,sBAAsB,GAGvB,MAAM,uBAAuB,CAAA;AAI9B,0EAA0E;AAC1E,KAAK,UAAU,iBAAiB;IAC9B,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,MAAM,CAAC,wBAAwB,CAAC,CAAqC,CAAA;IACrF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB;IACvC,OAAO,kBAAkB,CAAC,iBAAiB,CAAC,CAAA;AAC9C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAAmC;IAC7E,OAAO,WAAW,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAA;AAChD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAiB;IACvD,WAAW,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAA;AACtC,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,uBAAuB;IACrC,SAAS,CAAC,GAAG,EAAE;QACb,uBAAuB,CAAC,QAAQ,CAAC,CAAA;IACnC,CAAC,EAAE,EAAE,CAAC,CAAA;IACN,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,EAAE,OAAO,GAAG,EAAE,KAA2B,EAAE;IAC5E,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,GAAG,KAAK,CAAA;QACrB,KAAK,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,OAAO,GAAG,MAAM,sBAAsB,CAAC,OAAO,CAAC,CAAA;YACrD,IAAI,CAAC,SAAS;gBAAE,MAAM,2BAA2B,CAAC,OAAO,CAAC,CAAA;QAC5D,CAAC,CAAC,EAAE,CAAA;QACJ,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAA;QAClB,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IACb,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prenta/sections-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Public React renderer for Prenta CMS page sections — the canonical PageSection[] contract — with a consumer-controlled renderer registry.",
|
|
6
6
|
"repository": {
|
|
@@ -23,6 +23,11 @@
|
|
|
23
23
|
"import": "./dist/index.js",
|
|
24
24
|
"default": "./dist/index.js"
|
|
25
25
|
},
|
|
26
|
+
"./attribution": {
|
|
27
|
+
"types": "./dist/attribution-core.d.ts",
|
|
28
|
+
"import": "./dist/attribution-core.js",
|
|
29
|
+
"default": "./dist/attribution-core.js"
|
|
30
|
+
},
|
|
26
31
|
"./styles.css": "./dist/styles.css",
|
|
27
32
|
"./testing": {
|
|
28
33
|
"types": "./dist/testing.d.ts",
|
|
@@ -35,7 +40,7 @@
|
|
|
35
40
|
"CHANGELOG.md"
|
|
36
41
|
],
|
|
37
42
|
"dependencies": {
|
|
38
|
-
"@prenta/core": "8.
|
|
43
|
+
"@prenta/core": "8.25.0"
|
|
39
44
|
},
|
|
40
45
|
"peerDependencies": {
|
|
41
46
|
"react": ">=18.0.0",
|
|
@@ -54,12 +59,12 @@
|
|
|
54
59
|
"@tailwindcss/cli": "^4.3.5",
|
|
55
60
|
"@types/react": "^19.3.3",
|
|
56
61
|
"@types/react-dom": "^19.3.0",
|
|
57
|
-
"@vitest/coverage-v8": "
|
|
62
|
+
"@vitest/coverage-v8": "5.1.2",
|
|
58
63
|
"react": "^19.3.1",
|
|
59
64
|
"react-dom": "^19.3.1",
|
|
60
65
|
"tailwindcss": "^4.3.5",
|
|
61
66
|
"typescript": "^5.7.0",
|
|
62
|
-
"vitest": "^
|
|
67
|
+
"vitest": "^5.1.2",
|
|
63
68
|
"@prenta/plugin-consent": "1.0.2"
|
|
64
69
|
},
|
|
65
70
|
"engines": {
|