Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Noosphere1 on
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
Which tracking code? There
Which tracking code? There are modules for several of the services.
Hubspot tracking code
Thank you for replying to my question. The tracking code is from Hubspot:
Yes, there are several
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.
Having trouble finding the suggested template
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
It would normally sit under
It would normally sit under your sites root directory at sites/all/themes/THEMENAME/page.tpl.php
Am I entering the correct URL?
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
I found some sites/all/themes/noosphere files. Will any work?
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
Open
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
How do you refresh the theme cache?
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
How to clear theme cache
See http://drupal.org/node/337176
adding tracking code
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.
How to include tracking code to certain pages
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....
As described above, you will
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
Hook_page_alter
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...