Advertisement:

Author Topic: Universal Analytics not working  (Read 5878 times)

Offline ftr

  • Newbie
  • *
  • Posts: 5
Universal Analytics not working
« 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.

Offline shadow82x

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,278
  • Gender: Male
    • cmblaber on LinkedIn
Re: Universal Analytics not working
« Reply #1 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?
Colin B
Former Spammer, Customize, & Support Team Member

Offline ftr

  • Newbie
  • *
  • Posts: 5
Re: Universal Analytics not working
« Reply #2 on: November 11, 2013, 03:24:34 AM »
Thank you! Here it is the code:

Code: [Select]
<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.
« Last Edit: November 11, 2013, 10:05:19 AM by Kindred »

Offline Storman™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,027
Re: Universal Analytics not working
« Reply #3 on: November 11, 2013, 06:39:28 AM »
Quote
When 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.)
Any Backup method is bettter than no Backup method....

Offline margarett

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,761
  • Gender: Male
Re: Universal Analytics not working
« Reply #4 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...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

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

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 70,956
    • StoryBB/StoryBB on GitHub
Re: Universal Analytics not working
« Reply #5 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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Shambles

  • SMF Hero
  • ******
  • Posts: 5,104
  • Gender: Male
    • i30 Owners Club
Re: Universal Analytics not working
« Reply #6 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 )

Offline ftr

  • Newbie
  • *
  • Posts: 5
Re: Universal Analytics not working
« Reply #7 on: November 12, 2013, 08:56:24 AM »
Quote
When 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:)

Offline Storman™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,027
Re: Universal Analytics not working
« Reply #8 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.   ;)
Any Backup method is bettter than no Backup method....