diff --git a/crazyegg.module b/crazyegg.module
index 5f3556f..f012493 100644
--- a/crazyegg.module
+++ b/crazyegg.module
@@ -40,31 +40,25 @@ function crazyegg_help($path, $arg) {
 }
 
 /**
- * Implements hook_page_alter() to insert JavaScript to the appropriate scope/region of the page.
+ * Implements hook_page_alter().
  */
 function crazyegg_page_alter(&$page) {
-  global $user;
-
   $account_id = variable_get('crazyegg_account_id', '');
   $crazyegg_enabled = variable_get('crazyegg_enabled', TRUE);
+  $js_scope = variable_get('crazyegg_js_scope', 'footer');
 
-  if ($account_id && $crazyegg_enabled) {
-
-    $scope = 'footer';
-
+  if (!empty($account_id) && !empty($crazyegg_enabled) && !empty($js_scope)) {
     $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_host = "script.crazyegg.com";
 
-    $script = '
-      setTimeout(function(){var a=document.createElement("script");
-      var b=document.getElementsByTagName(\'script\')[0];
-      a.src=document.location.protocol+"//' . $script_host . '/' . $account_path . '"+Math.floor(new Date().getTime()/3600000);
-      a.async=true;a.type="text/javascript";b.parentNode.insertBefore(a,b)}, 1);
-      ';
-
-    drupal_add_js($script, array('scope' => $scope, 'type' => 'inline'));
+    // Output the JS code in the requested page region.
+    $script = 'setTimeout(function(){var a=document.createElement("script");
+var b=document.getElementsByTagName(\'script\')[0];
+a.src=document.location.protocol+"//' . $script_host . '/' . $account_path . '"+Math.floor(new Date().getTime()/3600000);
+a.async=true;a.type="text/javascript";b.parentNode.insertBefore(a,b)}, 1);';
+    drupal_add_js($script, array('scope' => $js_scope, 'type' => 'inline'));
   }
-}
\ No newline at end of file
+}
diff --git a/includes/admin.inc b/includes/admin.inc
index 07d877d..616fd80 100644
--- a/includes/admin.inc
+++ b/includes/admin.inc
@@ -33,5 +33,16 @@ function crazyegg_admin_settings_form() {
       '#markup' => $account_explanation,
   );
 
+  $form['crazyegg_js_scope'] = array(
+    '#type' => 'radios',
+    '#title' => t('Location to add code'),
+    '#description' => t('Controls where on the page the JavaScript code is added.'),
+    '#default_value' => variable_get('crazyegg_js_scope', 'footer'),
+    '#options' => array(
+      'header' => t('Header'),
+      'footer' => t('Footer'),
+    ),
+  );
+
   return system_settings_form($form);
-}
\ No newline at end of file
+}
