mmistakes / minimal-mistakes

:triangular_ruler: Jekyll theme for building a personal site, blog, project documentation, or portfolio.
https://mmistakes.github.io/minimal-mistakes/
MIT License
12.48k stars 25.75k forks source link

Google Analytics working for mobile access, but not for web access #2324

Closed deepns closed 5 years ago

deepns commented 5 years ago

Hi,

I forked my Github Pages site from mmistakes-starter at deepns.github.io. I wanted to add Google Analytics for my pages, so followed the instructions from the configuration guide . I updated the _config.yml with the GA tag, but didn't see any traffic reported in the GA console. I then added a custom.html in the _includes/head with the script tag given by GA. I'm now able to see the traffic updated when accessing the site from a mobile device, but not when accessing from a web browser. Any idea what I might be missing here? I thought mmistakes theme settings take care of inserting the GA script into the head of each page, but it seems to be missing here. Appreciate any help in resolving this issue.

Thanks, Deep

mmistakes commented 5 years ago

Which analytics provider did you try (google, google-universal)? There's a couple of different flavors of Google Analytics.

https://github.com/mmistakes/minimal-mistakes/blob/master/_includes/analytics-providers/google.html

https://github.com/mmistakes/minimal-mistakes/blob/master/_includes/analytics-providers/google-universal.html

deepns commented 5 years ago

Thank you for the response. I am using google-universal.. I think I used google as well, but didn't see any traffic. I then copied the script code from Google Analytics dashboard and pasted into _includes/head/custom.html. That code seems to be slightly different from the ones used in the files you referenced above. Is custom.html really needed here? I thought the theme files under analytics-providers/ provide the needed scripts.


From: Michael Rose notifications@github.com Sent: Monday, November 18, 2019 8:20 AM To: mmistakes/minimal-mistakes minimal-mistakes@noreply.github.com Cc: deepns deepan.seeralan@outlook.com; Author author@noreply.github.com Subject: Re: [mmistakes/minimal-mistakes] Google Analytics working for mobile access, but not for web access (#2324)

Which analytics provider did you try (google, google-universal)? There's a couple of different flavors of Google Analytics.

https://github.com/mmistakes/minimal-mistakes/blob/master/_includes/analytics-providers/google.html

https://github.com/mmistakes/minimal-mistakes/blob/master/_includes/analytics-providers/google-universal.html

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/mmistakes/minimal-mistakes/issues/2324?email_source=notifications&email_token=ANUELG5QXN7TU2DIHD3ADU3QUKJDPA5CNFSM4JOPRUKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEKM7GI#issuecomment-555011993, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ANUELGYQSCNJTF7O5N6HM6TQUKJDPANCNFSM4JOPRUKA.

mmistakes commented 5 years ago

Custom is only needed if you need to drop in a different analytics script embed. As far as I know the Google Analytics scripts the theme provides work. They're working for me.

Hard to tell if it's a configuration thing on your end or if the embed scripts used by the theme are older than what Google is using now. As far as I know they should be backwards compatible.

mmistakes commented 5 years ago

Looking at the source of your site I see this

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

  gtag('config', 'UA-151868570-1');
</script>

Which shows that you're using Google Tag Manager. If that's not what you're using on the backend, then that's why you're not getting any tracking data. Looks to me you have it misconfigured in _config.yml as the provider and google line needs to be indented properly.

Instead of this:

analytics:
provider: "google-universal"
google:
  tracking_id: "UA-151868570-1"
  anonymize_ip: false # default

You want:

analytics:
  provider: "google-universal"
  google:
    tracking_id: "UA-151868570-1"
    anonymize_ip: false # default
deepns commented 5 years ago

Thank you. That solved the problem. My bad, I missed to notice the misconfiguration in _config.yml.