Skip to content

Commit

Permalink
updated analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
ntotten committed Jul 27, 2024
1 parent 39424ce commit 9948f12
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
44 changes: 44 additions & 0 deletions src/app/analytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Script from "next/script";
import { GOOGLE_TAG_MANAGER_ID, KOALA_URL } from "../lib/env";

export function Analytics() {
return (
<>
{GOOGLE_TAG_MANAGER_ID && (
<>
<Script
id="gtm"
async
dangerouslySetInnerHTML={{
__html: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://ta.zuplo.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','${GOOGLE_TAG_MANAGER_ID}');`,
}}
/>
</>
)}
{GOOGLE_TAG_MANAGER_ID && (
<Script id="gtm2">
{`window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GOOGLE_TAG_MANAGER_ID}', {'allow_enhanced_conversions':true});`}
</Script>
)}
{KOALA_URL && (
<Script
id="koala-analytics"
strategy="afterInteractive"
async
dangerouslySetInnerHTML={{
__html: `
window.koalaSettings = { host: '${KOALA_URL}' };
!function(t){if(window.ko)return;window.ko=[],["identify","track","removeListeners","open","on","off","qualify","ready"].forEach(function(t){ko[t]=function(){var n=[].slice.call(arguments);return n.unshift(t),ko.push(n),ko}});var n=document.createElement("script");n.async=!0,n.setAttribute("src","${KOALA_URL}/v1/pk_32d64a435a311ccc9462e3721dba58cb3e35/sdk.js"),(document.body || document.head).appendChild(n)}();`,
}}
/>
)}
</>
);
}
31 changes: 2 additions & 29 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import localFont from "next/font/local";

import "@/styles/styles.css";
import "@/styles/tailwind.css";
import Script from "next/script";
import { Suspense } from "react";
import { GOOGLE_TAG_MANAGER_ID, KOALA_URL } from "../lib/env";
import { Analytics } from "./analytics";

const inter = Inter({
weight: ["300", "400", "500", "600", "700"],
Expand Down Expand Up @@ -52,33 +51,7 @@ export default function RootLayout({
type="image/x-icon"
href="https://cdn.zuplo.com/www/favicon.png"
/>
{GOOGLE_TAG_MANAGER_ID && (
<>
<Script
id="gtm"
async
dangerouslySetInnerHTML={{
__html: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://ta.zuplo.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','${GOOGLE_TAG_MANAGER_ID}');`,
}}
/>
</>
)}
{KOALA_URL && (
<Script
id="koala-analytics"
strategy="afterInteractive"
async
dangerouslySetInnerHTML={{
__html: `
window.koalaSettings = { host: '${KOALA_URL}' };
!function(t){if(window.ko)return;window.ko=[],["identify","track","removeListeners","open","on","off","qualify","ready"].forEach(function(t){ko[t]=function(){var n=[].slice.call(arguments);return n.unshift(t),ko.push(n),ko}});var n=document.createElement("script");n.async=!0,n.setAttribute("src","${KOALA_URL}/v1/pk_32d64a435a311ccc9462e3721dba58cb3e35/sdk.js"),(document.body || document.head).appendChild(n)}();`,
}}
/>
)}
<Analytics />
</head>
<body className="flex min-h-full bg-white dark:bg-black">
<Suspense>
Expand Down
6 changes: 4 additions & 2 deletions src/lib/env.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Analytics
export const POSTHOG_KEY = process.env.NEXT_PUBLIC_POSTHOG_KEY;
export const POSTHOG_URL = process.env.NEXT_PUBLIC_POSTHOG_URL;
export const ZARAZ_URL = process.env.NEXT_PUBLIC_ZARAZ_URL;
export const KOALA_URL = process.env.NEXT_PUBLIC_KOALA_URL;
export const REDDIT_PIXEL_ID = process.env.NEXT_PUBLIC_REDDIT_PIXEL_ID;
export const GOOGLE_TAG_MANAGER_ID =
process.env.NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID;
export const TWITTER_PIXEL_ID = process.env.NEXT_PUBLIC_TWITTER_PIXEL_ID;
export const KOALA_URL = process.env.NEXT_PUBLIC_KOALA_URL;

0 comments on commit 9948f12

Please sign in to comment.