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

Connecting to Google Analytics 4 #2000

Open
avihu111 opened this issue Jun 26, 2022 · 4 comments
Open

Connecting to Google Analytics 4 #2000

avihu111 opened this issue Jun 26, 2022 · 4 comments

Comments

@avihu111
Copy link

avihu111 commented Jun 26, 2022

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: Automattic/wp-calypso#46664

@avihu111 avihu111 changed the title Connecting to Google Analytics Connecting to Google Analytics 4 Jun 26, 2022
@avihu111
Copy link
Author

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.

@stunlocked94
Copy link

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

@Oraer
Copy link

Oraer commented Feb 10, 2023

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

@yuqianyi1001
Copy link

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

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