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

support for new Google Analytics #26

Open
bradipao opened this issue Jan 2, 2021 · 4 comments
Open

support for new Google Analytics #26

bradipao opened this issue Jan 2, 2021 · 4 comments

Comments

@bradipao
Copy link

bradipao commented Jan 2, 2021

I tried to enable Google Analytics using the proper parameter (google_analytics) in _config.yml and the intended code is actually injected in the page, but apparently it is valid only for old Analytics tracking IDs (UA-xxxxxxx). New measurement IDs (G-xxxxxxxx) seems to need a different script code.

I modified _default.html removing current code and I added new code just after HEAD tag as per Google Analytics documentation ( https://developers.google.com/analytics/devguides/collection/gtagjs ). After a few try it seems working now.

It is still compatible with the "google_analytics" parameter in _config.yml, the difference is just in the script code. But in a more general approach probably a dedicated parameter would be better, to have both scripts in the layout.

<head>

  {% if site.google_analytics %}
    <script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics }}"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', '{{ site.google_analytics }}');
    </script>
  {% endif %}
@parkr
Copy link
Contributor

parkr commented Jul 16, 2021

In #30, we are introducing a new include for custom headers. I'd propose that we put this old code there (for backwards compatibility) and then allow folks who want to use v4 to put that custom data into a custom include for Google Analytics.

@parkr
Copy link
Contributor

parkr commented Jul 16, 2021

To be clearer:

  1. _layouts/default.html contains {% include head-custom.html %} or similar.
  2. _includes/head-custom.html (maybe make it underscore-delimited) includes {% include google_analytics.html %}
  3. _includes/google_analytics.html contains pre-existing v3 code. User replaces this include inside their site with the code they want to be included instead.

@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
@ynikitenko
Copy link

Thank you! It would be great if you could add some information to the main page. I installed GA4, and only then realized that I need the other tracking number.

@stale stale bot removed the wontfix label Jul 3, 2022
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