Skip to content

Commit

Permalink
feat: setup gtm analytic (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
urmauur authored Jul 30, 2024
1 parent deff809 commit f140f40
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GTM_ID=xxxx
28 changes: 15 additions & 13 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const withNextra = require('nextra')({
theme: 'nextra-theme-docs',
themeConfig: './theme.config.jsx'
})

const withNextra = require("nextra")({
theme: "nextra-theme-docs",
themeConfig: "./theme.config.jsx",
});

const nextConfig = {
reactStrictMode: true,
output: 'export',
images: {
formats: ['image/webp'],
unoptimized: true,
},
}
reactStrictMode: true,
output: "export",
env: {
GTM_ID: process.env.GTM_ID,
},
images: {
formats: ["image/webp"],
unoptimized: true,
},
};

module.exports = withNextra(nextConfig)
module.exports = withNextra(nextConfig);
19 changes: 19 additions & 0 deletions src/pages/_app.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,28 @@ import '@code-hike/mdx/styles.css'
import { Fragment } from "react"
import Script from "next/script"


export default function App({ Component, pageProps }) {
return (
<Fragment>
<Script
strategy="afterInteractive"
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.GTM_ID}`}
/>
<Script
id="gtag-init"
strategy="afterInteractive"
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.GTM_ID}', {
page_path: window.location.pathname,
});
`,
}}
/>
<Component {...pageProps} />
</Fragment>
)
Expand Down

0 comments on commit f140f40

Please sign in to comment.