Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: ftr on November 10, 2013, 11:18:00 AM

Title: Universal Analytics not working
Post by: ftr on November 10, 2013, 11:18:00 AM
Hi all! My first message! Recently I updated from Google Analytics to what is now called Universal Analytics. Just changed the tracking code with a new one they gave me, but it stopped tracking.
I´m using Global Headers and Footers mod to include the code: it just doesn´t work. When I type the code directly on the index.template.php I get some syntax error about the slashes and the quotes...

¿Anybody else with similar problems? Thanks U in advance.
Title: Re: Universal Analytics not working
Post by: shadow82x on November 10, 2013, 03:31:59 PM
Welcome to the SMF community! Mind pasting the code here that you are trying to get work?
Title: Re: Universal Analytics not working
Post by: ftr on November 11, 2013, 03:24:34 AM
Thank you! Here it is the code:

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-[i]mynumbers[/i]-1', '[i]mywebsite.es[/i]');
  ga('send', 'pageview');

</script>

Thanks in advance.
Title: Re: Universal Analytics not working
Post by: Storman™ on November 11, 2013, 06:39:28 AM
QuoteWhen I type the code directly on the index.template.php I get some syntax error about the slashes and the quotes...

Where exactly are you putting the code ?

I believe the new code should be placed immediately before the </head> tag.

(Think the old code went before the </body> tag.)
Title: Re: Universal Analytics not working
Post by: margarett on November 11, 2013, 09:25:11 AM
He's using GHF, so there's no control over that.

Anyway, there shouldn't be a template parse error due to that, IIRC GHF should take care of escaping the script text... But I may be mistaken, here...
Title: Re: Universal Analytics not working
Post by: Arantor on November 11, 2013, 09:30:12 AM
GHF doesn't escape the text. Incidentally the security changes in 1.1.19 and 2.0.6 will throw a wobbler if you try to embed raw JavaScript via GHF because it smells an XSS hole - precisely because of the anti-XSS header I added.
Title: Re: Universal Analytics not working
Post by: Shambles on November 11, 2013, 09:39:40 AM
Quote from: ftr
ga('create', 'UA-mynumbers-1', 'mywebsite.es');

Check that part of your script, as according to GAdev the 3rd parameter (if specified) of a 'create' needs to be a configuration/tracker object:

https://developers.google.com/analytics/devguides/collection/analyticsjs/domains


(PS, I'm no expert - I just did a bit of research in my lunch break. Try just removing the ", 'mywebsite.es'" bit to see )
Title: Re: Universal Analytics not working
Post by: ftr on November 12, 2013, 08:56:24 AM
Quote from: Storman™ on November 11, 2013, 06:39:28 AM
QuoteWhen I type the code directly on the index.template.php I get some syntax error about the slashes and the quotes...

Where exactly are you putting the code ?

I believe the new code should be placed immediately before the </head> tag.

(Think the old code went before the </body> tag.)

Hi! Yes, I tried to put the code on both, before head and body, and no luck.

Thanks for taking time to answer, but since I´m not very good at coding I can´t understand so much   :-[
Luckily some one creates a mod to make it work  O:)
Title: Re: Universal Analytics not working
Post by: Storman™ on November 12, 2013, 12:48:05 PM
Might be best if you post the syntax error that you are getting and a copy of your index.template.php after you've added the code.   ;)