Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIL-251] Add google analytics #163

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.prod.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ NEXTAUTH_SECRET=
NEXTAUTH_URL=
GITHUB_ID=
GITHUB_SECRET=
NEXT_PUBLIC_IS_TESTNET=
NEXT_PUBLIC_IS_TESTNET=
NEXT_PUBLIC_GOOGLE_ANALYTICS_TRACKING_ID=
1 change: 1 addition & 0 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
echo "NEXT_PUBLIC_DMOB_API_URL='${{ vars.NEXT_PUBLIC_DMOB_API_URL }}'" >> .env
echo "NEXT_PUBLIC_GLIF_URL='${{ vars.NEXT_PUBLIC_GLIF_URL }}'" >> .env
echo "NEXT_PUBLIC_IS_TESTNET='${{ vars.NEXT_PUBLIC_IS_TESTNET }}'" >> .env
echo "NEXT_PUBLIC_GOOGLE_ANALYTICS_TRACKING_ID='${{ vars.NEXT_PUBLIC_GOOGLE_ANALYTICS_TRACKING_ID }}'" >> .env
echo "NEXTAUTH_URL='${{ vars.NEXTAUTH_URL }}'" >> .env
echo "NEXTAUTH_SECRET='placeholder'" >> .env
echo "GITHUB_ID='placeholder'" >> .env
Expand Down
5 changes: 5 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import '@fontsource/roboto/300.css'
import '@fontsource/roboto/400.css'
import '@fontsource/roboto/500.css'
import '@fontsource/roboto/700.css'
import Analytics from '@/components/Analytics'
import Head from 'next/head'

const inter = Inter({ subsets: ['latin'] })

Expand All @@ -26,6 +28,9 @@ export default function RootLayout({
}): JSX.Element {
return (
<html lang="en">
<Head>
<Analytics />
</Head>
<body className={inter.className + ' h-screen'}>
<ReactQueryProvider>
<ToastContainer position="top-right" autoClose={10000} />
Expand Down
21 changes: 21 additions & 0 deletions src/components/Analytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Script from 'next/script'
import { config } from '@/config'

const Analytics: React.FC = () => {
return (
<>
<Script
async
src={`https://www.googletagmanager.com/gtag/js?id=${config.gaTrackingId}`}
></Script>
<Script id="ga-script">
{`window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', '${config.gaTrackingId}');`}
</Script>
</>
)
}
export default Analytics
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const localConfig = {
glifNodeUrl:
process.env.NEXT_PUBLIC_GLIF_URL ?? 'https://api.node.glif.io/rpc/v1',
isTestnet: process.env.NEXT_PUBLIC_IS_TESTNET ?? 'true',
gaTrackingId: process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_TRACKING_ID ?? '',
}

const prodConfig = {
Expand All @@ -51,6 +52,7 @@ const prodConfig = {
dmobApiKey: process.env.NEXT_PUBLIC_DMOB_API_KEY ?? '',
glifNodeUrl: process.env.NEXT_PUBLIC_GLIF_URL ?? '',
isTestnet: process.env.NEXT_PUBLIC_IS_TESTNET ?? 'false',
gaTrackingId: process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_TRACKING_ID ?? '',
}

export const config =
Expand Down