Skip to content

Commit b23436f

Browse files
committed
main 🔑 add analytics cookieless
1 parent 88c91cd commit b23436f

5 files changed

Lines changed: 106 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Script from 'next/script';
2+
3+
export const GoogleAnalyticsScript = () => (
4+
<>
5+
<Script
6+
async
7+
id='google-analytics'
8+
src='https://www.googletagmanager.com/gtag/js?id=G-RRECQP6XBW'
9+
strategy='afterInteractive'
10+
/>
11+
<Script
12+
id='google-analytics-config'
13+
strategy='afterInteractive'
14+
dangerouslySetInnerHTML={{
15+
__html: `
16+
window.dataLayer = window.dataLayer || [];
17+
function gtag(){dataLayer.push(arguments);}
18+
gtag('js', new Date());
19+
gtag('config', 'G-RRECQP6XBW', {
20+
anonymize_ip: true,
21+
client_storage: 'none',
22+
allow_google_signals: false,
23+
allow_ad_personalization_signals: false
24+
});
25+
`
26+
}}
27+
/>
28+
</>
29+
);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Script from 'next/script';
2+
3+
export const GoogleTagManagerScript = () => (
4+
<>
5+
<Script
6+
id='google-tag-manager'
7+
strategy='afterInteractive'
8+
dangerouslySetInnerHTML={{
9+
__html: `
10+
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
11+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
12+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
13+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
14+
})(window,document,'script','dataLayer','GTM-5QW9TNN4');
15+
`
16+
}}
17+
/>
18+
19+
<noscript>
20+
<iframe
21+
height='0'
22+
src='https://www.googletagmanager.com/ns.html?id=GTM-5QW9TNN4'
23+
style={{ display: 'none', visibility: 'hidden' }}
24+
width='0'
25+
/>
26+
</noscript>
27+
</>
28+
);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Script from 'next/script';
2+
3+
export const YandexMetricaScript = () => (
4+
<>
5+
<Script
6+
id='yandex-metrika'
7+
strategy='afterInteractive'
8+
dangerouslySetInnerHTML={{
9+
__html: `
10+
(function(m,e,t,r,i,k,a){
11+
m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
12+
m[i].l=1*new Date();
13+
for (var j = 0; j < document.scripts.length; j++) {
14+
if (document.scripts[j].src === r) { return; }
15+
}
16+
k=e.createElement(t),a=e.getElementsByTagName(t)[0],
17+
k.async=1,k.src=r,a.parentNode.insertBefore(k,a)
18+
})(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
19+
20+
ym(102972492, "init", {
21+
clickmap:true,
22+
trackLinks:true,
23+
accurateTrackBounce:true
24+
});
25+
`
26+
}}
27+
/>
28+
<noscript>
29+
<div>
30+
<img
31+
alt=''
32+
src='https://mc.yandex.ru/watch/102972492'
33+
style={{ position: 'absolute', left: '-9999px' }}
34+
/>
35+
</div>
36+
</noscript>
37+
</>
38+
);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './GoogleAnalyticsScript/GoogleAnalyticsScript';
2+
export * from './GoogleTagManagerScript/GoogleTagManagerScript';
3+
export * from './YandexMetricaScript/YandexMetricaScript';

packages/docs/src/app/layout.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import type { ReactNode } from 'react';
33
import { RootProvider } from 'fumadocs-ui/provider';
44
import { Mulish } from 'next/font/google';
55

6+
import {
7+
GoogleAnalyticsScript,
8+
GoogleTagManagerScript,
9+
YandexMetricaScript
10+
} from './(components)/scripts';
611
import { SearchDialog } from './(components)/search';
712

813
import './global.css';
@@ -20,6 +25,9 @@ export const Layout = ({ children }: LayoutProps) => (
2025
<html className={mulish.className} lang='en' suppressHydrationWarning>
2126
<head>
2227
<link href='/google-recaptcha/metadata/favicon.ico' rel='icon' sizes='any' />
28+
<GoogleAnalyticsScript />
29+
<GoogleTagManagerScript />
30+
<YandexMetricaScript />
2331
</head>
2432
<body className='flex flex-col min-h-screen'>
2533
<RootProvider

0 commit comments

Comments
 (0)