-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "chore: replace gtag implementation w/ next.js" (#51)
- Loading branch information
1 parent
9a4037d
commit 5a1b728
Showing
5 changed files
with
43 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use client"; | ||
|
||
import Script from "next/script"; | ||
import * as gtag from "@/lib/gtag"; | ||
|
||
const GoogleAnalytics = () => { | ||
return ( | ||
<> | ||
<Script | ||
strategy="afterInteractive" | ||
src={`https://www.googletagmanager.com/gtag/js?id=${gtag.NEXT_PUBLIC_GA_TRACKING_ID}`} | ||
/> | ||
<Script | ||
id="gtag-init" | ||
strategy="afterInteractive" | ||
dangerouslySetInnerHTML={{ | ||
__html: ` | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
gtag('config', '${gtag.NEXT_PUBLIC_GA_TRACKING_ID}', { | ||
page_path: window.location.pathname, | ||
}); | ||
`, | ||
}} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default GoogleAnalytics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// https://stackoverflow.com/questions/77063977/implementing-google-analytics-in-nextjs-13-app-directory | ||
|
||
export const NEXT_PUBLIC_GA_TRACKING_ID: string | undefined = | ||
process.env.NEXT_PUBLIC_GA_TRACKING_ID; | ||
|
||
export const pageview = (url: string) => { | ||
(window as any).gtag("config", NEXT_PUBLIC_GA_TRACKING_ID, { | ||
page_path: url, | ||
}); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters