-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add google tags for relevant pages
- Loading branch information
1 parent
9458995
commit 092b62b
Showing
7 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
wondrous-bot-admin/src/components/GoogleTag/PostBodyGoogleTag.tsx
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,39 @@ | ||
import { useEffect, useState } from "react"; | ||
import ReactDOM from "react-dom"; | ||
|
||
const PostBodyGoogleTag = () => { | ||
const [domReady, setDomReady] = useState(false); | ||
useEffect(() => { | ||
setDomReady(true); | ||
// Create a div to be the portal target | ||
const target = document.createElement("div"); | ||
target.id = "gtm-noscript-container"; | ||
document.body.appendChild(target); | ||
|
||
return () => { | ||
// Cleanup - remove the target element when the component unmounts or the page changes | ||
if (document.body.contains(target)) { | ||
document.body.removeChild(target); | ||
} | ||
}; | ||
}, []); | ||
return domReady | ||
? ReactDOM.createPortal( | ||
<> | ||
{/* Google Tag Manager (noscript) */} | ||
<noscript> | ||
<iframe | ||
src="https://www.googletagmanager.com/ns.html?id=GTM-W3DT4LQ8" | ||
height="0" | ||
width="0" | ||
style={{ display: "none", visibility: "hidden" }} | ||
></iframe> | ||
</noscript> | ||
{/* End Google Tag Manager (noscript) */} | ||
</>, | ||
document.getElementById("gtm-noscript-container") | ||
) | ||
: null; | ||
}; | ||
|
||
export default PostBodyGoogleTag; |
33 changes: 33 additions & 0 deletions
33
wondrous-bot-admin/src/components/GoogleTag/PostHeaderGoogleTag.tsx
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,33 @@ | ||
import { useEffect } from "react"; | ||
|
||
const PostHeaderGoogleTag = () => { | ||
useEffect(() => { | ||
// Define the script content | ||
const scriptContent = `(function(w,d,s,l,i){ | ||
w[l]=w[l]||[]; | ||
w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'}); | ||
var f=d.getElementsByTagName(s)[0], | ||
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:''; | ||
j.async=true; | ||
j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl; | ||
f.parentNode.insertBefore(j,f); | ||
})(window,document,'script','dataLayer','GTM-W3DT4LQ8');`; | ||
|
||
// Create script element | ||
const script = document.createElement("script"); | ||
script.textContent = scriptContent; | ||
|
||
// Append the script to the document | ||
document.head.appendChild(script); | ||
|
||
// Clean up function to remove the script when the component unmounts | ||
return () => { | ||
document.head.removeChild(script); | ||
}; | ||
}, []); | ||
|
||
// Return nothing as it doesn't render anything | ||
return null; | ||
}; | ||
|
||
export default PostHeaderGoogleTag; |
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