Skip to content

Commit

Permalink
fix/GA4-tag (#445)
Browse files Browse the repository at this point in the history
* Update gulpfile.js
  • Loading branch information
laurenhitchon authored Aug 6, 2024
1 parent 67d3ea9 commit 235ae5b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,15 @@ function renamePathForProd() {

function addAnalytics() {
return src(`${config.dir.build}/**/*.html`)
.pipe(inject.before('</head>', '<script async src="https://www.googletagmanager.com/gtag/js?id=G-TMEHXHFJXJ"></script>\n'))
.pipe(inject.before('</head>', "<script>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', 'G-TMEHXHFJXJ');</script>\n"))
.pipe(inject.after('<head>', `<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=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-P2NKBBJZ');</script>
`))
.pipe(inject.after('<body>', `<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-P2NKBBJZ"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
`))
.pipe(dest(config.dir.build))
}

Expand Down

0 comments on commit 235ae5b

Please sign in to comment.