You are here

function crazyegg_footer in Crazy Egg Integration 6

Implements hook_footer() to insert JavaScript to the appropriate scope/region of the page.

File

./crazyegg.module, line 42

Code

function crazyegg_footer($main = 0) {
  global $user;
  $account_id = variable_get('crazyegg_account_id', '');
  $crazyegg_enabled = variable_get('crazyegg_enabled', TRUE);
  if ($account_id && $crazyegg_enabled) {
    $scope = 'footer';
    $account_path = str_pad($account_id, 8, "0", STR_PAD_LEFT);
    $account_path = substr($account_path, 0, 4) . '/' . substr($account_path, 4, 8);
    $account_path = "pages/scripts/" . $account_path . ".js";
    $script_host = "dnn506yrbagrg.cloudfront.net";
    $script = '
      setTimeout(function(){var a=document.createElement("script");
      var b=document.getElementsByTagName(\'script\')[0];
      a.src=document.location.protocol+"//' . $script_host . '/' . $account_path . '";
      a.async=true;a.type="text/javascript";b.parentNode.insertBefore(a,b)}, 1);
      ';
    drupal_add_js($script, 'inline', 'footer');
  }
}