[GeoNetwork-users] Google Tag Manager in GeoNetwork 3.x

Good morning.

I need to include the code for the Google Tag Manager in GeoNetwork, but I have no idea where I should put it.

Reading an old message of this list, the poster commented about changing the file base-layout.xsl. But he didn't tell how exactly.

Has anyone tried this before? Any clue is welcome, so thanks for any help provided!

Best regards.

Óscar Diago Alonso
Analista / Desarrollador GIS
oscar.diago@anonymised.com<mailto:oscar.diago@anonymised.com>
Tfno.: +34 945 13 13 72
C/ Pintor Clemente Arráiz, 3 BJ (01008) Vitoria-Gasteiz, Álava

Óscar Diago Alonso
Analista / Desarrollador GIS
oscar.diago@anonymised.com
Tfno.: +34 945 13 13 72
C/ Pintor Clemente Arráiz, 3 BJ (01008) Vitoria-Gasteiz, Álava
[https://geograma.com/wp-content/banners/banner_mail.png\]<https://www.geograma.com/casos-de-exito/&gt;
Si no ves la imagen puedes acceder desde aquí<https://www.geograma.com/casos-de-exito/&gt;

Tratamos su dirección de correo electrónico y otros datos personales para mantener el contacto y comunicación con Ud. y, en su caso, remitirle información sobre nuestros productos y servicios. Si no desea recibir tal información envíe un e-mail en tal sentido a dpd@anonymised.com Puede acceder, rectificar y suprimir los datos, así como otros derechos, como se detalla en la información adicional y completa a su disposición en nuestra política de privacidad en la URL www.geograma.com/politica-privacidad/. Este mensaje y los archivos adjuntos al mismo son privados y confidenciales, si no es Ud. el destinatario y ha recibido este mensaje por error, rogamos nos lo comunique inmediatamente sin difundir, almacenar o copiar su contenido.

[https://geograma.com/wp-content/banners/geo-web.png\]<https://www.geograma.com/&gt; [https://geograma.com/wp-content/banners/geo-linkedin.png\] <https://bit.ly/geo-linkedin&gt; [https://geograma.com/wp-content/banners/geo-twitter.png\] <https://bit.ly/geo-tw&gt;

Hello Oscar,

On Fri, Feb 18, 2022 at 10:43 AM Oscar Diago Alonso via GeoNetwork-users <
geonetwork-users@lists.sourceforge.net> wrote:

Good morning.

I need to include the code for the Google Tag Manager in GeoNetwork, but I
have no idea where I should put it.

Reading an old message of this list, the poster commented about changing
the file base-layout.xsl. But he didn't tell how exactly.

Has anyone tried this before? Any clue is welcome, so thanks for any help
provided!

I guess you need to modify the base-layout.xsl [1] file and add the code
required by Google Tag Manager there. For example:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform&quot;
                version="2.0"
                xmlns:util="java:org.fao.geonet.util.XslUtil"
                exclude-result-prefixes="#all">

  <xsl:output omit-xml-declaration="yes" method="html"
doctype-system="html" indent="yes"
              encoding="UTF-8"/>

  <xsl:include href="common/base-variables.xsl"/>
  <xsl:include href="base-layout-cssjs-loader.xsl"/>
  <xsl:include href="skin/default/skin.xsl"/>

  <xsl:template match="/">
    <html ng-app="{$angularModule}" lang="{$lang2chars}" id="ng-app">
      <head>

     <!-- 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=
'
https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f)
;
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
     <!-- End Google Tag Manager -->

...

      </head>

      <!-- The GnCatController takes care of
      loading site information, check user login state
      and a facet search to get main site information.
      -->
      <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']">

      <!-- Google Tag Manager (noscript) -->
      <noscript><iframe src="
https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX&quot;
height="0" width="0"
style="display:none;visibility:hidden"></iframe></noscript>
      <!-- End Google Tag Manager (noscript) -->

...

[1]
https://github.com/geonetwork/core-geonetwork/blob/3.12.x/web/src/main/webapp/xslt/base-layout.xsl#L43

--

*Vriendelijke groeten / Kind regards,Juan Luis Rodríguez.
<http://www.geocat.net/&gt;Veenderweg 136721 WD BennekomThe NetherlandsT: +31
(0)318 416664 <+31318416664>Please consider the environment before printing
this email.*

Hi.

Thanks for the answer. I’ll test it out as soon as possible.

Best regards.

Óscar Diago Alonso
Analista / Desarrollador GIS
oscar.diago@...1602...<mailto:oscar.diago@…1602…>
Tfno.: +34 945 13 13 72
C/ Pintor Clemente Arráiz, 3 BJ (01008) Vitoria-Gasteiz, Álava

De: Juan Luis Rodríguez Ponce <juanluisrp@...444...>
Enviado el: viernes, 18 de febrero de 2022 11:12
Para: Oscar Diago Alonso <Oscar.Diago@...1602...>
CC: geonetwork-users@lists.sourceforge.net
Asunto: Re: [GeoNetwork-users] Google Tag Manager in GeoNetwork 3.x

Hello Oscar,

On Fri, Feb 18, 2022 at 10:43 AM Oscar Diago Alonso via GeoNetwork-users <geonetwork-users@lists.sourceforge.net<mailto:geonetwork-users@lists.sourceforge.net>> wrote:
Good morning.

I need to include the code for the Google Tag Manager in GeoNetwork, but I have no idea where I should put it.

Reading an old message of this list, the poster commented about changing the file base-layout.xsl. But he didn't tell how exactly.

Has anyone tried this before? Any clue is welcome, so thanks for any help provided!

I guess you need to modify the base-layout.xsl [1] file and add the code required by Google Tag Manager there. For example:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform&quot;
                version="2.0"
                xmlns:util="java:org.fao.geonet.util.XslUtil"
                exclude-result-prefixes="#all">

  <xsl:output omit-xml-declaration="yes" method="html" doctype-system="html" indent="yes"
              encoding="UTF-8"/>

  <xsl:include href="common/base-variables.xsl"/>
  <xsl:include href="base-layout-cssjs-loader.xsl"/>
  <xsl:include href="skin/default/skin.xsl"/>

  <xsl:template match="/">
    <html ng-app="{$angularModule}" lang="{$lang2chars}" id="ng-app">
      <head>

     <!-- 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=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
     <!-- End Google Tag Manager -->

...
      </head>

      <!-- The GnCatController takes care of
      loading site information, check user login state
      and a facet search to get main site information.
      -->
      <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']">

      <!-- Google Tag Manager (noscript) -->
      <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX&quot;
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
      <!-- End Google Tag Manager (noscript) -->

...

[1] https://github.com/geonetwork/core-geonetwork/blob/3.12.x/web/src/main/webapp/xslt/base-layout.xsl#L43

--
Vriendelijke groeten / Kind regards,

Juan Luis Rodríguez.

[https://www.geocat.net/wp-content/uploads/2015/07/GeoCat_small1.png\]<http://www.geocat.net/&gt;
Veenderweg 13
6721 WD Bennekom
The Netherlands
T: +31 (0)318 416664<tel:+31318416664>

Please consider the environment before printing this email.

Hi.

I tested the solution, and it is working fine. Thanks!

But we also need to include an event to load DOM pages so we can enable some Google metrics. This line of code must be added somewhere on GeoNetwork:

dataLayer.push({ 'event': 'SPA DOM Ready', 'path': '{{Ruta de la página}}', 'title': '{{Título de la página}}’ });

Does anyone know where that line should be added?

Best regards.

Óscar Diago Alonso
Analista / Desarrollador GIS
oscar.diago@...1602...<mailto:oscar.diago@…1602…>
Tfno.: +34 945 13 13 72
C/ Pintor Clemente Arráiz, 3 BJ (01008) Vitoria-Gasteiz, Álava

De: Juan Luis Rodríguez Ponce <juanluisrp@...444...>
Enviado el: viernes, 18 de febrero de 2022 11:12
Para: Oscar Diago Alonso <Oscar.Diago@...1602...>
CC: geonetwork-users@lists.sourceforge.net
Asunto: Re: [GeoNetwork-users] Google Tag Manager in GeoNetwork 3.x

Hello Oscar,

On Fri, Feb 18, 2022 at 10:43 AM Oscar Diago Alonso via GeoNetwork-users <geonetwork-users@lists.sourceforge.net<mailto:geonetwork-users@lists.sourceforge.net>> wrote:
Good morning.

I need to include the code for the Google Tag Manager in GeoNetwork, but I have no idea where I should put it.

Reading an old message of this list, the poster commented about changing the file base-layout.xsl. But he didn't tell how exactly.

Has anyone tried this before? Any clue is welcome, so thanks for any help provided!

I guess you need to modify the base-layout.xsl [1] file and add the code required by Google Tag Manager there. For example:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform&quot;
                version="2.0"
                xmlns:util="java:org.fao.geonet.util.XslUtil"
                exclude-result-prefixes="#all">

  <xsl:output omit-xml-declaration="yes" method="html" doctype-system="html" indent="yes"
              encoding="UTF-8"/>

  <xsl:include href="common/base-variables.xsl"/>
  <xsl:include href="base-layout-cssjs-loader.xsl"/>
  <xsl:include href="skin/default/skin.xsl"/>

  <xsl:template match="/">
    <html ng-app="{$angularModule}" lang="{$lang2chars}" id="ng-app">
      <head>

     <!-- 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=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
     <!-- End Google Tag Manager -->

...
      </head>

      <!-- The GnCatController takes care of
      loading site information, check user login state
      and a facet search to get main site information.
      -->
      <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']">

      <!-- Google Tag Manager (noscript) -->
      <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX&quot;
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
      <!-- End Google Tag Manager (noscript) -->

...

[1] https://github.com/geonetwork/core-geonetwork/blob/3.12.x/web/src/main/webapp/xslt/base-layout.xsl#L43

--
Vriendelijke groeten / Kind regards,

Juan Luis Rodríguez.

[https://www.geocat.net/wp-content/uploads/2015/07/GeoCat_small1.png\]<http://www.geocat.net/&gt;
Veenderweg 13
6721 WD Bennekom
The Netherlands
T: +31 (0)318 416664<tel:+31318416664>

Please consider the environment before printing this email.