-
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.
- Loading branch information
Showing
7 changed files
with
48 additions
and
19 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
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
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,34 @@ | ||
|
||
const GA_TAG_INIT_CODE = ` | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
gtag('config', '${process.env.REACT_APP_GA_ID}', { | ||
anonymize_ip: true, | ||
cookie_flags: 'SameSite=None;Secure', | ||
}); | ||
gtag('consent', 'default', { | ||
ad_storage: 'denied' | ||
}); | ||
`; | ||
|
||
export function addAnalyticsTag(): void { | ||
const isDev = process.env.NODE_ENV === 'development'; | ||
|
||
if (process.env.REACT_APP_GA_ID && !isDev) { | ||
let gtmScript = document.createElement('script'); | ||
gtmScript.type = 'text/javascript'; | ||
gtmScript.src = `https://www.googletagmanager.com/gtag/js?id=${process.env.REACT_APP_GA_ID}`; | ||
gtmScript.async = true; | ||
|
||
document?.head?.appendChild(gtmScript)?.parentNode?.removeChild(gtmScript); | ||
|
||
let scriptTag = document.createElement('script'); | ||
scriptTag.type = 'text/javascript'; | ||
scriptTag.text = GA_TAG_INIT_CODE; | ||
|
||
document?.head?.appendChild(scriptTag)?.parentNode?.removeChild(scriptTag); | ||
} | ||
} |
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