Skip to content

Commit 5072517

Browse files
Merge pull request #482 from sei-protocol/feat/ga-gtm-migration
Replace GA with GTM - docs.sei.io
2 parents 2ef41a4 + 52bd4cc commit 5072517

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

app/layout.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import { getPageMap } from 'nextra/page-map';
44
import { Toaster } from 'sonner';
55
import { Metadata } from 'next';
6-
import Script from 'next/script';
6+
import { GoogleTagManager } from '@next/third-parties/google';
77

88
import DocsProviders from '../src/providers/DocsProviders';
99

@@ -12,6 +12,8 @@ import 'nextra-theme-docs/style.css';
1212
import './globals.css';
1313
import 'katex/dist/katex.min.css';
1414

15+
const GTM_ID = 'GTM-KKN784SR';
16+
1517
export const metadata: Metadata = {
1618
metadataBase: new URL('https://docs.sei.io'),
1719
title: {
@@ -105,19 +107,20 @@ export default async function RootLayout({ children }) {
105107
/>
106108
</head>
107109
<body style={{ width: '100%', height: '100%' }}>
110+
{/* Google Tag Manager (noscript) fallback */}
111+
<noscript>
112+
<iframe
113+
src={`https://www.googletagmanager.com/ns.html?id=${GTM_ID}`}
114+
height='0'
115+
width='0'
116+
style={{ display: 'none', visibility: 'hidden' }}
117+
title='Google Tag Manager'
118+
/>
119+
</noscript>
108120
<Toaster position='bottom-left' />
109121
<DocsProviders pageMap={await getPageMap()}>{children}</DocsProviders>
110122
</body>
111-
{/* Google Analytics: lazy-load after window load */}
112-
<Script src='https://www.googletagmanager.com/gtag/js?id=G-G33FDB53X5' strategy='lazyOnload' />
113-
<Script id='ga-init' strategy='lazyOnload'>
114-
{`
115-
window.dataLayer = window.dataLayer || [];
116-
function gtag(){dataLayer.push(arguments);}
117-
gtag('js', new Date());
118-
gtag('config', 'G-G33FDB53X5', { anonymize_ip: true });
119-
`}
120-
</Script>
123+
<GoogleTagManager gtmId={GTM_ID} />
121124
</html>
122125
);
123126
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"license": "MIT",
2525
"dependencies": {
2626
"@hcaptcha/react-hcaptcha": "^2.0.2",
27+
"@next/third-parties": "^16.1.6",
2728
"@radix-ui/themes": "^3.2.1",
2829
"@sei-js/evm": "^2.0.5",
2930
"@tabler/icons-react": "3.36.0",

src/components/FaucetRequest/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import React, { useRef, useState, useCallback } from 'react';
44
import { Button, Flex, Select } from '@radix-ui/themes';
55
import { toast } from 'sonner';
6+
import { sendGTMEvent } from '@next/third-parties/google';
67
import { IconDroplet, IconShieldCheck, IconHourglass, IconCheck, IconLoader2, IconExternalLink } from '@tabler/icons-react';
78
import { isAddress } from 'viem/utils';
89
import HCaptcha from '@hcaptcha/react-hcaptcha';
@@ -71,10 +72,7 @@ const RequestFaucetCard = () => {
7172
const messageId = responseJson.data.messageId;
7273
toast.success('Tokens requested successfully!');
7374
startPolling(messageId, setTxHash);
74-
if (typeof window !== 'undefined') {
75-
const g = (window as any).gtag as undefined | ((...args: any[]) => void);
76-
if (typeof g === 'function') g('event', 'faucetUsed', { address: destAddress });
77-
}
75+
sendGTMEvent({ event: 'faucet_used', address: destAddress });
7876
} else if (responseJson.data?.nextAllowedUseDate) {
7977
setNextUseTime(responseJson.data.nextAllowedUseDate);
8078
toast.error(`Rate limited. Try again after ${responseJson.data.nextAllowedUseDate}`);

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,13 @@
13761376
resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-16.1.5.tgz#92c0161dec3c466b120a312199a376d029b92ce2"
13771377
integrity sha512-7is37HJTNQGhjPpQbkKjKEboHYQnCgpVt/4rBrrln0D9nderNxZ8ZWs8w1fAtzUx7wEyYjQ+/13myFgFj6K2Ng==
13781378

1379+
"@next/third-parties@^16.1.6":
1380+
version "16.1.6"
1381+
resolved "https://registry.yarnpkg.com/@next/third-parties/-/third-parties-16.1.6.tgz#366980adab28f808ce6142af6b474066e2ad49da"
1382+
integrity sha512-/cLY1egaH529ylSMSK+C8dA3nWDLL4hOFR4fca9OLWWxjcNwzsbuq2pPb/tmdWL9Zj3K1nTjd1pWQoSlaDQ0VA==
1383+
dependencies:
1384+
third-party-capital "1.0.20"
1385+
13791386
"@noble/ciphers@^1.3.0":
13801387
version "1.3.0"
13811388
resolved "https://registry.yarnpkg.com/@noble/ciphers/-/ciphers-1.3.0.tgz#f64b8ff886c240e644e5573c097f86e5b43676dc"
@@ -8644,6 +8651,11 @@ text-decoder@^1.1.0:
86448651
dependencies:
86458652
b4a "^1.6.4"
86468653

8654+
third-party-capital@1.0.20:
8655+
version "1.0.20"
8656+
resolved "https://registry.yarnpkg.com/third-party-capital/-/third-party-capital-1.0.20.tgz#e218a929a35bf4d2245da9addb8ab978d2f41685"
8657+
integrity sha512-oB7yIimd8SuGptespDAZnNkzIz+NWaJCu2RMsbs4Wmp9zSDUM8Nhi3s2OOcqYuv3mN4hitXc8DVx+LyUmbUDiA==
8658+
86478659
tinyexec@^0.3.2:
86488660
version "0.3.2"
86498661
resolved "https://registry.yarnpkg.com/tinyexec/-/tinyexec-0.3.2.tgz#941794e657a85e496577995c6eef66f53f42b3d2"

0 commit comments

Comments
 (0)