Unverified Commit 65648ece authored by Jared Palmer's avatar Jared Palmer Committed by GitHub

Update next-google-analytics to work with .env files (#16529)

Changes the name of the environment variable to `NEXT_PUBLIC_GA_TRACKING_ID`
parent 35a90d0e
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"nextjs": { "nextjs": {
"name": "Google Analytics", "name": "Google Analytics",
"required-env": [ "required-env": [
"GA_TRACKING_ID" "NEXT_PUBLIC_GA_TRACKING_ID"
] ]
}, },
"peerDependencies": { "peerDependencies": {
......
...@@ -5,7 +5,7 @@ export default async function headTags() { ...@@ -5,7 +5,7 @@ export default async function headTags() {
<> <>
<script <script
async async
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.GA_TRACKING_ID}`} src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GA_TRACKING_ID}`}
/> />
<script <script
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{
...@@ -13,7 +13,7 @@ export default async function headTags() { ...@@ -13,7 +13,7 @@ export default async function headTags() {
window.dataLayer = window.dataLayer || []; window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);} function gtag(){dataLayer.push(arguments);}
gtag('js', new Date()); gtag('js', new Date());
gtag('config', '${process.env.GA_TRACKING_ID}'); gtag('config', '${process.env.NEXT_PUBLIC_GA_TRACKING_ID}');
`, `,
}} }}
/> />
......
export default async function initClient({ router }) { export default async function initClient({ router }) {
router.events.on('routeChangeComplete', (url) => { router.events.on('routeChangeComplete', (url) => {
setTimeout(() => { setTimeout(() => {
window.gtag('config', process.env.GA_TRACKING_ID, { window.gtag('config', process.env.NEXT_PUBLIC_GA_TRACKING_ID, {
page_location: url, page_location: url,
page_title: document.title, page_title: document.title,
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment