Google Analytics plugin not detected

Hello!

I’ve installed the Google Analytics & Google Analytics (gtag.js) plugins, but when I run Google Tag Assistant on my webpage, it only detects the gtag. And of course on the G Analytics admin page, no visits are detected.

Does anyone know what I did wrong and/or what I need to do?

@plshelpme, I have no experience with any of the plugins and have only used the recommended ‘gtag.js’ snippet to observe page-views trends. Coincidentally, I’m ‘researching’ Google Tag Manager a bit last few days and hence got curious about your question…

TL;DR:

  • In my setup on localhost, both plugins work when installed separately. When installed together I cannot verify that both work correctly. However, in every setup, Google Analytics records page-views in the real-time report. Some config settings are required though (see below).
  • Tag Assistant shows correct count of tags when plugins are installed separately. When installed together, it doesn’t show a different count of tags, but shows the error ‘Same web property ID is tracked twice’. This may account for only seeing the recommended ‘gtag.js’ tags.
  • Not sure what your issue is, but maybe your find some hints/answers in the tests I did.
  • NB. The developer of the google-analytics (gtag.js) plugin hasn’t responded for 5 months to proposed solutions to issues, maybe it is best to copy the suggested tag snippet from Google Analytics manually into the <head> of ‘base.html.twig’ template.

A few questions:

  • What is the reason for installing two plugins for adding Google Analytics tags?
    They both do the same thing: One with the older library and one with the newer and recommended wrapper library (gtag).
  • What did you expect to see in Tag Assistant?
  • Did you test both plugins both separately and together?
  • Are snippets being inserted into the HTML of the page?
  • Are you testing on localhost or a hosted server.

Some tests with notes and observations:

  • Only plugin ganalytics:
    • Note:
      • When using localhost, nothing is loaded because ganalytics blocks localhost. This can be seen in the generated html code.
        After commenting out the specific code, its snippet is loaded.
    • Loads https://www.google-analytics.com/analytics.js
    • Realtime page-view is detected in Google Analytics
    • Tag Assistent found 1 tag: ‘Google Analytics’
  • Only plugin google-analytics:
    • Notes:
      • For localhost, config variable ‘cookie_domain’ must be set to non-empty string.
      • Config variable ‘object_name’ must be set to anything except empty string. Else a javascript error is thrown and and incomplete tag count is shown by Tag Assistant.
    • Loads:
    • Realtime page-view is detected in Google Analytics
    • Tag Assistent found 2 tags:
      • ‘Global site tag (gtag.js)’
      • ‘Google Analytics’ (with message ‘Non standard implementation’ - because ‘cooky_domain’ setting?)
  • Loading ganalytics and google-analytics:
2 Likes

Hi @pamtbaau, thank you for your response.

Answering your questions:

  • I installed both thinking it was necessary.
  • In Tag Assistant, I was expecting to see that Google Analytics is detected.
  • Yes, I tried separately and together. Still no luck.
  • The snippet is inserted into the HTML when I use the second plugin (gtag.js).
  • I am testing on localhost.

I’m wondering, if the gtag is detected, why Tag Assistant says ‘Google Analytics tracking code’ has not been installed on the webpage. I see the tracking code in the HTML.

Question: Under your note for the google-analytics plugin, what did you mean when you said, “config variable ‘cookie_domain’ must be set to non-empty string”?

I just took on the task of updating the website and installing this plugin, so I’m almost completely new to this.

@plshelpme,

You wrote:

I installed both thinking it was necessary.

  • If there is no reason to use the older version of the GA snippet, I would suggest to only install the ‘google-analytics’ plugin.

In Tag Assistant, I was expecting to see that Google Analytics is detected.

  • Maybe my question should have been more explicit: :slight_smile:
    • How would you know it is detected?
    • What tells you it hasn’t been detected?

