Skip to content

Commit

Permalink
⚗️ [Analytics] Experiment with Google Analytics (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
beefchimi authored Jan 21, 2024
1 parent b36bdf9 commit 2cc4992
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
31 changes: 5 additions & 26 deletions app/website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,17 @@
href="https://fonts.googleapis.com/css2?family=Lexend+Zetta:wght@900&display=swap"
rel="stylesheet"
/>
</head>

<body>
<div id="VueApp"></div>

<script type="module" src="/src/main.ts"></script>

<!-- Google tag (gtag.js) -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-4CCVV95VKM"
></script>
<script>
const validAddressTerms = ['beefchimi', 'earwurm'];
const address = window.location.href.toLowerCase();
const validAddress = validAddressTerms.some((term) =>
address.includes(term),
);

// Do not proceed if in local development.
if (!validAddress) return;

window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}

gtag('js', new Date());
gtag('config', 'G-4CCVV95VKM');
<script src="/ga.js"></script>
</head>

console.log('Google Analytics initialized for:', address);
</script>
<body>
<div id="VueApp"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions app/website/public/ga.js
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 2cc4992

Please sign in to comment.