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

how to set google analytics? #3

Open
Oran-Ac opened this issue Dec 4, 2021 · 3 comments
Open

how to set google analytics? #3

Oran-Ac opened this issue Dec 4, 2021 · 3 comments

Comments

@Oran-Ac
Copy link

Oran-Ac commented Dec 4, 2021

Hi, I would like to ask if the google analytics can be used by just changing the settings in _config.yml
google_analytics: UA-111540567-4
I tried but I couldn't get any data in google analytics

@Oran-Ac Oran-Ac changed the title how how to set google analytics? Dec 4, 2021
@yaoyao-liu
Copy link
Owner

If changing the setting in _config.yml doesn't work, you may replace the following lines in /_layouts/homepage.html with the code provided by Google Analytics:

<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>

@shuhanmirza
Copy link

@yaoyao-liu please replace the code for g-analytics with below code. I intended to open a PR for this. However, the repo does not provide permission to create a new branch.

    {% if site.google_analytics %}
    <!-- Google tag (gtag.js) -->
    <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>
    {% endif %}

@MING-ZCH
Copy link

MING-ZCH commented Aug 5, 2024

@yaoyao-liu please replace the code for g-analytics with below code. I intended to open a PR for this. However, the repo does not provide permission to create a new branch.

    {% if site.google_analytics %}
    <!-- Google tag (gtag.js) -->
    <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>
    {% endif %}

hi, I tried your code but failed, too. Is this the completed code?

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

No branches or pull requests

4 participants