Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Google Analytics - SilverStripe not sending the stuff


8 Posts   1652 Views


13 September 2009 at 1:44am (Last edited: 13 September 2009 1:45am), Community Member, 6 Posts

Hi everybody ::- ). I've been using SilverStripe for quite some time, about a year, even if I'm not very adept in PHP (my turf is C#). Anyway, you did a great job with this CMS, I love it.

Now, if only I could make it work with Google Analytics hehe, that would be great.

I put the tracking code before the    </head> because some post said so.
But then when it didn't work I moved it before the </body>. No luck either.
Now I have it in both places and still no luck.

In either case, the <script type="text/javascript"> is rendered in the page, but my analytics are as dead as ever.

I've been searching the Forums but those solutions apparently don't work for me. Am I screwing this up somewhere?

Take a look...

Thank you ::- ).


13 September 2009 at 2:20am Community Member, 243 Posts

You have the code for Google Analytics on that page twice.

If you aren't getting stats through, it is an analytics issue.

Firstly, delete the duplicate code.

Second, Go and check that you are using the exact code they give you in your analytics account.

Thirdly, wait a day for stats to go through.



13 September 2009 at 3:07am Community Member, 901 Posts

I already encountered problems with google analytics. The main problem is the document.write part (that's responsible to load the ga.js file), which simply doesn't work in some browsers with some doctypes.

Usually, I just solve the issue by "normally" including the ga.js file.. this works fine as long as you don't switch from unencrypted (http) to encrypted (https) pages throughout your site (which should be true for most websites).

<script type="text/javascript" src="" ></script>
<script type="text/javascript">
   try {
      var pageTracker = _gat._getTracker("YOUR-TRACKINGCODE");
   } catch(err) {}

And: You should place this code just before the closing </body> tag. And make sure you're including the stuff only once :)


13 September 2009 at 2:45pm Community Member, 6 Posts

Hi and thank you for your answers ::- ). Do you really think having the code twice is a problem? Other than, of course, the messing-up of the statistics? Anyway, I removed it. Now going to wait a day or two to see what happens.

Can you guys shuffle a bit around the website so that I test if I am getting the data into analytics?

*laugh* this sounds like a commercial campaign *laugh*... but I'm not selling anything so I guess it's fine ::- >


13 September 2009 at 7:37pm Community Member, 901 Posts

You won't be getting any data on analytics, since your script doesn't work. If you enable something like firebug you'll see there's a JavaScript error being thrown. It's the same problem I was getting, so I suggest you include your tracking code like I proposed in my last post...


13 September 2009 at 10:01pm (Last edited: 13 September 2009 10:04pm), Community Member, 6 Posts

Ah damn, I just saw the error now. Grrr, that's annoying. Well, my site doesn't use HTTPS so I'll do it your way. Can you try again? I'm not seeing any more problems in my FireBug.

But just for the hell of it, can anybody explain why this JS error happens? I mean, I haven't changed the encoding type of the Templates which SilverStripe uses to generate pages from.

Operation is not supported" code: "9 @ document.write(unescape(

My encoding is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
<html xmlns="" lang="en" >


13 September 2009 at 10:32pm Community Member, 901 Posts

The explanation is here:

It has nothing to do with SilverStripe, it's a XML (XHTML) <> document.write incompatibility. You could use other techniques to add the script block dynamically though.
For an example, have a look at the "DHTML Way" proposed here:

If you don't switch between http and https, you can leave everything as it is now...


14 September 2009 at 12:02am Community Member, 6 Posts

Thank you banal, you saved my cheap arse ::- ). I got no data yet but perhaps tomorrow...