Site wide code and Google Tag Manager

I love the new site-wide code feature of RW7.

I use Google Tag Manager (GTM) to track users/pages/downloads etc. The Tag Manager code needs to be added to every page of a website. So far, so good for site-wide code.

BUT Google says the code needs to be added at the beginning of the page, just after the <BODY> tag. RW site-wide code adds the code at the bottom of the page, just above the </BODY> tag.

I have fudged, and added the GTM code to the Header, but this is not ideal.

Message to Realmac developers: can we have the option of adding site-wide code to the top of the <BODY>, not at the bottom?

1 Like

Thanks for posting my question for me embert :slight_smile:

I’d love to know the answer to this too. Very very interested to know.

Did anyone work out how to do this. I’ve tried a few options and varioustions, but can’t seem to get GTM to work correctly. In particular, google chrome is doing funny things.

This post was posted in August 2016. Was this ever resolved as I’m still seeing the same thing in Rapidweaver 8.7 and it’s November 2020. I can’t see a reply from Rapidweaver up here.

Is there a solution to this issue or a way to put Google Tag Manager code at the top of the code rather than at the bottom as this poster asked four years ago?

Thanks

A shot in the dark but have you tried this:

It puts the code two or three lines from the top of the <body> depending on what stacks you are using. In my case there are a couple of <div> lines for foundry but I’m not sure if they will make any difference or if it would break foundry as it’s supposed to be at the very top. In this case what you want isn’t going to reference foundry so I wonder if it would work?

1 Like

Ooh, now that’s a good suggestion, I’ll give it a shot and see if it works or breaks! Thanks for the prompt reply.

Hi Nick

Well it didn’t break Foundry or my website to move the code into an HTML at the top as you suggested.

However, I’m still seeing the error message in google tag assistant as below. However, it seems to be working in that tags are firing and google analytics tracking is working on the site so maybe it’s fine.

I’m not enough of a GTM expert to be able to say whether this is causing a problem or not. I’ve got my analytics tracking working through GTM but I’d have thought this message would have disappeared if it was acceptable.

This was the same message I was getting when the code was placed in the ā€˜body’ section of the code editor in RapidWeaver.

Screenshot 2020-11-26 at 10.55.46 AM

This may also be a kludge but the GTM code is going to be in the middle of some Foundry statements so perhaps this.

Start your code with </div></div> to close those statements
Then add the GTM code
Finish your code with <div><div> so that foundry can close them properly.

quick edit, I don’t think there are enough divs and this is beginning to look like a dirty hack. Gone to count them.

finale edit:- miight work if you start with 4 * </div>, then the GTM code and finish with 4 * <div>

Thanks Nick

I sent on the question and a link to this thread to Adam @Elixir to ask for his views as the genius behind Foundry, so I’ll see what that brings to the discussion too.

JP

1 Like

Good idea, my knowledge is way lacking for looking at code. I even had to read up on what a DIV was so at least I understand that now and could probably conclude that they do no harm to the GTM code snippet.

Reading up on GTM it would prefer to have the code snippet as close to the top of body as possible but not matter too much if it’s not quite there. So maybe you’ll win this.

I can’t for the life of me understand why Google tase manager integration hasn’t been addressed yet. I don’t normally like to criticise a small business - particularly a British one, but come on Realmac!

1 Like

I have my GTM code in an HTML stack which is inside a Partial with my Foundry Control Center and Typeface stacks. It’s the first stack in the partial. I’m pretty sure I created the partial from one stack and then pasted the other stacks in. The HTML stack is the first stack in the partial. It is not in any other stacks. When I view my page source, it’s the first code in the body tag.

When you view the source, make sure you look at an actual source file either exported to a local folder or from the actual folder on the server using a text editor. When I do that, I see that the GTM code is the first code within the body tag. If I just view it through a browser’s dev tools, it’s not the first code. GTM and other scripts can move things around on page load, so you can’t just go by that.

2 Likes

There is no easy fix for RealMac on this.

Every theme from every developer would need to change in order to accommodate anything RealMac would do.

The Theme (and yes, every RW website uses a theme even the Frameworks) code the HTML body tag. The Theme developer determines what code and how much stuff gets placed between the ā€œopeningā€ body tag and the actual content (%content% theme variable).

A traditional theme like one from ThemeFlood, Michael David Design or MultiTheme can have a ton of code like navigation Logos and more between the opening <body tag and where the main content starts. So placing code in an HTML stack at the top probably would be less effective, and would only work on a stacks page.
Even some frameworks can have some code after the opening body tag and before the %content% variable.
Foundry has a division tag (<div class="blur_wrapper">, and don’t forget those pesky Stacks-in and stacks-out divisions that the html stack puts on the page. So technically the code wouldn’t be the first thing but pretty close.
I do not understand how important it is for the code to be ā€œimmediately after the opening <body> tagā€.
So RealMac would need to add a new theme variable, provide a place for you to add the code in the UI, and then the theme developers would need to add that new variable to each theme in the proper place.