diff --git a/includes/klaviyo.admin.inc b/includes/klaviyo.admin.inc
index 040ad8b..e860806 100644
--- a/includes/klaviyo.admin.inc
+++ b/includes/klaviyo.admin.inc
@@ -48,5 +48,44 @@ function klaviyo_api_integration_settings() {
     );
   }
 
+  // START Javascript settings
+  $settings = variable_get('klaviyo_javascript', '');
+
+  $form['klaviyo_javascript'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Klaviyo javascript settings'),
+    '#collapsible' => TRUE,
+    '#group' => 'klaviyo',
+    '#tree' => TRUE
+  );
+
+  $form['klaviyo_javascript']['key_public'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Public API key'),
+    '#description' => t('The public API key is used in order to send events via the JavaScript integration. 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' => $settings['key_public'],
+    '#size' => 60,
+    '#maxlength' => 128,
+    '#required' => FALSE,
+    '#group' => 'klaviyo',
+  );
+
+  $roles = user_roles();
+  $role_options = array();
+  foreach ($roles as $rid => $name) {
+    $role_options[$rid] = $name;
+  }
+  $form['klaviyo_javascript']['roles'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Remove script for specific roles'),
+    '#default_value' => $settings['roles'] ? $settings['roles'] : array(),
+    '#options' => $role_options,
+    '#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.'),
+  );
+  // END Javascript settings
+
+
   return system_settings_form($form);
 }
diff --git a/klaviyo.module b/klaviyo.module
index 9fe581c..cf8e493 100644
--- a/klaviyo.module
+++ b/klaviyo.module
@@ -520,3 +520,58 @@ function klaviyo_get_installation_instructions() {
     '!drupal_project_page' => 'https://www.drupal.org/project/klaviyo#klaviyo-installation',
   ));
 }
+
+/**
+ * Implementation of hook_page_alter().
+ *
+ * @global object $user
+ *   full user object for current user
+ * @param  $page
+ *   nested array of renderable elements that make up the page.
+ */
+function klaviyo_page_alter(&$page) {
+  global $user;
+  $settings = variable_get('klaviyo_javascript', '');
+  if (!empty($settings['key_public']) && _klaviyo_visibility_roles($user)) {
+    $script = "var _learnq = _learnq || [];" .
+              "_learnq.push(['account', '" . $settings['key_public'] . "']);" .
+              "(function () {" .
+              "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);" .
+              "})();";
+
+    drupal_add_js($script, array(
+      'scope' => 'footer',
+      'type' => 'inline',
+      'weight' => 0
+      )
+    );
+  }
+}
+
+/**
+ * Based on visibility setting this function returns TRUE if Klaviyo code should
+ * be added for the current role and otherwise FALSE.
+ *
+ * @param object $account
+ *   a full user object.
+ * @return boolean
+ *   a decision on visibility, true/false
+ */
+function _klaviyo_visibility_roles($account) {
+  $enabled = TRUE;
+  $roles = variable_get('klaviyo_javascript', array())['roles'];
+  if (array_sum($roles) > 0) {
+    // One or more roles are selected for tracking.
+    foreach (array_keys($account->roles) as $rid) {
+      // Is the current user a member of one role selected in admin settings?
+      if (isset($roles[$rid]) && $rid == $roles[$rid]) {
+        // Current user is a member of a role that is selected in admin settings.
+        $enabled = FALSE;
+        break;
+      }
+    }
+  }
+  return $enabled;
+}
