cloudflare-next-intl 0.4.4 → 0.4.5
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.
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loads and initializes Microsoft Clarity. Split into its own module and
|
|
3
|
+
* loaded via `next/dynamic` from `cookie_consent_analytics.tsx` — bundlers
|
|
4
|
+
* (webpack/Turbopack) resolve every literal `import()` specifier they can
|
|
5
|
+
* reach at build time, so keeping this file's `import('@microsoft/clarity')`
|
|
6
|
+
* out of the main analytics module means consumers who never set
|
|
7
|
+
* `secrets.clarityProjectId` (and never render this component) don't need
|
|
8
|
+
* `@microsoft/clarity` (an optional peer dependency) installed at all — the
|
|
9
|
+
* dynamic-imported chunk containing this file is only built/requested the
|
|
10
|
+
* first time it's actually rendered.
|
|
11
|
+
*/
|
|
12
|
+
export default function ClarityScript({ projectId }: {
|
|
13
|
+
projectId: string;
|
|
14
|
+
}): null;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
let cachedClarityModule;
|
|
4
|
+
function getClarityModule() {
|
|
5
|
+
if (!cachedClarityModule) {
|
|
6
|
+
cachedClarityModule = import('@microsoft/clarity');
|
|
7
|
+
}
|
|
8
|
+
return cachedClarityModule;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Loads and initializes Microsoft Clarity. Split into its own module and
|
|
12
|
+
* loaded via `next/dynamic` from `cookie_consent_analytics.tsx` — bundlers
|
|
13
|
+
* (webpack/Turbopack) resolve every literal `import()` specifier they can
|
|
14
|
+
* reach at build time, so keeping this file's `import('@microsoft/clarity')`
|
|
15
|
+
* out of the main analytics module means consumers who never set
|
|
16
|
+
* `secrets.clarityProjectId` (and never render this component) don't need
|
|
17
|
+
* `@microsoft/clarity` (an optional peer dependency) installed at all — the
|
|
18
|
+
* dynamic-imported chunk containing this file is only built/requested the
|
|
19
|
+
* first time it's actually rendered.
|
|
20
|
+
*/
|
|
21
|
+
export default function ClarityScript({ projectId }) {
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
getClarityModule()
|
|
24
|
+
.then(({ default: Clarity }) => {
|
|
25
|
+
Clarity.init(projectId);
|
|
26
|
+
Clarity.consent();
|
|
27
|
+
})
|
|
28
|
+
.catch((error) => console.error(`cloudflare-next-intl: failed to load @microsoft/clarity: ${error}`));
|
|
29
|
+
}, [projectId]);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useEffect } from 'react';
|
|
4
|
+
import dynamic from 'next/dynamic';
|
|
4
5
|
import useCookieConsent from '../use_cookie_consent';
|
|
6
|
+
// Hoisted to module scope, like this package's other `dynamic()` calls —
|
|
7
|
+
// calling it inside the component body would create a new component
|
|
8
|
+
// identity every render. Deferring to a separate chunk keeps
|
|
9
|
+
// `@microsoft/clarity`'s `import()` (in `clarity_script.tsx`) out of this
|
|
10
|
+
// module, so bundlers only resolve it when `ClarityScript` is actually
|
|
11
|
+
// rendered — see that file's doc comment for why this matters.
|
|
12
|
+
const ClarityScript = dynamic(() => import('./clarity_script'));
|
|
5
13
|
/**
|
|
6
14
|
* Renders whichever analytics/ads scripts have a resolved secret, gated on
|
|
7
15
|
* consent: Google Consent Mode bootstrap always loads (defaults to
|
|
@@ -30,24 +38,6 @@ export default function CookieConsentAnalytics({ secrets }) {
|
|
|
30
38
|
const hasGoogle = Boolean(secrets.googleAnalyticsId || secrets.googleAdsId || secrets.googleAdSenseId);
|
|
31
39
|
return (_jsxs(_Fragment, { children: [hasGoogle && (_jsx("script", { id: "cookie-consent-google-consent-mode", dangerouslySetInnerHTML: { __html: googleConsentModeBootstrapScript(secrets) } })), consent === true && secrets.cloudflareBeaconToken && (_jsx("script", { defer: true, src: "https://static.cloudflareinsights.com/beacon.min.js", "data-cf-beacon": secrets.cloudflareBeaconToken })), consent === true && secrets.clarityProjectId && _jsx(ClarityScript, { projectId: secrets.clarityProjectId })] }));
|
|
32
40
|
}
|
|
33
|
-
let cachedClarityModule;
|
|
34
|
-
function getClarityModule() {
|
|
35
|
-
if (!cachedClarityModule) {
|
|
36
|
-
cachedClarityModule = import('@microsoft/clarity');
|
|
37
|
-
}
|
|
38
|
-
return cachedClarityModule;
|
|
39
|
-
}
|
|
40
|
-
function ClarityScript({ projectId }) {
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
getClarityModule()
|
|
43
|
-
.then(({ default: Clarity }) => {
|
|
44
|
-
Clarity.init(projectId);
|
|
45
|
-
Clarity.consent();
|
|
46
|
-
})
|
|
47
|
-
.catch((error) => console.error(`cloudflare-next-intl: failed to load @microsoft/clarity: ${error}`));
|
|
48
|
-
}, [projectId]);
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
41
|
/**
|
|
52
42
|
* Denies storage by default and loads the configured Google tags; the
|
|
53
43
|
* effect above sends the `update` once consent is known. Only IDs present
|