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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

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

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

Google Analytics - SilverStripe not sending the stuff

Go to End

8 Posts   2037 Views


Community Member, 6 Posts

13 September 2009 at 1:44am

Edited: 13/09/2009 1:45am

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 ::- ).


Community Member, 253 Posts

13 September 2009 at 2:20am

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.



Community Member, 904 Posts

13 September 2009 at 3:07am

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 :)


Community Member, 6 Posts

13 September 2009 at 2:45pm

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 ::- >


Community Member, 904 Posts

13 September 2009 at 7:37pm

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...


Community Member, 6 Posts

13 September 2009 at 10:01pm

Edited: 13/09/2009 10:04pm

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" >


Community Member, 904 Posts

13 September 2009 at 10:32pm

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...


Community Member, 6 Posts

14 September 2009 at 12:02am

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