Adding tracking code immediately the open body tag


(Justin) #1

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


(Greg Schneck) #2

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


(Justin) #3

The latest version, every page - thanks


(Greg Schneck) #4

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.


(Doug Bennett) #5

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.


(Justin) #6

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!


(Doug Bennett) #7

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:

https://support.google.com/tagmanager/answer/6103696


(Justin) #8

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)


(Doug Bennett) #9

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.


(Michael Forte) #10

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?


(Nicko) #11

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