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

Update Google Analytics Code #49

Open
ahwm opened this issue Oct 15, 2020 · 10 comments
Open

Update Google Analytics Code #49

ahwm opened this issue Oct 15, 2020 · 10 comments

Comments

@ahwm
Copy link

ahwm commented Oct 15, 2020

Google has upgraded Google Analytics and is recommending using gtag.js instead of analytics.js (and sending emails to anyone using analytics.js on their sites).

Instead of

      <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', '{Property ID}', 'auto');
        ga('send', 'pageview');
      </script>

Google is now using this:

<script async src="https://www.googletagmanager.com/gtag/js?id={Property ID}"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', '{Property ID}');
</script>
@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale
Copy link

stale bot commented Jan 9, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 9, 2022
@brianary
Copy link

Google is sunsetting Universal Analytics on July 1, 2023: [GA4] Make the switch to Google Analytics 4 - Analytics Help

@ahwm
Copy link
Author

ahwm commented Dec 30, 2022

The code above is valid for GA4 so would be future-proof. If this isn't updated in the template then it will be required by the dev to override the template to add their own, which sort of defeats the purpose of the template.

@stale stale bot removed the wontfix label Dec 30, 2022
@shivioua
Copy link

shivioua commented Jan 5, 2023

Seems that for now this is the officially supported way if one would like to have Google Analytics version 4 (GA4) for theme slate: https://github.com/shivioua/slate#customizing-google-analytics-code

With a bit inspiration from here:
pages-themes/minimal#88 (comment)

@shivioua
Copy link

shivioua commented Jan 5, 2023

Yup, it worked for my GH Page, this is the custom header templated that I've added.
shivioua/shivioua.github.io@24e9545

Hope it will save a bit of time for more people out there. Have fun :)

@shivioua
Copy link

shivioua commented Jan 5, 2023

I'm not an jekyll expert, but in additon to above comment I've created this PR: #82

I assume that similar PRs should be created for all officially supported github pages themes before this one will be merged in.

@brianary
Copy link

brianary commented Jan 6, 2023

@shivioua Works great! Thanks!

@brianary
Copy link

brianary commented Jan 6, 2023

@shivioua While adding the new client code to _includes/head-custom-google-analytics.html works, Google's process for migrating the account, and setting up the "properties" and "flows" for the new Analytics is entirely incomprehensible to me. Rather than spending an absurd amount of time to learn a wildly overbuilt system (that may or may not act ethically with my users' data) for my extremely modest needs, I've used that same file to integrate with GoatCounter.com, which is simple and works just great for my needs.

@shivioua
Copy link

shivioua commented Jan 7, 2023

Thanks for sharing @brianary. I've put a brief look both on the GH project of Goat Counter and your implementation, looks like worth investigating. My needs are couple levels less sophisticated as what's offered by GA. Will definately give it a try at some point.

@ahwm Looks like this thread can be closed or you'd like to wait for the result of #82?
@brianary Would you consider creating a PR for supporting GoatCounter in slate theme?

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

No branches or pull requests

3 participants