diff --git a/components/Layout.tsx b/components/Layout.tsx
index d16e047f2..a94c4244a 100644
--- a/components/Layout.tsx
+++ b/components/Layout.tsx
@@ -2,6 +2,7 @@ import * as React from 'react'
import Head from 'next/head'
import Footer from './Footer'
import Header from './Header'
+import { GA_TRACKING_ID } from '../lib/gtag'
interface LayoutProps {
meta?: {
@@ -43,6 +44,24 @@ export default function Layout(props: LayoutProps) {
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@400;600;700&family=PT+Sans:wght@400;700&display=swap"
rel="stylesheet"
/>
+ {/* Global Site Tag (gtag.js) - Google Analytics */}
+
+
+
diff --git a/lib/gtag.js b/lib/gtag.js
new file mode 100644
index 000000000..58bf47d25
--- /dev/null
+++ b/lib/gtag.js
@@ -0,0 +1,17 @@
+export const GA_TRACKING_ID = process.env.NEXT_PUBLIC_GA_ID
+
+// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
+export const pageview = (url) => {
+ window.gtag('config', 'UA-40540747-22', {
+ page_path: url,
+ })
+}
+
+// https://developers.google.com/analytics/devguides/collection/gtagjs/events
+export const event = ({ action, category, label, value }) => {
+ window.gtag('event', action, {
+ event_category: category,
+ event_label: label,
+ value: value,
+ })
+}
\ No newline at end of file
diff --git a/pages/_app.tsx b/pages/_app.tsx
index 38dcd0cac..3d7292000 100644
--- a/pages/_app.tsx
+++ b/pages/_app.tsx
@@ -1,11 +1,22 @@
import { AppProps } from 'next/app'
+import { useEffect } from 'react'
+import { useRouter } from 'next/router'
// TODO: update these CSS imports once we settle on a CSS strategy.
import 'bootstrap/dist/css/bootstrap.css'
import '../styles/Footer.scss'
import '../styles/typography.scss'
+import * as gtag from '../lib/gtag'
-function MyApp({ Component, pageProps }: AppProps) {
+export default function MyApp({ Component, pageProps }: AppProps) {
+ const router = useRouter()
+ useEffect(() => {
+ const handleRouteChange = (url: URL) => {
+ gtag.pageview(url)
+ }
+ router.events.on('routeChangeComplete', handleRouteChange)
+ return () => {
+ router.events.off('routeChangeComplete', handleRouteChange)
+ }
+ }, [router.events])
return
-}
-
-export default MyApp
+ }
diff --git a/posts/how-to-install-sourcegraph.md b/posts/how-to-lorem-ipsum.md
similarity index 98%
rename from posts/how-to-install-sourcegraph.md
rename to posts/how-to-lorem-ipsum.md
index 79536f601..90580d440 100644
--- a/posts/how-to-install-sourcegraph.md
+++ b/posts/how-to-lorem-ipsum.md
@@ -1,5 +1,5 @@
---
-title: How to install Sourcegraph
+title: How To Lorem Ipsum
tags: [tutorial, installation]
---
diff --git a/posts/how-to-search.md b/posts/lorem-ipsum-dolor.md
similarity index 98%
rename from posts/how-to-search.md
rename to posts/lorem-ipsum-dolor.md
index d6533be2a..f71f7c438 100644
--- a/posts/how-to-search.md
+++ b/posts/lorem-ipsum-dolor.md
@@ -1,5 +1,5 @@
---
-title: How to search
+title: Lorem Ipsum Dolor Sit Amet
tags: [tutorial, search]
---