FriendsOfFlarum / analytics

A Flarum extension that provides your forum piwik's and google's analytics features
https://discuss.flarum.org/d/1983
MIT License
33 stars 12 forks source link

Compatibility with Google Search Console verification #26

Open csBlackWolf opened 4 years ago

csBlackWolf commented 4 years ago

I think it would be great if the Google Analytics code could be recognized by the Google Search Console to confirm the ownership of the website.

When I try to verify my ownership through Analytics, I get the following error:

Verification method: Google Analytics

Failure reason: The Google Analytics tracking code on your site is in the wrong location on the page. You can verify site ownership with the tracking snippet placed in the <head> section of your home page. Learn more: https://support.google.com/analytics/answer/174090

Please fix your implementation and reverify, or use another verification method. Learn more: https://support.google.com/webmasters/answer/9008080#google_analytics_verification

Would it be possible to make it compatible?

PS: The Google Tag Manager code is also not recognized by the Google Search Console.

clarkwinkelmann commented 4 years ago

Thanks for the report!

Could you confirm where the code is inserted on your page? It should be inserted in the head already.

Is the "homepage" described by Google actually a Flarum page or is it maybe another website (for example if Flarum is in a subfolder)?

csBlackWolf commented 4 years ago

The code seems to be in the head.

It looks like this:

<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-000000000-0"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
</script>

Google say it should look like this:

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

  gtag('config', 'UA-000000000-0');
</script>

I am not sure that could be the problem, but google mentions that it is important, to have the exact same code. https://support.google.com/webmasters/answer/9008080#google_analytics_verification

I also think I have read that it would be better to insert the script before any other script and the CSS.

csBlackWolf commented 3 years ago

My Flarum is still not recognized by Google Search Console. Any ideas?

grafik grafik grafik

clarkwinkelmann commented 3 years ago

It seems like we made the choice to only call the tracking code once the first page is rendered in the single page app https://github.com/FriendsOfFlarum/analytics/blob/fb91b7e05d99d1d489197362d5c09c1a5647bb13/js/src/forum/index.js#L7

That would be why it can't be used for Google verification.

I don't really know if we want to change that. Are you able to use another verification method?

csBlackWolf commented 3 years ago

I don't really know if we want to change that. Are you able to use another verification method?

That is the problem. For FreeFlarum, this was the only good way to verify for the google search console. The only other way would be to buy a domain, make a subdomain and set it via CNAME to my FreeFlarum Domain. Then i could use the domain verification. However, this is a little inconvenient. :(

clarkwinkelmann commented 3 years ago

You mean it worked on Flarum beta 13?

The code that seems to be at the origin of the problem hasn't been changed in the last 2 years :sweat_smile:

csBlackWolf commented 3 years ago

I think i can remember that it have worked in the past... I am almost sure about it. I was thinking that google has changed something how it detects analytics. 😮