How do I add a block of JavaScript to the home page only? I have a block of JavaScript I need to add to my homepage (and only my homepage) to enable the logging of clicks via a heat mapping service I signed up for.

They specified the code needed to be placed just before the &lt;/body&gt; tag, but I imagine it's safe to put it anywhere within the &lt;body&gt; tag.

I'd like the snippet not to appear on any other pages. How can I accomplish this?

I am running Drupal 6.
If by home page you mean the front page, then you can implement hook_preprocess_page() in a custom module.

function mymodule_preprocess_page(&amp;$variables) {
  if ($variables['is_front']) {
    drupal_add_js(drupal_get_path('module', 'mymodule') . '/mymodule.js');
    $variables['scripts'] = drupal_get_js();
  }
}


The same code works on Drupal 7, as $variables['is_front'] is set in _template_preprocess_default_variables() (called from template_preprocess()), using the following code.

  // drupal_is_front_page() might throw an exception.
  try {
    $variables['is_front'] = drupal_is_front_page();
  }
  catch (Exception $e) {
    // If the database is not yet available, set default values for these
    // variables.
    $variables['is_front'] = FALSE;
    $variables['db_is_active'] = FALSE;
  }


The reason of calling drupal_add_js() first, and then drupal_get_js() is that, in the case another module that is executed after would run the following code, the JavaScript file would still be added.

function quite_a_different_module_preprocess_page(&amp;$vars) {
  drupal_add_js(drupal_get_path('module', 'quite_a_different_mymodule') . '/quite_a_different_module.js');
  $vars['scripts'] = drupal_get_js();
}


Using drupal_add_js(), the file will be added to the output returned from drupal_get_js().