diff --git a/includes/klaviyo.admin.inc b/includes/klaviyo.admin.inc
index 040ad8b..a2809e5 100644
--- a/includes/klaviyo.admin.inc
+++ b/includes/klaviyo.admin.inc
@@ -48,5 +48,39 @@ function klaviyo_api_integration_settings() {
     );
   }
 
+  $js_settings = variable_get('klaviyo_javascript', array('public_api_key' => '', 'roles' => array()));
+  $form['klaviyo_javascript'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Javascript API'),
+    '#description' => t('The JavaScript API adds automatic tracking of visited pages such as the "Active on site" metric. See <a href="!url">the Klaviyo jasvascript API documentation</a> for more information. Enter the public API key to enable the snippet.',
+      array('!url' => 'https://www.klaviyo.com/docs/getting-started')
+    ),
+    '#collapsible' => TRUE,
+    '#tree' => TRUE
+  );
+
+  $form['klaviyo_javascript']['public_api_key'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Public API key'),
+    '#description' => t('The javascript will not be added if the public key is missing. The public key can be retrieved from Account >> Settings >> <a href="!url">API Keys</a> from within Klaviyo.',
+      array('!url' => 'https://www.klaviyo.com/account#api-keys-tab')
+    ),
+    '#default_value' => $js_settings['public_api_key'],
+    '#size' => 60,
+    '#maxlength' => 128,
+    '#required' => FALSE,
+  );
+
+  // @todo: Add ability for black list vs white list.
+  $form['klaviyo_javascript']['roles'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Remove script for specific roles'),
+    '#default_value' => $js_settings['roles'],
+    '#options' => user_roles(),
+    '#description' => t('Remove script only for the selected role(s). If none of the roles are selected, all roles will have the script. Otherwise, any roles selected here will NOT have the script.'),
+  );
+
+  // @todo: Add ability to exclude on certain pages.
+
   return system_settings_form($form);
 }
diff --git a/klaviyo.install b/klaviyo.install
index 0bf6604..75fa2a5 100644
--- a/klaviyo.install
+++ b/klaviyo.install
@@ -68,6 +68,7 @@ function klaviyo_schema() {
 function klaviyo_uninstall() {
   variable_del('klaviyo_api_key');
   variable_del('klaviyo_drupal_site_id');
+  variable_del('klaviyo_javascript');
   variable_del('klaviyo_entity_settings_user');
   variable_del('klaviyo_person_attributes_user');
 }
diff --git a/klaviyo.js b/klaviyo.js
new file mode 100644
index 0000000..6e80753
--- /dev/null
+++ b/klaviyo.js
@@ -0,0 +1,30 @@
+/**
+ * @file
+ * Provides JavaScript for Klaviyo.
+ */
+
+// Must be in the global namespace so that the Klaviyo 3rd party script may
+// access this variable.
+var _learnq = _learnq || [];
+
+(function ($) {
+
+Drupal.behaviors.klaviyo = {
+  attach: function (context) {
+    var klaviyo = Drupal.settings.klaviyo || {}
+
+    if (klaviyo.public_api_key) {
+      _learnq.push(['account', klaviyo.public_api_key]);
+    }
+
+    if (klaviyo.identify) {
+      _learnq.push(['identify', klaviyo.identify]);
+    };
+
+    var b = document.createElement('script'); b.type = 'text/javascript'; b.async = true;
+    b.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'a.klaviyo.com/media/js/analytics/analytics.js';
+    var a = document.getElementsByTagName('script')[0]; a.parentNode.insertBefore(b, a);
+  }
+};
+
+})(jQuery);
diff --git a/klaviyo.module b/klaviyo.module
index 9fe581c..fd69772 100644
--- a/klaviyo.module
+++ b/klaviyo.module
@@ -520,3 +520,61 @@ function klaviyo_get_installation_instructions() {
     '!drupal_project_page' => 'https://www.drupal.org/project/klaviyo#klaviyo-installation',
   ));
 }
+
+/**
+ * Implementation of hook_page_alter().
+ */
+function klaviyo_page_alter(&$page) {
+  global $user;
+
+  $settings = variable_get('klaviyo_javascript', array());
+  if (!empty($settings['public_api_key']) && _klaviyo_js_should_add_js($user)) {
+    $page['content']['#attached']['js'][] = array(
+      'data' => drupal_get_path('module', 'klaviyo') . '/klaviyo.js',
+      'type'=>'file',
+      'weight' => 0,
+      'scope' => 'footer',
+    );
+
+    $identify = array();
+    if (!empty($user->mail)) {
+      $identify = array(
+        'identify' => array(
+          '$email' => $user->mail,
+          'drupal.site_id' => klaviyo_api_get_instance()->getSiteId(),
+        ),
+      );
+    }
+
+    $page['content']['#attached']['js'][] = array(
+      'data' => array(
+        'klaviyo' => array(
+          'public_api_key' => $settings['public_api_key']
+        ) + $identify,
+      ),
+      'type' => 'setting',
+    );
+  }
+}
+
+/**
+ * Determine if the JS tracking snippet should be added to a page.
+ *
+ * @param object $account
+ *   (optional) The user account to check, if not given use currently logged in user.
+ * @return boolean
+ *   Returns TRUE if the JS tracking snippt should be added to a page and FALSE
+ *   otherwise.
+ */
+function _klaviyo_js_should_add_js($account = NULL) {
+  if (is_null($account)) {
+    global $user;
+    $account = $user;
+  }
+
+  $js_settings = variable_get('klaviyo_javascript', array());
+  $roles = !empty($js_settings['roles']) ? $js_settings['roles'] : array();
+  $role_intersection = array_intersect_key($account->roles, array_flip($js_settings['roles']));
+
+  return empty($role_intersection);
+}
