From eebcb941f92a67025f32e9d8cbd52e7658964daa Mon Sep 17 00:00:00 2001 From: beefchimi Date: Sat, 20 Jan 2024 20:01:02 -0500 Subject: [PATCH] :alembic: [Analytics] Try moving the ga code into a public asset --- app/website/index.html | 31 +++++-------------------------- app/website/public/ga.js | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 app/website/public/ga.js diff --git a/app/website/index.html b/app/website/index.html index 0b677f0..745d91f 100644 --- a/app/website/index.html +++ b/app/website/index.html @@ -18,38 +18,17 @@ href="https://fonts.googleapis.com/css2?family=Lexend+Zetta:wght@900&display=swap" rel="stylesheet" /> - - - -
- - - + - console.log('Google Analytics initialized for:', address); - + +
+ diff --git a/app/website/public/ga.js b/app/website/public/ga.js new file mode 100644 index 0000000..963dced --- /dev/null +++ b/app/website/public/ga.js @@ -0,0 +1,24 @@ +/* eslint-disable */ + +function analytics() { + const validAddressTerms = ['github', 'beefchimi', 'earwurm']; + const address = window.location.href.toLowerCase(); + const validAddress = validAddressTerms.every((term) => + address.includes(term), + ); + + if (!validAddress) return; + + window.dataLayer = window.dataLayer || []; + + function gtag() { + dataLayer.push(arguments); + } + + gtag('js', new Date()); + gtag('config', 'G-4CCVV95VKM'); + + console.log('Google Analytics initialized for:', address); +} + +analytics();