Search

Hello all,

I may have missed this somewhere along the way, but could someone please point me in the right direction of how to embed GA into my master.xsl file?

Thanks :)

Tim.

Would you mind posting your master.xsl?

Just paste in the script tags before your closing body tag. No different in XSLT than any other templating method.

Thanks guys, I did that but for some reason <![CDATA[ tags were placed around my analytics javascript and it would then fail in firebug…

As follows is the last part of my master.xsl file, i’ve included my GA code as I have always done in other websites…

    <!-- google analytics //-->
        <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
        </script>   
        <script type="text/javascript">
        _uacct = "UA-12345678";
        urchinTracker();
        </script>

    </body>     

</html>

I’ve had this problem before—think it has something to do with the XSL processor/settings. My not-particularly-clean-solution is in this thread.

This seems to work for me – wrap the code in <xsl:comment> tags like this:

  <script type="text/javascript">
  <xsl:comment>
    var pageTracker = _gat._getTracker("UA-937700-1");
    pageTracker._initData();
    pageTracker._trackPageview();
  </xsl:comment>
  </script>

The output looks like this:

    <script type="text/javascript">
<!--
    var pageTracker = _gat._getTracker("UA-937700-1");
    pageTracker._initData();
    pageTracker._trackPageview();
  -->
    </script>

FYI: wdtan mentioned the same method as MrBlank in the last thread, but it didn’t work for me. I’ve only come across that problem on two servers, the rest of the the just outputting as straight-up HTML has worked perfectly.

@makenosound - which servers did that happen on? any particular host?

normally, the xsl:comment method should work for any in-page javascript call.

Hi,

What am I doing wrong here?

    &lt;script type="text/javascript">
     <xsl:comment>
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'xxx']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
     </xsl:comment>

&lt;/script>

This is working on one of my 2.0.6 sites:

<xsl:template name="google-analytics">
<xsl:text disable-output-escaping="yes"><![CDATA[
<script type="text/javascript">
//<![CDATA[
  var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
  document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
//]]>]]&gt;
&lt;/script>
</xsl:text>
<xsl:text disable-output-escaping="yes"><![CDATA[
<script type="text/javascript">
//<![CDATA[
  try {
  var pageTracker = _gat._getTracker("YOUR_TRACKER_ID_HERE");
  pageTracker._trackPageview();
  } catch(err) {}
//]]>]]&gt;
&lt;/script>
</xsl:text>
</xsl:template>

This is what it is displaying:

&lt;script type="text/javascript">

//<![CDATA[ var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”); document.write(unescape(“%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”)); //]]> </script>

<script type=”text/javascript”> //<![CDATA[ try { var pageTracker = gat.getTracker(“UA-16416245-1”); pageTracker._trackPageview(); } catch(err) {} //]]> </script>

That doesn’t look right. Incase the formatting is off here is the url:

http://regupolacousticsmiddleeast.com/

The code above got garbled. Try it now.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details