I'm trying to insert a JavaScript code on a specific page using Tracking Code Snippets module, but it does not seem to work (there's a bug in it). Specifically, I want the code to be inserted only on a specific page (URL path .html) inside the tag. Anyone knows of a module / easy solution (without changing the code of my .tpl files) to do that? Thanks!

  • Notice that requests for module are off-topic, and easy solution is rather subjective_.
    – apaderno
    Nov 7, 2016 at 20:39

2 Answers 2


You can place it in a block that only displays on that page.

If you want it in the head, there's a module that does it for you: Add To Head

  • Thanks! Do you think it'll slow everything down to do it via the block? Nov 7, 2016 at 19:53
  • As far as Drupal goes it shouldn't slow anything down. Mostly depends upon the Javascript.
    – Will
    Nov 7, 2016 at 19:58
  • Ok, with the block it won't work because I don't have a setting in my theme to display it inside the <head> tag... Unless I didn't notice another way of doing it? Nov 7, 2016 at 20:19
  • Blocks don't go in the head. If you need it in the head, you can use the module I mentioned or blu's answer.
    – Will
    Nov 7, 2016 at 20:34

in your themes template.php you can add this to node preprocess:

function MY_THEME_preprocess_node(&$vars) {
    if($vars['nid'] == 'XX'){

this checks for only node pages that match the node ID. you can also change drupal_add_js to have the javascript placed at the footer instead of header.

Not the answer you're looking for? Browse other questions tagged or ask your own question.