News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Universal Analytics not working

Started by ftr, November 10, 2013, 11:18:00 AM

Previous topic - Next topic

ftr

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.

shadow82x

Welcome to the SMF community! Mind pasting the code here that you are trying to get work?
Colin B
Former Spammer, Customize, & Support Team Member

ftr

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

Storman™

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

margarett

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...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

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.

Shambles

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 )

ftr

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

Storman™

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

Advertisement: