Zach Lysobey
Zach Lysobey

Reputation: 15734

Alternative google analytics tracking code?

I'm using the following code to add Google analytics to a website.

The problem is... I don't have access to the source files, only an edit box in a (very old) custom CMS.

Pasting in <scripts> works fine generally, but they have a templating solution in place which uses square brackets ([,]), and the GA code is messing it all up.

I can think of 2 possible solutions:

  1. Some sort of alternative syntax so I can omit the brackets from the tracking code
  2. A completely different (older?) method of including the tracking code. Does this exist?

My existing GA code

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxx-1']);
  _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);
  })();
</script>

Upvotes: 0

Views: 611

Answers (2)

0__0
0__0

Reputation: 834

Being able to host a file outside the CMS, you can put the tracking code in a separate file and include it as an external javascript.

Upvotes: 3

Mr Benn
Mr Benn

Reputation: 476

You could try substituting in HTML entities

[ = &#91;
] = &#93;

so when they display in the browser they hopefully get interpreted correctly - I've seen that kind of approach work with this kind of issue in template languages before.

Failing that see http://perishablepress.com/3-ways-track-google-analytics/ - there's a few old school GA script option documented there. Cheers Ben

Upvotes: 1

Related Questions