jekyll-now
jekyll-now copied to clipboard
Connecting to Google Analytics 4
Hi,
I'm trying to connect my GitHub page to Google Analytics.
I created an Analytics account (a Analytics 4 account) and got a Measurement ID
instead of a tracking code
.
I tried to add my Measurement ID
into the _config.yml
but it didn't work.
# Enter your Google Analytics web tracking code (e.g. UA-2110908-2) to activate tracking
# Added measurement ID instead of tracking code (which is missing)
google_analytics: G-31B2ABCDEF
What am I doing wrong? What can I do to make Analytics work? I'm a newbie in web development, so forgive me if this is trivial. Thanks a lot!
Edit: Possibly related issue: https://github.com/Automattic/wp-calypso/issues/46664
Update: I was able to configure the old Google Analytics version using this link: https://support.google.com/analytics/answer/10269537
I'm leaving this issue open because Analytics stops supporting the old version in a year.
Running into the same problem right now. Hoping this will get fixed.
@avihu111 @marcandrelutz
Hi! I also encountered the same problem, but I have solved it. You can use a Measurement ID instead of a tracking code. It works for me.
# Enter your Google Analytics web tracking code (e.g. UA-2110908-2) to activate tracking
# Added measurement ID instead of tracking code (which is missing)
google_analytics: G-XXXXXXXXXX
I don't know if my solution can help you.
Here is old versionsolution:
<!-- 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','//www.google-analytics.com/analytics.js','ga');
ga('create', '{{ site.google_analytics }}', 'auto');
ga('send', 'pageview', {
'page': '{{ site.baseurl }}{{ page.url }}',
'title': '{{ page.title | replace: "'", "\\'" }}'
});
</script>
Here is my versionsolution:
<!-- 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('event', 'page_view', {
page_title: '{{ page.title | replace: "'", "\\'" }}',
page_location: '{{ site.baseurl }}{{ page.url }}',
send_to: '{{ site.google_analytics }}'
});
gtag('config', '{{ site.google_analytics }}');
</script>
Refer to: google_analytics answer
The above solution should be checked in!! My blog didn't have the track data for the whole year!!!