membermatters / MemberMatters

An open source membership, access and payments portal for makerspaces and community groups.
https://membermatters.org
MIT License
40 stars 23 forks source link

Google analytics needs to be updated to use Google tag manager #214

Closed proffalken closed 9 months ago

proffalken commented 10 months ago

Describe the bug

Currently the code created looks like this:

<script async="" src="https://www.google-analytics.com/analytics.js"></script>
<script>window.ga =
        window.ga ||
        function () {
          (ga.q = ga.q || []).push(arguments);
        };
      ga.l = +new Date();
</script>

The code in tag manager looks like this:

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

  gtag('config', '<CODE>');
</script>

Looks like it's the code at https://github.com/membermatters/MemberMatters/blob/main/src-frontend/src/store/modules/config.js#L127-L140 that needs to be changed, but I've no idea how to do it! :rofl:

To Reproduce Steps to reproduce the behavior:

  1. Sign up for a Google Analytics account
  2. Get your G-TAG from the Analytics UI
  3. Add it in Constance on the backend admin
  4. Check code and see that the data is not being sent to Google Analytics

Expected behavior Page views etc. should appear in Google Analytics

jabelone commented 9 months ago

Good spot! I forgot to update the code when Google deprecated the old universal analytics in favour of Google Tag Manager / GA4. I've just pushed some changes that should fix this. Note the constance key has changed (this is on purpose as the older UA IDs will not work) so you'll need to save the Measurement ID from the Google Analytics dashboard into constance again.

I got a test ping from my local setup so it should be working again now on the dev branch, and will make it's way into the next release.