I am a total newcomer to Drupal, so please forgive me if I am posting in the wrong place or violating any rules.

I need to add tracking code to all of our pages and it must go right before the end body html code. The problem is that I can't find the end body html code when I go to view or edit a page. How can I access all of the code for a page to add the tracking code? Also, is there a way to set up adding the tracking code globally to all pages without having to enter it manually page by page?

Thank you for your help!

Comments

nevets’s picture

Which tracking code? There are modules for several of the services.

Noosphere1’s picture

Thank you for replying to my question. The tracking code is from Hubspot:

<script type="text/javascript" language="javascript">
var hs_portalid=90336; 
var hs_salog_version = "2.00";
var hs_ppa = "noospheremarketing.app9.hubspot.com";
document.write(unescape("%3Cscript src='" + document.location.protocol + "//" + hs_ppa + "/salog.js.aspx' type='text/javascript'%3E%3C/script%3E"));
</script>
rbayliss’s picture

Yes, there are several modules to do exactly this. If one of those doesn't work for you, find the file page.tpl.php in whichever theme you are using (usually found inside /sites/all/themes/YOURTHEMENAME/templates/page.tpl.php) and add it to the bottom of the page. That should add it to each page of the site.

Noosphere1’s picture

Thank you so much for trying to help me.
I have attempted to find the page.tpl.php path you suggested, but so far I have not been able to do so. I tried http://www.noospheremarketing.com/admin/sites/all/themes/noosphere/templ...
but got a page not found error message. Can you suggest something else to try that will get me to this template?
Thank you again!
Robert

nevets’s picture

It would normally sit under your sites root directory at sites/all/themes/THEMENAME/page.tpl.php

Noosphere1’s picture

Thank you for trying to help me.

From within the control panel, http://www.noospheremarketing.com/admin, I am pasting: http://www.noospheremarketing.com/admin/sites/all/themes/noosphere/templ...
and then I am getting the page not found error message. Is this the correct way to do this, or is there a way to access the php from one of the drop downs in the control panel?

Thank you again,

Robert

Noosphere1’s picture

I tried to find the files directly within the control panel where the site is hosted. The closest I come to /sites/all/themes/noosphere/templates/page.tpl.php is a list of the files which follow. Will any of these files work to install the tracking code?
Thank you again for your help!
Robert

/public_html/sites/all/themes/noosphere/node-right_form.tpl.php
/public_html/sites/all/themes/noosphere/node-bucket.tpl.php
/public_html/sites/all/themes/noosphere/administration-panel.tpl.php
/public_html/sites/all/themes/noosphere/block.tpl.php
/public_html/sites/all/themes/noosphere/page.tpl.php
/public_html/sites/all/themes/noosphere/node-free_text.tpl.php
/public_html/sites/all/themes/noosphere/node-resources.tpl.php
/public_html/sites/all/themes/noosphere/views-view-fields--News.tpl.php
/public_html/sites/all/themes/noosphere/page3.tpl.php
/public_html/sites/all/themes/noosphere/box.tpl.php
/public_html/sites/all/themes/noosphere/comment.tpl.php
/public_html/sites/all/themes/noosphere/node.tpl.php
/public_html/sites/all/themes/noosphere/.svn/text-base/page.tpl.php.svn-base
/public_html/sites/all/themes/noosphere/.svn/text-base/box.tpl.php.svn-base
/public_html/sites/all/themes/noosphere/.svn/text-base/node.tpl.php.svn-base
/public_html/sites/all/themes/noosphere/.svn/text-base/administration-panel.tpl.php.svn-base
/public_html/sites/all/themes/noosphere/.svn/text-base/comment.tpl.php.svn-base
/public_html/sites/all/themes/noosphere/.svn/text-base/node-resources.tpl.php.svn-base
/public_html/sites/all/themes/noosphere/.svn/text-base/block.tpl.php.svn-base
/public_html/sites/all/themes/noosphere/.svn/text-base/node-free_text.tpl.php.svn-base
/public_html/sites/all/themes/noosphere/.svn/text-base/node-bucket.tpl.php.svn-base

Patroclas’s picture

Open /public_html/sites/all/themes/noosphere/page.tpl.php in a text editor (No 5 from the top of your list) - that should be the one you need. Remember to refresh the theme cache after you save it

Noosphere1’s picture

Thank you so much! I think I am getting there. Can you tell me how to refresh the theme cache? I don't want to mess up anything.
Thank you again,
Robert

Patroclas’s picture

cobey’s picture

Hello.... I am new at this too. I am trying to add tracking code to 2 pages of my site. I have an example of what it should look like in the source code; however, I don't know how to access the html code within drupal. Is there a simple way to do this? I'm not advanced enough to be adding modules, etc. To date, I have only added/edited text within the site. Your guidance greatly appreciated.

JPCloutier’s picture

I am looking to do the same where I have tracking code that only needs to be added to my "Call-To-Action" pages (ie. Request a Demo, contact us, etc....

Patroclas’s picture

As described above, you will need to access and edit template pages (they will have the suffix 'tpl.php'). These are in your theme folder and you can fine tune them without too much difficulty if you know a bit of html and maybe some very simple php.

You can search for info on how to name files to be used for specific nodes etc and you could take a look here...
http://drupal.org/node/290410

The naming of the files is different in D6 and D7

bibliophileaxe’s picture

You could use hook_page_alter. I recently had to do this to add tracking code before the closing body tag and I used hook_page_alter and added the content to $page['page_bottom'].

https://api.drupal.org/api/drupal/modules%21system%21system.api.php/func...