XF 2.2 Add Google Analytics 4

polle

Active member
How to add the new Google Analytics 4 code?

When trying the new format this pops up:

Code:
Please enter your Google Analytics web property ID / UA number in the format UA-XXXXXX-Y.

Thanks.
 

supertrenxxx

New member
It works for me...
Otherwise you can remove the old code in ACP and just paste the GA4 tag in PAGE_CONTAINER template between <head> tags
Can you kindly tell me how to do this?, just paste all the js google code?:

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

gtag('config', 'G-CODE_XXXX');
</script>
 

supertrenxxx

New member
Are you sure the code is pated between the <head> tags in PAGE-CONTAINER template ?
Yes:

{{ $xf.runJobs ? ' data-run-jobs=""' : '' }}>
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-2W50S2JLXB"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-2W50S2JLXB');
</script>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">

(...)

Same error:

Oops! We ran into some problems.
Oops! We ran into some problems. Please try again later. More error details may be in the browser console.
 

supertrenxxx

New member
Check the browser inspector (F12) then the Console tab.

I suspect there will be a 403 error which is due to the server - either modsec, or mod_evasive.
Could I modify the template locally with notepad and upload the template via ftp?, do you know where is the path of this template in the server public_html directory?
 

JoyFreak

Well-known member
I upgraded my GA to the new GA4 today. Does it automatically associate itself to the old analytics? @nicodak has suggested nothing is needed to be changed in the Admin CP. Does that mean I do not need to copy the script tag into <head> of my site?
 

spirogg

Active member
hello I just created a new UA and g4 code in google analytics.. I am just starting so I did not know which one is needed for Xenforo ACP, so I just created both since it gave me that option.

What I did next was:

I went to the setup page in Xenforo ACP it asks for a code either UA or G so I entered the G-XXXXXXXXXX code.

- On google analytics : at the top right of the page when I created it, in web stream details > it has a code on the top right > that says "Measurement ID" and below is the code that starts with G-XXXXXXXXXXX.

Just asking If I have it right?

- I just added that code into Xenforo ACP analytics filed and saved.

- Do I have to add any js script in the templates
like the old UA code which was < google analytics UA-XXXXXXXX> script etc... ?

or just what I did added the G4-XXXXXXX code into Xenforo ACP ?

thanks so much in advance trying to get ready to go to production in my forum so still setting things up


Kind Regards
Spiro
 

spirogg

Active member
Which one? Which of the options worked for you?
When you sign up for google analytics during adding your domain and information. There is an advance link at the bottom. You click on that and select that you want to create both old UA and new G4 analytics ID’s. Then it created both. So I could use one or the other. So I just added the newest G-XXXXXXXX and it worked. :)
 
Last edited:

Sal Collaziano

Well-known member
Received this via email today:

"The new, more intelligent Google Analytics experience is here. This next generation of Google Analytics will take your digital analytics to a whole new level by delivering the essential customer insights you need. In order to experience this new Analytics, you will need to upgrade to Google's latest dynamic tagging solution."

Will there be a notice when the new tag is added to XenForo and will everything be seamless or is there something that needs to be updated on the Google Analytics account side?
 
Top