Reputation: 15734
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:
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
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
Reputation: 476
You could try substituting in HTML entities
[ = [
] = ]
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