Skip to content

Commit

Permalink
Add Google Analytics Tag to html pages
Browse files Browse the repository at this point in the history
switch google analytics 4 to google tag manager
  • Loading branch information
Benoît Regamey authored and cmangeat committed Jan 26, 2024
1 parent b641181 commit 43d41b7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions web/src/main/webapp/xslt/base-layout-cssjs-loader.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,26 @@
}]);
</script>
</xsl:template>

<!-- Google Tag Manager -->
<xsl:template name="ga4-load-head">
<!-- Google Tag Manager -->
<script>
<![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>

<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>
3 changes: 3 additions & 0 deletions web/src/main/webapp/xslt/base-layout.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
title="{concat($env/system/site/name, ' - ', $env/system/site/organization)}"/>

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


Expand All @@ -69,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
2 changes: 2 additions & 0 deletions web/src/main/webapp/xslt/common/render-html.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@
title="{$title}"/>

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

</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 43d41b7

Please sign in to comment.