solved New Google Analytics GA4

researchcooperative
@researchcooperative
last year
694 posts
Today I received the notice from Google about switching over to GA4. For manual installation (not using the Google tools for major CMS products) they give instructions for manual installation, as below. Exactly how do we place this script in our own site? Will the updated JR module be able to do this for us?! (I have taken out the html brackets)

Thanks, hopefully... Peter

" Install the Google tag manually

Below is the Google tag for this account. Copy and paste it in the code of every page of your website, immediately after the head element. Don’t add more than one Google tag to each page. "

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

gtag('config', 'G-blahblahblah');
/script




--
PJ Matthews, Kyoto
Migrated from Ning 2.0. Now at Jamroom 6 beta and using Jamroom Hosting for The Research Cooperative (researchcooperative.org)

updated by @researchcooperative: 05/10/23 10:03:32AM
michael
@michael
last year
7,713 posts
That looks like the same code used in the 'GLOBAL' setting of the module.
ACP -> MODULES -> SITE -> GOOGLE ANALYTICS -> GLOBAL CONFIG -> ENABLED ANALYTICS
global.jpg
global.jpg  •  249KB

GLOBAltxt.jpg
GLOBAltxt.jpg  •  272KB


updated by @michael: 02/07/23 01:43:44PM
researchcooperative
@researchcooperative
last year
694 posts
Thanks.

Just now I tried to replace the existing global.tpl content with exactly what Google provided, and was given the following error message by the JR system. What can be done next?

P.

There are syntax error(s) in your template - please fix and try again:
Syntax error in template "data/cache/jrCore/test_template_ga449sve.tpl" on line 5 "function gtag(){dataLayer.push(arguments);}" - Unexpected ".", expected one of: "}"


--
PJ Matthews, Kyoto
Migrated from Ning 2.0. Now at Jamroom 6 beta and using Jamroom Hosting for The Research Cooperative (researchcooperative.org)
michael
@michael
last year
7,713 posts
dont change the template, just make sure your setting is set to GLOBAL and your analytics ID is correct then there's nothing left to do.
researchcooperative
@researchcooperative
last year
694 posts
Hmmm... looked again at the JR code and the Google script and found different use of empty spaces. After changing the spaces, JR system accepted the script:
"The template has been successfully updated"

So I will reset the caches and see what happens next!


--
PJ Matthews, Kyoto
Migrated from Ning 2.0. Now at Jamroom 6 beta and using Jamroom Hosting for The Research Cooperative (researchcooperative.org)