Loading

New Google Analytics tracking code

Annoying Browser ErrorOver the last few days, I have been trying to fix a foxy problem on one of the websites I work on.

The problem was that we use Google Analytics as a tool on our sites. This gives us a way to get visitor information. Now our website has normal, and secure pages. And you need a different code to go on different pages. There's not much difference really, little more than one has a link that begins http:// and the other https://.

The problem is our secure applications use a skin which is common to both. Which means if the skin is being used for all of the standard pages, they all run as normal. However if you access a secure page, which uses the same skin, the tracking code tries to load the unsecure script, which gives the error: This page contains both secure and nonsecure items. Do you want to display the nonsecure ones?

Now from a user's perspective this is pants. They shouldn't have this error, and it should not effect the performance of the page. They are just wanting to look at some secure data, so why should we worry them with this error?

So I've been tinkering with JavaScript, and rather bizarrely am trying to use JavaScript to write out a JavaScript line on the page, that will sense a secure protocol in use, and call the correct script accordingly. There method in JavaScript called location.protocol which gives me https or http back. Problem solved I thought! But I couldn't somehow get it to work. Maybe the problem was that there was more to just swapping the protocol over. Maybe Google uses different script for secure and nonsecure pages.

Off I trot to Analytics to examine the tracking code. And what do I find? Google has produced new tracking code called ga.js which solves this problem automatically. Doh! Can I have my last day back please Google?

14-Dec-2007 Permanent Link

 

It's all about me...

I'm a 55 year old married father who works with websites for a living. Doing that for work means I dont often update this site, unless I can think of something useful to say. I mostly like taking photos - and most of my internet presence now will be related to that.

Something else?

Dont you find it ironic that people invest so much in bringing you to a website only to give you a list of links to take you elsewhere? So I'm not going to give you a list of my favourite haunts to send you away from this site.

(c) somewhere in space and time: M.Norman