Jump to:

23375 Posts in 18175 Topics by 2866 members

General Questions

SilverStripe Forums » General Questions » Google Analytics - SilverStripe not sending the stuff

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

Page: 1
Go to End
Author Topic: 1630 Views
  • Axonn
    Avatar
    Community Member
    6 Posts

    Google Analytics - SilverStripe not sending the stuff Link to this post

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

    http://www.axonnsd.org/ASDClock/

    Thank you ::- ).

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Google Analytics - SilverStripe not sending the stuff Link to this post

    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.

    Done.

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Google Analytics - SilverStripe not sending the stuff Link to this post

    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="http://www.google-analytics.com/ga.js" ></script>
    <script type="text/javascript">
       try {
          var pageTracker = _gat._getTracker("YOUR-TRACKINGCODE");
          pageTracker._trackPageview();
       } catch(err) {}
    </script>

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

  • Axonn
    Avatar
    Community Member
    6 Posts

    Re: Google Analytics - SilverStripe not sending the stuff Link to this post

    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?

    http://www.axonnsd.org/

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

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Google Analytics - SilverStripe not sending the stuff Link to this post

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

  • Axonn
    Avatar
    Community Member
    6 Posts

    Re: Google Analytics - SilverStripe not sending the stuff Link to this post

    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 http://axonnsd.org/ASDClock/ 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" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" >

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Google Analytics - SilverStripe not sending the stuff Link to this post

    The explanation is here:
    http://www.w3.org/MarkUp/2004/xhtml-faq#docwrite

    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: http://www.codehouse.com/javascript/articles/external/

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

  • Axonn
    Avatar
    Community Member
    6 Posts

    Re: Google Analytics - SilverStripe not sending the stuff Link to this post

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

    1630 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.