jekyll-now icon indicating copy to clipboard operation
jekyll-now copied to clipboard

Connecting to Google Analytics 4

Open avihu111 opened this issue 2 years ago • 4 comments

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

avihu111 avatar Jun 26 '22 11:06 avihu111

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.

avihu111 avatar Jun 27 '22 06:06 avihu111

Running into the same problem right now. Hoping this will get fixed.

stunlocked94 avatar Nov 24 '22 16:11 stunlocked94

@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 togoogle_analytics answer

google analytics devguidesmigration/

Oraer avatar Feb 10 '23 12:02 Oraer

The above solution should be checked in!! My blog didn't have the track data for the whole year!!!

yuqianyi1001 avatar Jan 15 '24 01:01 yuqianyi1001