cloudflare-next-intl 0.4.4 → 0.4.6
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/dist/src/cookie_consent/client/components/clarity_script.d.ts +10 -0
- package/dist/src/cookie_consent/client/components/clarity_script.js +27 -0
- package/dist/src/cookie_consent/client/components/cookie_consent_analytics.js +6 -18
- package/dist/src/types/types.d.ts +5 -1
- package/package.json +4 -5
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loads and initializes Microsoft Clarity. Split into its own module and
|
|
3
|
+
* loaded via `next/dynamic` from `cookie_consent_analytics.tsx` so it's
|
|
4
|
+
* only fetched as a separate chunk once actually rendered (consent granted
|
|
5
|
+
* and `secrets.clarityProjectId` set) — `@microsoft/clarity` is a real
|
|
6
|
+
* dependency of this package, so it's always installed regardless.
|
|
7
|
+
*/
|
|
8
|
+
export default function ClarityScript({ projectId }: {
|
|
9
|
+
projectId: string;
|
|
10
|
+
}): null;
|
|
@@ -0,0 +1,27 @@
|
|
|
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` so it's
|
|
13
|
+
* only fetched as a separate chunk once actually rendered (consent granted
|
|
14
|
+
* and `secrets.clarityProjectId` set) — `@microsoft/clarity` is a real
|
|
15
|
+
* dependency of this package, so it's always installed regardless.
|
|
16
|
+
*/
|
|
17
|
+
export default function ClarityScript({ projectId }) {
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
getClarityModule()
|
|
20
|
+
.then(({ default: Clarity }) => {
|
|
21
|
+
Clarity.init(projectId);
|
|
22
|
+
Clarity.consent();
|
|
23
|
+
})
|
|
24
|
+
.catch((error) => console.error(`cloudflare-next-intl: failed to load @microsoft/clarity: ${error}`));
|
|
25
|
+
}, [projectId]);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
@@ -1,7 +1,13 @@
|
|
|
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 — calling `dynamic()` inside the component body
|
|
7
|
+
// creates a brand-new component identity every render, forcing a
|
|
8
|
+
// remount. Splitting into a separate chunk keeps `@microsoft/clarity`'s
|
|
9
|
+
// import out of this module until `ClarityScript` is actually rendered.
|
|
10
|
+
const ClarityScript = dynamic(() => import('./clarity_script'));
|
|
5
11
|
/**
|
|
6
12
|
* Renders whichever analytics/ads scripts have a resolved secret, gated on
|
|
7
13
|
* consent: Google Consent Mode bootstrap always loads (defaults to
|
|
@@ -30,24 +36,6 @@ export default function CookieConsentAnalytics({ secrets }) {
|
|
|
30
36
|
const hasGoogle = Boolean(secrets.googleAnalyticsId || secrets.googleAdsId || secrets.googleAdSenseId);
|
|
31
37
|
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
38
|
}
|
|
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
39
|
/**
|
|
52
40
|
* Denies storage by default and loads the configured Google tags; the
|
|
53
41
|
* effect above sends the `update` once consent is known. Only IDs present
|
|
@@ -219,7 +219,11 @@ export interface CookieConsentAnalyticsSecrets {
|
|
|
219
219
|
googleAdsId?: string;
|
|
220
220
|
/** Google AdSense publisher ID, e.g. `"ca-pub-XXXXXXXXXXXXXXXX"`. */
|
|
221
221
|
googleAdSenseId?: string;
|
|
222
|
-
/**
|
|
222
|
+
/**
|
|
223
|
+
* Microsoft Clarity project ID. `@microsoft/clarity` is a real
|
|
224
|
+
* dependency of this package (small, so always installed) — loaded and
|
|
225
|
+
* initialized automatically once consent is granted.
|
|
226
|
+
*/
|
|
223
227
|
clarityProjectId?: string;
|
|
224
228
|
}
|
|
225
229
|
export interface FirebaseAuthRoutingConfig {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloudflare-next-intl",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"description": "Optimized Next Intl Package Special for App Router and Cloudflare",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -181,8 +181,10 @@
|
|
|
181
181
|
"url": "https://github.com/demian-ilnytskyi/cloudflare-next-intl/issues"
|
|
182
182
|
},
|
|
183
183
|
"homepage": "https://github.com/demian-ilnytskyi/cloudflare-next-intl#readme",
|
|
184
|
+
"dependencies": {
|
|
185
|
+
"@microsoft/clarity": "^1.0.2"
|
|
186
|
+
},
|
|
184
187
|
"peerDependencies": {
|
|
185
|
-
"@microsoft/clarity": ">=1.0.0",
|
|
186
188
|
"firebase": ">=10.0.0",
|
|
187
189
|
"next": ">=12.0.0",
|
|
188
190
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || >=19.0.0-rc <19.0.0 || ^19.0.0",
|
|
@@ -194,9 +196,6 @@
|
|
|
194
196
|
},
|
|
195
197
|
"firebase": {
|
|
196
198
|
"optional": true
|
|
197
|
-
},
|
|
198
|
-
"@microsoft/clarity": {
|
|
199
|
-
"optional": true
|
|
200
199
|
}
|
|
201
200
|
},
|
|
202
201
|
"devDependencies": {
|