Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google analytics ga.js is deprecated #361

Closed
kakawait opened this issue Nov 13, 2016 · 3 comments
Closed

Google analytics ga.js is deprecated #361

kakawait opened this issue Nov 13, 2016 · 3 comments
Assignees

Comments

@kakawait
Copy link
Contributor

kakawait commented Nov 13, 2016

Actual behavior

https://github.com/LouisBarranqueiro/hexo-theme-tranquilpeak/blob/master/layout/_partial/google-analytics.ejs

is using ga.js that is now deprecated by google itself

ga.js is a legacy library. If you are starting a new implementation we recommend you use the latest version of this library, analytics.js. For exisiting implementations, learn how to migrate from ga.js to analytics.js.

https://developers.google.com/analytics/devguides/collection/gajs/

Expected behavior

Migrate to analytics.js

Here two possibility

  1. Common way (sync)
<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', '<%= theme.google_analytics_id %>', 'auto');
  ga('send', 'pageview');

</script>

or using async from HTML5 to do not block website (http://caniuse.com/#feat=script-async)

<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', '<%= theme.google_analytics_id %>', 'auto');
ga('send', 'pageview');
</script>
<script async src='//www.google-analytics.com/analytics.js'></script>
@jrbenito
Copy link
Contributor

I would go for async way.

@kakawait
Copy link
Contributor Author

On my fork I set async as default but configuration to allow switch if your user target is using old browser that do not support async

PS: You can check your user browser in google analytics, great news :)

@LouisBarranqueiro
Copy link
Owner

let's use the first one, PR please :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants