-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: customize URL of Google Tag Manager #4369
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Inspired by https://github.com/LukasGentele/docusaurus-gtm-plugin (the one we were using) | ||
// and https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-google-tag-manager | ||
// But modified to support a custom URL for the tag manager script. | ||
|
||
module.exports = function pluginGoogleTagManager(_context, options) { | ||
if (process.env.NODE_ENV !== "production") { | ||
return null; | ||
} | ||
Comment on lines
+6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will prevent GTM from rendering when running locally. The plugin we're previously using doesn't do this, but it seems like the right thing to do. |
||
|
||
const { containerId, tagManagerUrl = "https://www.googletagmanager.com" } = | ||
options; | ||
return { | ||
name: "docusaurus-plugin-google-tag-manager", | ||
|
||
injectHtmlTags() { | ||
return { | ||
headTags: [ | ||
`<!-- Google Tag Manager --> | ||
<script>(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= | ||
'${tagManagerUrl}/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); | ||
})(window,document,'script','dataLayer','${containerId}');</script> | ||
<!-- End Google Tag Manager -->`, | ||
], | ||
postBodyTags: [ | ||
`<!-- Google Tag Manager (noscript) --> | ||
<noscript><iframe src="${tagManagerUrl}/ns.html?id=${containerId}" | ||
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> | ||
<!-- End Google Tag Manager (noscript) -->`, | ||
], | ||
}; | ||
}, | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what this is or why were holding on to it, but I've been meaning to delete this for a long time 😅