Adding tracking code immediately the open body tag

Hi - I’m working on a website that has a marketing company working on it too - they want me to add some tracking code immediately after the opening body tag…

How can I do this? Cheers!!

Which version of RW are you using and do you want the tracking code on selected pages or every page?

The latest version, every page - thanks

The RW method inserts the code at the bottom of the body, not the top but you can try that. In the left hand page panel at the bottom go to Settings > Code > Body. You can insert the code there. But as I say, it is inserted at the top of the body.

The only way I know to place code just after the opening body tag would be to insert the code in the Theme html. WARNING: Never edit your theme html file unless you have backed up (made a copy of) your theme html file. You need to always be able to restore your theme html if something goes wrong. But it is a sure way of getting the code where you want it. Locate your theme, right click to Show Package Contents, and look for for index html file. Insert the code immediately after the opening body tag. I assume here you are using a standard RW theme. I also assume you know that you need to use a plain text editor like bbedit or textwrangler when you do this.

2nd Warning: You can mess up things beyond repair if you break your theme html file. Be wise - use caution. I’d have a duplicate of the entire Rapidweaver folder (that contains the add-ons) and also a copy of the theme itself PLUS your own copy of the original theme html file.

Perhaps others here know of another way to place the code exactly after the opening body tag. I’d let others respond before you do anything. And try inserting the code the standard RW method and see if that works.

Might help if you give us more on type of code your your inserting. What’s it used for,who is supplying it etc.

Most tracking codes like Googles tag manager, and Analytics go into the head section, not the body.

Thanks Greg - That’s what I had done already I duplicated the theme and added there. You can see the specific code right under the opening Body tag here

But was really wondering if there was a cleaner way of doing this, obviously not.

Cheers all!

Using Foundation theme, that will get overlayed with each update.
Looks like your using Google’s Tag Manager. I’m not an expert on that but using the hidden iFrame approach I thought was only for non-JavaScript sites.

I think you can add the tracking code via JavaScript inserted in the head section.

Look under website installation on this link:

1 Like

Thank you - just dont want to get into a too and throw with this marketing company, it’s what they want, then they shall get - when Foundation updates it does not overwrite the duplicate, does it? I was thinking I simply duplicate the new version and run in that script - it’s so quick and simple - I dont foresee this being too much of a pain - update are not so often either (nor to the actual webiste either)

When foundation updates, the theme and the stacks must be kept in sync. That means you’re duplicate theme, could misbehave.

I never let marketers, or users tell me how to code or implement something. Find out what the objective is and find the best way to implement. Otherwise you’re going to end up with a maintenance nightmare.

The link above has links on how to test. As long as the GTM-xxxx Is correct then the marketing folks get what they wanted, and you have an much easier to maintain site.

I’m doing this from memory but couldn’t you use an html stack at the top of the page in a foundation theme and it will appear right after the opening body tag?

I thought so too, but that isn’t working for me. The website displayed as it should in safari but not in Chrome.

The Tag Manager script is placed in HEAD but there’s some HTML code (iFrame as shown below) that has to be placed right after opening BODY tag - if not placed there, Tag Manager analysing doesn’t work. I struggle with that issue right now - trying to optimize to Google new “standards”

You need to mark the code as preformatted text on this forum or it won’t show up.

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

The easiest way is to start with a line with three back-ticks ` (right to the left of the number 1 on standard keyboards). Then end it with a line of three more back-ticks.

I’m no expert on tag manager (I don’t use Google for much). The code I show above is from here:
웹페이지용 Google 태그 관리자  |  Google Tag Manager for Web  |  Google for Developers

If your code is different then you’ll need to repost it for us to see it.
There is no way in RapidWeaver to put code directly below the opening body tag. The best you can do for a stacks page, place it into an HTML stack and make it the first thing on the page.

As I said I don’t know much about Google tag manager, but I can tell you that the iFrame is surrounded by <noscript> tags so it should only be invoked if the browser has JavaScript turned off (less than 1% worldwide). So my guess is if the tag manager isn’t working it’s probably not that the noscript code is missing.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.