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

Google Analytics #88

Closed
omerayyildiz opened this issue Oct 21, 2020 · 11 comments
Closed

Google Analytics #88

omerayyildiz opened this issue Oct 21, 2020 · 11 comments

Comments

@omerayyildiz
Copy link

omerayyildiz commented Oct 21, 2020

How can I add google analytics to my page?

Although I added an analytics.html file into the _includes folder and linked it to the config.yml file but google could not pull any data.

my page: https://omerayyildiz.com/nishgt
my repository: https://github.com/omerayyildiz/nishgt

@pedrominicz
Copy link

You can add by setting site.google_analytics in _config.yml.

@omerayyildiz
Copy link
Author

i did that but it didn't work
image
image

@pedrominicz
Copy link

pedrominicz commented Oct 22, 2020

site. is implicit in _config.yml. Change your _config.yml as follows:

logo: /assets/img/banner.jpg
theme: jekyll-theme-minimal
google_analytics: G-XXXXXXXXXX

@omerayyildiz
Copy link
Author

Not working :/
image

@omerayyildiz
Copy link
Author

Thanks for help but I give up :/

@mmvanheusden
Copy link

The problem is caused by Google Analytics 4

@omerayyildiz
Copy link
Author

What's problem in Google Analytics 4?

@ChristopherBull
Copy link

I am experiencing this issue too. When you create a new account/property in Google Analytics, it defaults to Google Analytics 4 which (as I understand it) is not backwards compatible with previous collection JS files from before Nov 2020.

The problem (and solutions) with Google Analytics 4 in Jekyll themes are summarised in other similar repositories, e.g.:

@mosaicgeospatial
Copy link

For anyone else having this problem, here is how I solved it.
Add your google analytics tag to _config.yaml as stated previously:
google_analytics: G-XXXXXXXXXX

Make your own _layouts/default.html file - copy the contents from the same file in the minimal repository:
https://github.com/pages-themes/minimal/blob/master/_layouts/default.html

Find the following section at the bottom of the file:

    <script>
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
      ga('create', '{{ site.google_analytics }}', 'auto');
      ga('send', 'pageview');
    </script>

Replace it with this:

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

@mmvanheusden
Copy link

@mosaicgeospatial Could you open a pull request for this?

@pedrominicz
Copy link

I created a pull request with @mosaicgeospatial's changes. Also, @omerayyildiz, please keep the issue opened until it has been fully resolved.

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

Successfully merging a pull request may close this issue.

5 participants