Skip to content

Commit

Permalink
feat: use google analytics script (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardocasares authored Aug 31, 2021
1 parent 2967f88 commit 33d57e8
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 188 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"dependencies": {
"@geist-ui/react-icons": "^1.0.0",
"@genql/runtime": "2.6.0",
"@next/plugin-google-analytics": "^10.0.6",
"@next/plugin-sentry": "ricardocasares/next-plugin-sentry",
"@stitches/react": "^1.0.0",
"@vercel/fetch": "^6.1.0",
Expand Down
15 changes: 14 additions & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import { useEffect } from "react";
import { AppProps } from "next/app";
import { useRouter } from "next/router";
import { DefaultSeo } from "next-seo";
import { Providers } from "@/lib/providers";
import { Layout } from "@/components/Layout";
import { Header } from "@/components/Header";
import { Scrollable } from "@/components/Scrollable";
import { Player } from "@/components/Player";
import seoProps from "@/config/seo";
import { globalStyles } from "@/css/global";
import { pageview } from "@/lib/utils";
import seoProps from "@/config/seo";


export function BembaApp({ Component, pageProps }: AppProps) {
globalStyles();

const router = useRouter();

useEffect(() => {
const handleRouteChange = (url: string) => pageview(url);
router.events.on("routeChangeComplete", handleRouteChange);

return () => router.events.off("routeChangeComplete", handleRouteChange);
}, [router.events]);

return (
<Providers>
<Layout>
Expand Down
16 changes: 16 additions & 0 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ export default class Document extends NextDocument {
<Html lang="en">
<Head>
<style id="stitches" dangerouslySetInnerHTML={{ __html: getCssText() }} />
<script
async
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GA_TRACKING_ID}`}
/>
<script
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.NEXT_PUBLIC_GA_TRACKING_ID}', {
page_path: window.location.pathname,
});
`,
}}
/>
</Head>
<body>
<Main />
Expand Down
Loading

1 comment on commit 33d57e8

@vercel
Copy link

@vercel vercel bot commented on 33d57e8 Aug 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

Please sign in to comment.