User Tools

Site Tools


en:user_advanced:google_analytics
This version is outdated by a newer approved version.DiffThis version (2018/08/06 23:12) is a draft.
Approvals: 0/1
The Previously approved version (2018/08/06 21:25) 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: https://moz.com/blog/absolute-beginners-guide-to-google-analytics

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="https://www.googletagmanager.com/gtag/js?id=UA-xxx"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-xxx');
</script>

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-1</xsl:variable>
    <!-- Global site tag (gtag.js) - Google Analytics -->
	<script async="async" src="https://www.googletagmanager.com/gtag/js?id={$trackid}"><xsl:text> </xsl:text></script>
	<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>
	</script>
  </xsl:template>
en/user_advanced/google_analytics.1533597155.txt.gz · Last modified: 2018/08/06 23:12 by kjdon