Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add GA conditionally

Tomas Valentaa13bf5dd3ac6
diff --git a/components/Layout.tsx b/components/Layout.tsx
index a24871ee1..d699f514f 100644
--- a/components/Layout.tsx
+++ b/components/Layout.tsx
@@ -93,22 +93,25 @@ function Layout({ children }: PropsWithChildren) {
return (
<>
- <>
- <Script
- src={`https://www.googletagmanager.com/gtag/js?id=${gtag.GA_TRACKING_ID}`}
- />
- <Script id="google-analytics">
- {`
+ {distinctID &&
+ <>
+ <Script
+ src={`https://www.googletagmanager.com/gtag/js?id=${gtag.GA_TRACKING_ID}`}
+ />
+ <Script id="google-analytics">
+ {`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${gtag.GA_TRACKING_ID}', {
page_path: window.location.pathname,
+ user_id: '${distinctID}',
});
`}
- </Script>
- </>
+ </Script>
+ </>
+ }
<style jsx global>
{`
:root {
diff --git a/utils/gtag.js b/utils/gtag.js
index aa24d1b67..e53912bf1 100644
--- a/utils/gtag.js
+++ b/utils/gtag.js
@@ -8,13 +8,3 @@ export const pageview = (url, user_id) => {
})
console.log('tracked pageview', url, user_id)
}
-
-// https://developers.google.com/analytics/devguides/collection/gtagjs/events
-export const event = ({ action, category, label, value, user_id }) => {
- window.gtag('event', action, {
- event_category: category,
- event_label: label,
- value: value,
- user_id: user_id,
- })
-}