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?
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?
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?
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.
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>
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.
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!
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.
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.