Skip to content

Commit

Permalink
switch google analytics 4 to google tag manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Benoît Regamey authored and cmangeat committed Feb 1, 2023
1 parent dc86ce7 commit a09decf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
27 changes: 18 additions & 9 deletions web/src/main/webapp/xslt/base-layout-cssjs-loader.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,25 @@
</script>
</xsl:template>

<!-- Google Analytics 4 -->
<xsl:template name="ga4-load">
<!-- Google tag (gtag.js) -->
<script async="async" src="https://www.googletagmanager.com/gtag/js?id=G-C0NWPQVB2N"></script>
<!-- Google Tag Manager -->
<xsl:template name="ga4-load-head">
<!-- Google Tag Manager -->
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
<![CDATA[
(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-NBPF5L9');
]]>
</script>
<!-- End Google Tag Manager -->
</xsl:template>

gtag('config', 'G-C0NWPQVB2N');
</script>
<xsl:template name="ga4-load-body">
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NBPF5L9"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
</xsl:template>
</xsl:stylesheet>
4 changes: 3 additions & 1 deletion web/src/main/webapp/xslt/base-layout.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
title="{concat($env/system/site/name, ' - ', $env/system/site/organization)}"/>

<xsl:call-template name="css-load"/>
<xsl:call-template name="ga4-load"/>
<xsl:call-template name="ga4-load-head"/>
</head>


Expand All @@ -70,6 +70,8 @@
-->
<body data-ng-controller="GnCatController" data-ng-class="[isHeaderFixed ? 'gn-header-fixed' : 'gn-header-relative', isLogoInHeader ? 'gn-logo-in-header' : 'gn-logo-in-navbar', isFooterEnabled ? 'gn-show-footer' : 'gn-hide-footer']">

<xsl:call-template name="ga4-load-body"/>

<div data-gn-alert-manager=""></div>

<xsl:choose>
Expand Down
1 change: 1 addition & 0 deletions web/src/main/webapp/xslt/common/render-html.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
</head>

<body class="gn-nojs {$cssClass}">
<xsl:call-template name="ga4-load-body"/>
<div class="gn-full">
<xsl:call-template name="header"/>
<div class="container" role="main">
Expand Down

0 comments on commit a09decf

Please sign in to comment.