From eeba3fff1739610f282a84eefcc1d201c00b9708 Mon Sep 17 00:00:00 2001 From: Daniel O'Connell Date: Mon, 5 Feb 2024 16:55:55 +0100 Subject: [PATCH] Add google analitics --- .github/workflows/deploy.yml | 1 + app/root.tsx | 36 ++++++++++++++++++++++++++++++------ remix.env.d.ts | 1 + wrangler.toml.template | 3 ++- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4e5f244e..dfd10a8b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,6 +23,7 @@ jobs: | sed s/{CODA_TOKEN}/${{ secrets.CODA_TOKEN }}/ \ | sed s/{CODA_INCOMING_TOKEN}/${{ secrets.CODA_INCOMING_TOKEN }}/ \ | sed s/{CODA_WRITES_TOKEN}/${{ secrets.CODA_WRITES_TOKEN }}/ \ + | sed s/{GOOGLE_ANALYTICS_ID}/${{ secrets.GOOGLE_ANALYTICS_ID }}/ \ > wrangler.toml npm ci npm run deploy diff --git a/app/root.tsx b/app/root.tsx index 7bed402d..533fa102 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -1,14 +1,13 @@ -import {Links, LiveReload, Meta, Outlet, Scripts} from '@remix-run/react' +import {useEffect} from 'react' +import {Links, LiveReload, Meta, Outlet, Scripts, useLoaderData} from '@remix-run/react' import type {MetaFunction, LinksFunction, LoaderFunction} from '@remix-run/cloudflare' import {cssBundleHref} from '@remix-run/css-bundle' import newStyles from '~/newRoot.css' -import {useLoaderData} from '@remix-run/react' import {CachedObjectsProvider} from '~/hooks/useCachedObjects' import {questionsOnPage} from '~/hooks/stateModifiers' -import {loadQuestionDetail} from '~/server-utils/stampy' import {useTheme} from './hooks/theme' -import {useEffect} from 'react' +import {loadQuestionDetail} from '~/server-utils/stampy' /* * Transform the given text into a meta header format. @@ -98,9 +97,34 @@ export const loader = async ({request}: Parameters[0]) => { minLogo, embed, showSearch, + gaTrackingId: GOOGLE_ANALYTICS_ID, } } +const GoogleAnalytics = ({gaTrackingId}: {gaTrackingId?: string}) => { + if (!gaTrackingId) return null + return ( + <> +