Skip to content
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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,14 @@ module.exports = {
// do not delete the following 'noIndex' line as it is modified for production
noIndex: true,
plugins: [
// ["@edno/docusaurus2-graphql-doc-generator",
// {
// schema: "http://localhost:8080/tasklist/graphql",
// rootPath: "./docs/", // docs will be generated under (rootPath/baseURL)
// baseURL: "apis-tools/tasklist-api",
// linkRoot: "/docs/",
// loaders: {
// UrlLoader: "@graphql-tools/url-loader"
// }
// },
// ],
Comment on lines -26 to -36
Copy link
Collaborator Author

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 😅

// This custom Osano plugin must precede the gtm-plugin.
"./static/plugins/osano",
[
require.resolve("docusaurus-gtm-plugin"),
"./static/plugins/gtm",
{
id: "GTM-KQGNSTS", // GTM Container ID
containerId: "GTM-KQGNSTS",
tagManagerUrl:
process.env.TAG_MANAGER_URL || "https://ssgtm.camunda.io",
},
],
"./static/plugins/bpmn-js",
Expand Down
11 changes: 0 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"@saucelabs/theme-github-codeblock": "^0.2.3",
"clsx": "^1.2.1",
"docusaurus": "^1.14.7",
"docusaurus-gtm-plugin": "0.0.2",
"docusaurus-plugin-openapi-docs": "^2.0.4",
"docusaurus-theme-openapi-docs": "^2.0.4",
"mixpanel-browser": "^2.47.0",
Expand Down
35 changes: 35 additions & 0 deletions static/plugins/gtm/index.js
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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) -->`,
],
};
},
};
};
Loading