diff --git a/app/src/app/layout.tsx b/app/src/app/layout.tsx
index 6526c56..115197e 100644
--- a/app/src/app/layout.tsx
+++ b/app/src/app/layout.tsx
@@ -1,6 +1,60 @@
import type { Metadata } from "next";
+import Script from "next/script";
import "./globals.css";
+const GA_MEASUREMENT_ID = "G-2YHG89FY0N";
+const TOOL_NAME = "policybench";
+
+const ANALYTICS_INLINE = `
+window.dataLayer = window.dataLayer || [];
+function gtag(){dataLayer.push(arguments);}
+gtag('js', new Date());
+gtag('config', '${GA_MEASUREMENT_ID}', { tool_name: '${TOOL_NAME}' });
+`;
+
+const SCROLL_INLINE = `
+(function() {
+ var TOOL_NAME = '${TOOL_NAME}';
+ if (typeof window === 'undefined' || !window.gtag) return;
+
+ var scrollFired = {};
+ window.addEventListener('scroll', function() {
+ var docHeight = document.documentElement.scrollHeight - window.innerHeight;
+ if (docHeight <= 0) return;
+ var pct = Math.floor((window.scrollY / docHeight) * 100);
+ [25, 50, 75, 100].forEach(function(m) {
+ if (pct >= m && !scrollFired[m]) {
+ scrollFired[m] = true;
+ window.gtag('event', 'scroll_depth', { percent: m, tool_name: TOOL_NAME });
+ }
+ });
+ }, { passive: true });
+
+ [30, 60, 120, 300].forEach(function(sec) {
+ setTimeout(function() {
+ if (document.visibilityState !== 'hidden') {
+ window.gtag('event', 'time_on_tool', { seconds: sec, tool_name: TOOL_NAME });
+ }
+ }, sec * 1000);
+ });
+
+ document.addEventListener('click', function(e) {
+ var link = e.target && e.target.closest ? e.target.closest('a') : null;
+ if (!link || !link.href) return;
+ try {
+ var url = new URL(link.href, window.location.origin);
+ if (url.hostname && url.hostname !== window.location.hostname) {
+ window.gtag('event', 'outbound_click', {
+ url: link.href,
+ target_hostname: url.hostname,
+ tool_name: TOOL_NAME
+ });
+ }
+ } catch (err) {}
+ });
+})();
+`;
+
const SITE_URL = "https://policybench.org";
const SITE_TITLE = "PolicyBench, by PolicyEngine";
const SITE_DESCRIPTION =
@@ -60,6 +114,16 @@ export default function RootLayout({
Skip to main content
{children}
+
+
+