-
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.
Browse files
Browse the repository at this point in the history
* Apply Google Analytics tracking #196 Resolve #196 * Apply Google Analytics tracking #196 Resolve #196
- Loading branch information
1 parent
270b9a0
commit fa6c4e6
Showing
3 changed files
with
257 additions
and
226 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"use client"; | ||
|
||
import { useSearchParams } from "next/navigation"; | ||
import Script from "next/script"; | ||
import React from "react"; | ||
|
||
type Props = {}; | ||
|
||
const AnalyticsScripts = (props: Props) => { | ||
const searchParams = useSearchParams(); | ||
|
||
const noTrackingQuery = searchParams.get("no-tracking"); | ||
const noTracking = noTrackingQuery | ||
? decodeURIComponent(noTrackingQuery) === "true" | ||
: false; | ||
|
||
return ( | ||
<> | ||
{process.env.NODE_ENV === "production" && !noTracking && ( | ||
<> | ||
<Script | ||
strategy="afterInteractive" | ||
src={`https://www.googletagmanager.com/gtag/js?id=G-ZXQWB7MHM7`} | ||
/> | ||
<Script id="google-analytics" strategy="afterInteractive"> | ||
{` | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
gtag('config', 'G-ZXQWB7MHM7'); | ||
`} | ||
</Script> | ||
<Script id="ms-clarity"> | ||
{` | ||
(function(c,l,a,r,i,t,y){ | ||
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)}; | ||
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i; | ||
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y); | ||
})(window, document, "clarity", "script", "n0wi3fv67g"); | ||
`} | ||
</Script> | ||
</> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default AnalyticsScripts; |
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
Oops, something went wrong.