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 New Google Analytics 4 #193

Open
warmstarter opened this issue Oct 21, 2022 · 1 comment
Open

Support New Google Analytics 4 #193

warmstarter opened this issue Oct 21, 2022 · 1 comment

Comments

@warmstarter
Copy link

Alabaster supports Google Analytics UA via 'analytics_id' options. This will be deprecated in summer 2023, and for a new account, you have to jump through hoops to even get a UA id if you do not already have one, it is not at all simple. Even if you do this, it is basically a dual GA4/UA account, and kinda messy.

https://support.google.com/analytics/answer/9304153

This site explains the setup of an account, and then the section on 'Add the Google tag directly to your webpages' explains what you need to do. They have some site types where it seems like it can automatically add, and for others it gives manual instructions.

I was successfully able to get this to work by adding it into the layout.html included with Alabaster as shown:

{%- set theme_show_relbar_top = theme_show_relbar_top or theme_show_relbars %}
{%- set theme_show_relbar_bottom = theme_show_relbar_bottom or theme_show_relbars %}

{# removed existing top+bottom related nav, and embed in main content #}
{%- block relbar1 %}{% endblock %}
{%- block relbar2 %}{% endblock %}

{# Nav should appear before content, not after #}
{%- block content %}
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-3ZFF0CWSJN"></script>
        <script>
                                  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-XXXXXXX');
        </script>
{%- if theme_fixed_sidebar|lower == 'true' %}
  <div class="document">
    {{ sidebar() }}
    {%- block document %}

what is in there as ''G-XXXXXXX' should be the GA4 analytics_id to be used, so would need to be a configurable option.

@winedarksea
Copy link

+1
it's 2024 and it still appears the new GA ids are not directly supported.

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

2 participants