Skip to content

Commit

Permalink
Merge pull request #18 from LainForge/tarun/dev
Browse files Browse the repository at this point in the history
fix: disable google analytics in dev mode
  • Loading branch information
TarunAdobe committed Nov 8, 2023
2 parents 98ff0a7 + d81463b commit 8b67490
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export const LOGO_IMAGE = {
height: 46,
};

export const MODE = process.env.NODE_ENV || "development";

export const SOCIALS: SocialObjects = [
{
name: "Github",
Expand Down
25 changes: 15 additions & 10 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import { SITE } from "@config";
import { SITE, MODE } from "@config";
import "@styles/base.css";
export interface Props {
Expand All @@ -22,6 +22,10 @@ const socialImageURL = new URL(
ogImage ? ogImage : SITE.ogImage,
Astro.url.origin
).href;
const isDev = MODE === "development";
const dynamicTitle = isDev ? "Dev" : title;
---

<!DOCTYPE html>
Expand All @@ -34,7 +38,7 @@ const socialImageURL = new URL(
<meta name="generator" content={Astro.generator} />

<!-- General Meta Tags -->
<title>{title}</title>
<title>{dynamicTitle}</title>
<meta name="title" content={title} />
<meta name="description" content={description} />
<meta name="author" content={author} />
Expand All @@ -60,20 +64,21 @@ const socialImageURL = new URL(
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,400;0,500;0,600;0,700;1,400;1,600&display=swap"
rel="stylesheet"
/>

<script is:inline src="/toggle-theme.js"></script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DCEZKXTEPN" type="text/partytown"></script>
<script type="text/partytown">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-DCEZKXTEPN');
const isDev = document.title;
if (isDev !== "Dev") {
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
console.log("sending gtag");
gtag('config', 'G-DCEZKXTEPN');
}
</script>

<script is:inline src="/toggle-theme.js"></script>
</head>
<body>
<body data-is-dev={isDev}>
<slot />
</body>
</html>

0 comments on commit 8b67490

Please sign in to comment.