Move the Doogle Analytics bit - Post...

User 2699991 Photo


Registered User
4,993 posts
Online Now

Now that Google have forced their new GA4 thingy onto those that use it, and it requires the code to be placed immediately after the <head> stuff, please consider (for those that use Google analytics on SD) to the top of the "Page Manager" bit, to save having to edit the project file after exporting, (personally I don't, but a client with 147 pages (all with GA4) and all that are regularly updated does,, phew it takes ages and ages to get it published and with all that in the right position.

Unless of course I am missing somesthing simple like an easier way to do it :D:D
Mastering The Understanding With Hands-On Learning
NEW TO "COFFEECUP SITE DESIGNER" FOUNDATION 6 FRAMEWORK?
STUCK ON SOMETHING?

LEARNING & UNDERSTANDING "THE HOW TO"? THE WHY'S & THE WHEREFORE'S?
WITH WAYAN'S STEP BY STEP TUTORIALS
Contact Me For One To One Assistance
https://mawarputih.coffeecup.com/forms/contact-wayan/

A simple quick way to contact me
https://rsd-tutorialscom.coffeecup.com/ … l-details/
User 379556 Photo


Registered User
1,554 posts

If I'm correct in thinking that the chunk of code is to be placed between the closing </head> tag and the opening <body> tag, perhaps it's possible to do it for all 147 pages in one go by a Regular Expression 'find and replace' using TextCrawler on a local export of the project.

Find: Reg Ex </head>
Replace </head>\r\n The code to be added \r\n


Frank
User 2699991 Photo


Registered User
4,993 posts
Online Now

Hi Frank
It has to be placed immediately after the <head> before everything else. Unless I have misunderstood the Google instructions;)
Mastering The Understanding With Hands-On Learning
NEW TO "COFFEECUP SITE DESIGNER" FOUNDATION 6 FRAMEWORK?
STUCK ON SOMETHING?

LEARNING & UNDERSTANDING "THE HOW TO"? THE WHY'S & THE WHEREFORE'S?
WITH WAYAN'S STEP BY STEP TUTORIALS
Contact Me For One To One Assistance
https://mawarputih.coffeecup.com/forms/contact-wayan/

A simple quick way to contact me
https://rsd-tutorialscom.coffeecup.com/ … l-details/
User 379556 Photo


Registered User
1,554 posts

Hi Wayan.

The question is whether the Google instructions refer to the <head> tag or the <head> element. In my view those instructions are ambiguous. I therefore looked elsewhere and found the following.

https://www.websitebuilderexpert.com/bu … et-up-ga4/ says "Select the ‘Install manually’ tab, and copy the Google tag that appears. Then, paste this snippet of code into every page of your website, immediately after the <head> element.

If it is the <head> tag, then my previous post would need to have the two </head> items changed to <head>.

Frank
User 2699991 Photo


Registered User
4,993 posts
Online Now

Hmm yes confusing
If it has to go immediately after the CLOSING </head> tag, then thats easy by placing a HTML element, onto the body before anything else, and inserting the code there (make it a symbol so easy to put onto every page.

I have been putting it into the <head> bit right at the top (before the <meta charset="utf-8">
IE
<head>
><!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id="xxxxxxxxxxx "></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', ' xxxxxxx ');
</script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="generator" content="RSD 5.0.3541">
<meta name="description" content=" xxxxx ">
<title>xxxxxxxx</title

I have had it this way now since the start of the new GA4 (june 2023) and it works OK getting results information etc )
However the site hase been updated already and now needs that GA4 code putting back, I think I may try it after the </head> thingy, (before the <body> thingy on a testing website, to see if it still works with the code in that position, if so then happy as I can place it in a HTML element on the body on every page thereafter
Fingers crossed.

Mastering The Understanding With Hands-On Learning
NEW TO "COFFEECUP SITE DESIGNER" FOUNDATION 6 FRAMEWORK?
STUCK ON SOMETHING?

LEARNING & UNDERSTANDING "THE HOW TO"? THE WHY'S & THE WHEREFORE'S?
WITH WAYAN'S STEP BY STEP TUTORIALS
Contact Me For One To One Assistance
https://mawarputih.coffeecup.com/forms/contact-wayan/

A simple quick way to contact me
https://rsd-tutorialscom.coffeecup.com/ … l-details/
User 379556 Photo


Registered User
1,554 posts

Hi Wayan.

Your practical test sounds wise.

I wonder whether someone can find a definitive answer regarding the ambiguity. Does Google itself perhaps have somewhere an example showing exactly what is meant?

I think that https://support.google.com/analytics/an … l-manually under the heading 'How to manually install the Google tag' may confirm that they mean the <head> element rather than the <head> tag, but it goes on to say that, if you're using a website builder, it can go into 'the platform's custom HTML field'. Your idea of using the HTML element therefore sounds promising.

Frank

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.