Passing variables to setTimeout without curly brackets

So, google analytics eh? Should be a piece of piss really. But.. What if you can’d properly edit the code? We’re stuck to a CMS where you have very limited access to the code. We can edit between the <body> and the </body> tag and we can also edit the stylesheets. So, here I am, trying to track our checkout process, seeing as every single checkout page comes up as index.html due to what is obviously VERY VERY clever programming.

So I came up with a small snippet to send a trackEvent to Google analytics(this is my first time really ever touching javascript). Code follows here.

<script type=”text/javascript”>
function functionName(eventName) {
pageTracker._trackEvent(‘Checkout’,eventName);
}
</script>

Now! This would be all fine and dandy, the CMS offers a page text editor which in theory will allow you to stick a bit of code in there; It does have a view source button, so you can stick bits of code in there. So you know, unless the CMS strips out curly brackets we’ll be OK. What? Did I hear that right? Yes, the CMS does in fact strip out curly brackets. What a retarded load of bollocks.

So, Seeing as it strips out curly brackets(but NOTHING else) from the default page text I had to resort to finding another route. The solution I arrived at in the end is not elegant, but it works and it does what I need it to do. The code above gets put at the end of the footer and the function gets called with a two second timeout the only place where I was allowed to insert code.

<script type=”text/javascript”>
setTimeout(“functionName(‘eventName’)”, 2000);
</script>

I have however in hindsight realized that for my purposes creating a faux pageview and then set up a goal with a funnel is better for what I need to do. So that will be my next task.

WordPress Themes