This version is outdated by a newer approved version.DiffThis version (2018/08/07 14:11) is a draft.
Approvals: 0/1
The Previously approved version (2018/08/07 11:15) is available.Diff

This is an old revision of the document!

Using Google Analytics

Here are just some notes I am making as I try to work out how to use this.

It seems that you sign up to google analytics with your google account.

Then you can add websites to be analysed.

Useful website:

You add analytics account - you can have more than one. Eg we have New Zealand Digital Library account.

Inside your account, you can have lots of properties, which are websites.

Once you set up a property for a website, you get a snippet of code which goes into the head of all the pages in that website that need tracking. The code is common to all pages apart from the ID, which is unique to a property. In the following example, I have put UA-xxx as a substitute for the tracking ID.

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src=""></script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-xxx');

If you are writing this into XSLT file, you need to format it like this:

  <xsl:template name="addGoogleTracking">
    <xsl:variable name="trackid">UA-xxx</xsl:variable>
    <!-- Global site tag (gtag.js) - Google Analytics -->
	<script async="async" src="{$trackid}"><xsl:text> </xsl:text></script>
	  <xsl:text disable-output-escaping="yes">
	  window.dataLayer = window.dataLayer || [];
	  function gtag(){dataLayer.push(arguments);}
	  gtag('js', new Date());
	  gtag('config', '</xsl:text><xsl:value-of select="$trackid"/><xsl:text disable-output-escaping="yes">');</xsl:text>

Adding and using new servlet params

To make this work I have modified the java code to store any initParams mentioned in the servlet definition (in servlets.xml) in the config_params HashMap. This gets passed to the transformer when it does the page transformation, so all of these get passed in as parameters. You can access them by declaring <xsl:param name="param-name"/> at the start of web/interfaces/default/transform/gslib.xsl along with the other predefined ones.

  <!-- some global parameters - these are set by whoever is invoking the transformation
  Any servlet init parameters can be accessed by adding a param here-->
  <xsl:param name="interface_name"/>
  <xsl:param name="library_name"/>
  <xsl:param name="site_name"/>
  <xsl:param name="use_client_side_xslt"/>
  <xsl:param name="filepath"/>
  <xsl:param name="google_tracking_id"/>

Now that this has been implemented, instead of hard coding the tracking id in the xslt file, you can specify it as an initParam to a servlet (therefore each servlet can have a different one if need be)