Skip to content

Commit b4605f7

Browse files
authored
feat: Implement new Google Tag Manager (#204)
1 parent b21d3e0 commit b4605f7

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

docusaurus.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ const config = {
131131
sidebarPath: './sidebars.js',
132132
},
133133
],
134+
'./plugins/gtm-plugin',
134135
],
135136

136137
presets: [

plugins/gtm-plugin/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = function (context, options) {
2+
return {
3+
name: 'docusaurus-plugin-gtm-secondary',
4+
injectHtmlTags() {
5+
return {
6+
headTags: [
7+
{
8+
tagName: 'script',
9+
innerHTML: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
10+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
11+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
12+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
13+
})(window,document,'script','dataLayer','GTM-TVR3P3LC');`,
14+
},
15+
],
16+
preBodyTags: [
17+
{
18+
tagName: 'noscript',
19+
innerHTML: `<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-TVR3P3LC"
20+
height="0" width="0" style="display:none;visibility:hidden"></iframe>`,
21+
},
22+
],
23+
};
24+
},
25+
};
26+
};

0 commit comments

Comments
 (0)