Advertisement:

Author Topic: OSClass 2.2.1 Google Analytics Plugin needs to be updated [SOLVED]  (Read 1470 times)

ephraim

  • Jr. Member
  • **
  • Posts: 80
I  recently noticed that the reports for google analytics have started to act intermittently and I'm using the plugin built by OSClass which only asked for the tracking ID in the backend, I investigated and found that the issue was the plugin is using an old tracking code which is now being detected as missing or invalid even if  the code is there. So the plugin needs to be updated now with the new tracking code.

The old code from the plugin was this:
<script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', '<?php echo $id; ?>']);
    _gaq.push(['_trackPageview']);
   
    (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www')   '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
</script>

and should now be replaced with:

<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', '<?php echo $id; ?>', 'auto');
  ga('require', 'linkid', 'linkid.js');
  ga('send', 'pageview');

</script>

The code can be found on the /plugins/google_analytics/footer.php  <<<just replaced the old script tag with the new one from google analytics tracking info.

You can also placed the new code on the footer.php of your theme if you don't want to use the plugin.

Issues screen shot in attachment:

Aficionado

  • Guest
Re: OSClass 2.2.1 Google Analytics Plugin needs to be updated [SOLVED]
« Reply #1 on: July 09, 2015, 08:40:36 pm »
GA Plugin is actually outdated. It also puts the script at the FOOTER and that has also changed. Google says to put it on the header.

So better inject it manually in the theme's header.


ephraim

  • Jr. Member
  • **
  • Posts: 80
Re: OSClass 2.2.1 Google Analytics Plugin needs to be updated [SOLVED]
« Reply #2 on: July 09, 2015, 09:33:49 pm »
I agree that GA plugin is outdated, but Google doesn't mention on their documentation that it should be put on the header. So the old plugin will still work it just needs updating. Screen shot attached: Oh by the way opening <body> tag is not the header. It's after the <body> tag enclosed in <script> tag if that's what you mean? It's just a matter of calling the php hook anywhere you like it to appear ;)
« Last Edit: July 09, 2015, 09:38:21 pm by ephraim »

Aficionado

  • Guest
Re: OSClass 2.2.1 Google Analytics Plugin needs to be updated [SOLVED]
« Reply #3 on: July 09, 2015, 09:45:21 pm »
I agree that GA plugin is outdated, but Google doesn't mention on their documentation that it should be put on the header. So the old plugin will still work it just needs updating. Screen shot attached: Oh by the way opening <body> tag is not the header. It's after the <body> tag enclosed in <script> tag if that's what you mean? It's just a matter of calling the php hook anywhere you like it to appear ;)

Quote
Paste your snippet (unaltered, in its entirety) into every web page you want to track. Paste it immediately before the closing </head> tag.
If you use templates to dynamically generate pages for your site (like if you use PHP, ASP, or a similar technology), you can paste the tracking code snippet into its own file, then include it in your page header.

https://support.google.com/analytics/answer/1008080?hl=en

ephraim

  • Jr. Member
  • **
  • Posts: 80
Re: OSClass 2.2.1 Google Analytics Plugin needs to be updated [SOLVED]
« Reply #4 on: July 09, 2015, 09:59:45 pm »
I agree that GA plugin is outdated, but Google doesn't mention on their documentation that it should be put on the header. So the old plugin will still work it just needs updating. Screen shot attached: Oh by the way opening <body> tag is not the header. It's after the <body> tag enclosed in <script> tag if that's what you mean? It's just a matter of calling the php hook anywhere you like it to appear ;)

Quote
Paste your snippet (unaltered, in its entirety) into every web page you want to track. Paste it immediately before the closing </head> tag.
If you use templates to dynamically generate pages for your site (like if you use PHP, ASP, or a similar technology), you can paste the tracking code snippet into its own file, then include it in your page header.

https://support.google.com/analytics/answer/1008080?hl=en

In that case Google Analytics, should update their documentation as well :), well looks like it would work on both <header> or <body> I just usually put mine on the <body> tag. Cheers  ;D

Aficionado

  • Guest
Re: OSClass 2.2.1 Google Analytics Plugin needs to be updated [SOLVED]
« Reply #5 on: July 09, 2015, 10:06:07 pm »
Never said it doesn't work. I said what google suggests.

Also the new code is async so ....

Aficionado

  • Guest
Re: OSClass 2.2.1 Google Analytics Plugin needs to be updated [SOLVED]
« Reply #6 on: July 09, 2015, 10:07:37 pm »
Quote
Header:
Async means it won't affect page load as much as the footer, but if you don't load any other javascript in the page, this difference is negligible. The downside of the header is that the page request is sent before you set any custom variables / events. So certain things will not get sent to Google, at least until a second page view occurs. If you're a rookie and you don't know what i'm talking about when i say "custom variables / events", then put the async code in the head.

Footer:
If you have a lot of in page scripts, the footer will lose some data, as people navigate away from the page before GA loads. If you have no scripting in the page, then this can be not too different to the header in many cases. However, wordpress is typically pretty sluggish, so this is probably not the case.

Split between header and footer:
By defining the tracking object in the header, but executing the async load code in the footer, you can add events and variables through the page code and they will be sent when the async file load completes. If you don't have a lot of javascript between the header and footer and you use a lot of custom commands, this is optimal. Otherwise probably the header is best, but note any commands after the pageview request will not work as you expect.

ephraim

  • Jr. Member
  • **
  • Posts: 80
Re: OSClass 2.2.1 Google Analytics Plugin needs to be updated [SOLVED]
« Reply #7 on: July 09, 2015, 10:18:40 pm »
Loading it on header or footer doesn't matter to me actually as I've been using other analytics on my site like piwik, and I find it more liberating than google analytics without me worrying much on referral spam now plaguing Google Analytics. But that's another story. Just here to put heads up on people who might experienced the same issues I encounter.