User Tools

Site Tools


en:user_advanced:google_analytics

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
en:user_advanced:google_analytics [2018/08/06 21:21] kjdonen:user_advanced:google_analytics [2018/08/06 23:12] kjdon
Line 12: Line 12:
  
 You add analytics account - you can have more than one. Eg we have New Zealand Digital Library account. 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.
 +
 +<code>
 +<!-- 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>
 +</code>
 +
 +If you are writing this into XSLT file, you need to format it like this:
 +
 +<code>
 +  <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>
 +
 +</code>
en/user_advanced/google_analytics.txt · Last modified: 2023/03/13 01:46 by 127.0.0.1