The snippet is inserted into the HTML when I use the second plugin (gtag.js)

  • Would you mind copying it here? You might want to remove your GA tracking ID.
    Please use tripple backticks (```) on separate line before and after the copied text.

Tag Assistant says ‘Google Analytics tracking code’ has not been installed on the webpage.

  • I cannot find that message in the list of messages in Tag Assistant, nor can I find it using Google search…
    Is that a literal message and where is that message displayed?

what did you mean when you said, “config variable ‘cookie_domain’ must be set to non-empty string”?

  • An empty string is ‘’ (2 single-quotes) or “” (2 double-quotes) and a non-empty string contains characters like ‘abc’ resp. “abc”.
  • Try the following:
    • Copy file ‘/user/plugins/google-analytics/google-analytics.yaml’ into folder ‘/user/config/plugins’.
    • Update the following values in file ‘/user/config/plugins/google-analytics.yaml’:
      tracking_id: "UA-XXXXXXXX-X"  <-- Use your own GA tracking code here
      cookie_domain: "none"         <-- Set to empty string "" when running on hosted website.
      object_name: "gtag"           <-- Needed to fix a bug in plugin
      

Hope this helps…

1 Like

Thank you for your reply, @pamtbaau

If there is no reason to use the older version of the GA snippet, I would suggest to only install the ‘google-analytics’ plugin.

I am now only using the gtag.js plugin.

How would you know it is detected? What tells you it hasn’t been detected?


The last line tells me to “Add Google Analytics” and when I click the question mark (that shows up when you hover over it), it takes me to a page that tells me G Analytics hasn’t been installed yet.

  • Would you mind copying it here? You might want to remove your GA tracking ID.
    Please use tripple backticks (```) on separate line before and after the copied text.
<head>


<!-- Global site tag (gtag.js) - Google Analytics --><script src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X" async=""></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function (){dataLayer.push(arguments);}
  ('js', new Date());
  ('config', 'UA-XXXXXXXXX-X', {'anonymize_ip':true});
</script>

Okay, thank you. I understand.

Would you happen to know how I would access the code through grav so that I can edit it?

@plshelpme, I’m afraid you haven’t configured the plugin correctly. You have only given ‘tracking_id’ a value… Please set the configuration of the plugin as shown above.

  • If object_name is not set, javascript will throw an error in the browser, and the second tag will not be shown by Tag Assistant. That’s why you only see one tag 'Google site tag (gtag.js).

    The error in your snippet is located on this line:

    function (){dataLayer.push(arguments);}  <-- missing function name
    
  • If cookie_domain is not set, Google Analytics will no receive any page views.

You should see something like:


Whereby the ‘Google Analytics’ tag shows the following error: ‘Non-standard implementation’, which is because of the cookie_domain property.

The code should look like:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script src="https://www.googletagmanager.com/gtag/js?id=UA-12345678-9" async></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-12345678-9', {'cookie_domain':'none'});
</script>

The above configurations sends hits to Google Analytics and can be seen in the real-time report.

Would you happen to know how I would access the code through grav so that I can edit it?

Unfortunately, the google-analytics plugin generates the snippet hard-coded in PHP.

If you want to edit the snippet, you might be better of by copying the snippet from Google Analytics website and paste it in ‘/user/themes/your-theme/templates/partials/base-html.twig’.

Not sure what skills you have and what kind of edits you require, but if you need to analyze more dimensions/metrics than only page-views, you might want to have a look at Google Tag Manager.

1 Like

@pamtbaau It works!!! It shows both tags and I can see views in real time now!

Thank you so much!

1 Like

@plshelpme Well done!

Which solution have you opted for? The plugin, or manual copy/pasting the snippet into the themes template?

Since you are new on the forum:

  • You may now mark the reply that has lead you to the solution as ‘solution’ by ticking the ‘solution’ icon in the lower right corner of that reply.
  • And if you really want to show your appreciation, you might be tempted to tick the ‘love’ icon on any reply you appreciate.

@pamtbaau The plugin!

It was quite simple, but I just wasn’t understanding it for some reason. Your explanation with the html code helped a lot. I just needed to configure the plugin correctly.

@plshelpme, Don’t forget to unset the ‘cookie_domain’ once you go live on a hosted webserver…