diff --git a/adobeanalytics.module b/adobeanalytics.module
index 00d2b63..8dac92a 100644
--- a/adobeanalytics.module
+++ b/adobeanalytics.module
@@ -5,14 +5,6 @@
  * Adds the Javascript to the bottom of Drupal page.
  */
 
-/**
- * To allow tracking by the AdobeAnalytics package.
- */
-
-define('ADOBEANALYTICS_TOKEN_CACHE', 'adobeanalytics:tag_token_results');
-
-use \Drupal\adobeanalytics\AdobeAnalyticsHelper;
-use \Drupal\Core\Render\Markup;
 use \Drupal\Core\Routing\RouteMatchInterface;
 
 /**
@@ -22,21 +14,22 @@ function adobeanalytics_help($route_name, RouteMatchInterface $route_match) {
 
   switch ($route_name) {
     case 'help.page.adobeanalytics':
-      return t("Settings for AdobeAnalytics.");
+      return ['#markup' => "<p>" . t("Settings for AdobeAnalytics.") . "</p>"];
   }
 }
 
 /**
  * Implements template_preprocess_html().
  */
-function adobeanalytics_preprocess_html(&$variables) {
+function adobeanalytics_page_bottom(&$variables) {
 
   $user = \Drupal::currentUser();
   $config = \Drupal::config('adobeanalytics.settings');
-  $adobeanalytics_helper = new AdobeAnalyticsHelper();
+  $adobeanalytics_helper = \Drupal::service('adobeanalytics.adobe_analytics_helper');
 
   // Check if we should track the currently active user's role.
   $track_user = TRUE;
+  $get_roles = array();
   $tracking_type = $config->get('adobeanalytics_role_tracking_type');
   $stored_roles = $config->get('adobeanalytics_track_roles');
   if ($stored_roles) {
@@ -73,7 +66,7 @@ function adobeanalytics_preprocess_html(&$variables) {
   $adobeanalytics_js_file_location = $config->get(
         "adobeanalytics_js_file_location"
     );
-  $js_file_location = ['#plain_text' => $adobeanalytics_js_file_location];
+  $js_file_location = $adobeanalytics_js_file_location;
 
   // Add any custom code snippets if specified and replace any tokens.
   $context = $adobeanalytics_helper->adobeAnalyticsGetTokenContext();
@@ -91,7 +84,7 @@ function adobeanalytics_preprocess_html(&$variables) {
   $adobeanalytics_version = $config->get("adobeanalytics_version");
 
   $header = "<!-- AdobeAnalytics code version: ";
-  $header .= ['#plain_text' => $adobeanalytics_version];
+  $header .= $adobeanalytics_version;
   $header .= "\nCopyright 1996-" . date('Y') . " Adobe, Inc. -->\n";
   $header .= "<script type=\"text/javascript\" src=\"";
   $header .= $js_file_location;
@@ -100,11 +93,9 @@ function adobeanalytics_preprocess_html(&$variables) {
 
   $footer = '/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
     ' . "\n";
-  $footer .= 'var s_code=s.t();if(s_code)document.write(s_code)//--></script>' . "\
-    n";
+  $footer .= 'var s_code=s.t();if(s_code)document.write(s_code)//--></script>' . "\n";
   $footer .= '<script type="text/javascript"><!--' . "\n";
-  $footer .= "if(navigator.appVersion.indexOf('MSIE')>=0)document.write(unescape('%
-    3C')+'\!-'+'-')" . "\n";
+  $footer .= "if(navigator.appVersion.indexOf('MSIE')>=0)document.write(unescape('%3C')+'\!-'+'-')" . "\n";
   $footer .= '//--></script>' . "\n";
   $nojs = $config->get("adobeanalytics_image_file_location");
   if (!empty($nojs)) {
@@ -114,7 +105,7 @@ function adobeanalytics_preprocess_html(&$variables) {
   }
   $footer .= '<!--/DO NOT REMOVE/-->' . "\n";
   $footer .= '<!-- End AdobeAnalytics code version: ';
-  $footer .= ['#plain_text' => $adobeanalytics_version];
+  $footer .= $adobeanalytics_version;
   $footer .= ' -->' . "\n";
 
   if ($adobeanalytics_hooked_vars = \Drupal::moduleHandler()->invokeAll(
@@ -134,19 +125,18 @@ function adobeanalytics_preprocess_html(&$variables) {
     }
   }
 
-  $markup = new Markup();
-  $variables['page_bottom']['adobeanalytics'] = array(
+  $variables['adobeanalytics'] = array(
     'header' => array(
       '#type' => 'markup',
-      '#markup' => $markup->create($header),
+      '#markup' => $header,
     ),
     'variables' => array(
       '#type' => 'markup',
-      '#markup' => $markup->create($extra_variables_formatted),
+      '#markup' => $extra_variables_formatted,
     ),
     'footer' => array(
       '#type' => 'markup',
-      '#markup' => $markup->create($footer),
+      '#markup' => $footer,
     ),
   );
 }
@@ -158,14 +148,15 @@ function adobeanalytics_adobeanalytics_variables() {
 
   $variables = array();
   $config = Drupal::config('adobeanalytics.settings');
-  $adobeanalytics_helper = new AdobeAnalyticsHelper();
+  $adobeanalytics_helper = \Drupal::service('adobeanalytics.adobe_analytics_helper');
 
   // Include variables set using the context module.
-  if (\Drupal::moduleHandler()->moduleExists('context')) {
-    if ($plugin = context_get_plugin('reaction', 'adobeanalytics_vars')) {
-      $plugin->execute($variables);
-    }
-  }
+  /*
+   * @TODO support context module.
+   *
+   * Removing block of code for now until that module is in a stable place to
+   * implement the correct way.  The implementation removed was out of date.
+   */
 
   // Include variables from the "custom variables" section of the settings form.
   $settings_variables = $config->get('adobeanalytics_extra_variables');
diff --git a/adobeanalytics.services.yml b/adobeanalytics.services.yml
new file mode 100644
index 0000000..5eec807
--- /dev/null
+++ b/adobeanalytics.services.yml
@@ -0,0 +1,4 @@
+services:
+  adobeanalytics.adobe_analytics_helper:
+    class: Drupal\adobeanalytics\AdobeAnalyticsHelper
+    arguments: ['@current_route_match', '@module_handler', '@token']
diff --git a/config/schema/adobeanalytics.schema.yml b/config/schema/adobeanalytics.schema.yml
new file mode 100644
index 0000000..853d5e3
--- /dev/null
+++ b/config/schema/adobeanalytics.schema.yml
@@ -0,0 +1,25 @@
+adoboanalystics.settings:
+  type: config_object
+  label: 'Adobe Analytics settings'
+  mapping:
+    adobeanalytics_role_tracking_type:
+      type: string
+      label: 'Role Tracking Type'
+    adobeanalytics_js_file_location:
+      type: string
+      label: 'Javascript file location'
+    adobeanalytics_codesnippet:
+      type: string
+      label: 'Codesnippet'
+    adobeanalytics_version:
+      type: string
+      label: 'Version'
+    adobeanalytics_image_file_location:
+      type: string
+      label: 'Image file location'
+    adobeanalytics_token_cache_lifetime:
+    adobeanalytics_extra_variables: { }
+    adobeanalytics_track_roles: { }
+    admin_only:
+      type: boolean
+      label: 'Only apply to admin pages'
diff --git a/src/AdobeAnalyticsHelper.php b/src/AdobeAnalyticsHelper.php
index 162730c..2d46b62 100644
--- a/src/AdobeAnalyticsHelper.php
+++ b/src/AdobeAnalyticsHelper.php
@@ -2,25 +2,71 @@
 
 namespace Drupal\adobeanalytics;
 
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\Routing\CurrentRouteMatch;
+use Drupal\Core\Utility\Token;
+use Drupal\system\Entity\Menu;
+
 /**
  * Class to provide helpful function.
  */
 class AdobeAnalyticsHelper {
+  /**
+   * The CurrentRouteMatch service.
+   *
+   * @var \Drupal\Core\Routing\CurrentRouteMatch
+   */
+  protected $currentRouteMatch;
+
+  /**
+   * The ModuleHandler service.
+   *
+   * @var \Drupal\Core\Extension\ModuleHandlerInterface
+   */
+  protected $moduleHandler;
+
+  /**
+   * The Token replacement object.
+   *
+   * @var \Drupal\Core\Utility\Token
+   */
+  protected $token;
+
+  /**
+   * Array of variables.
+   *
+   * @var array
+   */
+  protected $variables;
+
+  /**
+   * Context array.
+   *
+   * @var array
+   */
+  protected $context;
+
+  /**
+   * Constructs an AdobeAnalyticsHelper object.
+   */
+  public function __construct(CurrentRouteMatch $currentRouteMatch, ModuleHandlerInterface $moduleHandler, Token $token) {
+    $this->currentRouteMatch = $currentRouteMatch;
+    $this->moduleHandler = $moduleHandler;
+    $this->token = $token;
+  }
 
   /**
    * Get the context.
    */
   public function adobeAnalyticsGetTokenContext() {
 
-    $context = &drupal_static(__function__);
-    if (is_null($context)) {
-      $context['node'] = \Drupal::routeMatch()->getParameter('node');
-      $context['term'] = \Drupal::routeMatch()->getParameter('taxonomy_term', 2);
-      if (\Drupal::moduleHandler()->moduleExists('menu')) {
-        $context['menu'] = menu_ui_load('main-menu');
-      }
+    if (is_null($this->context)) {
+      $this->context['node'] = $this->currentRouteMatch->getParameter('node');
+      $this->context['term'] = ($this->currentRouteMatch->getParameter('taxonomy_term')) ? $this->currentRouteMatch->getParameter('taxonomy_term') : 2;
+      $this->context['menu'] = Menu::load('main-menu');
     }
-    return $context;
+    
+    return $this->context;
   }
 
   /**
@@ -28,9 +74,8 @@ class AdobeAnalyticsHelper {
    */
   public function adobeAnalyticsTokenReplace($text, $data = array(), array $options = array()) {
 
-    $processed_strings =& drupal_static(__FUNCTION__, NULL);
     // Short-circuit the degenerate case, just like token_replace() does.
-    $text_tokens = \Drupal::token()->replace($text);
+    $text_tokens = $this->token->replace($text);
     if (!empty($text_tokens)) {
       return $text_tokens;
     }
@@ -41,7 +86,7 @@ class AdobeAnalyticsHelper {
    */
   public function adobeAnalyticsFormatVariables($variables = array()) {
 
-    $extra_variables = $this->adobeAnalyticsGetVariables();
+    $extra_variables = $this->getVariables();
 
     // Create context data to be used by token.
     $variables_formatted = '';
@@ -72,29 +117,21 @@ class AdobeAnalyticsHelper {
    *    Extra variable name.
    * @param string $value
    *    Value of the the name variable.
-   *
-   * @return variables
-   *    Return the variables.
    */
-  public function adobeAnalyticsSetVariable($name = NULL, $value = NULL) {
-
-    $variables = &drupal_static(__FUNCTION__, array());
-
-    if (empty($name)) {
-      return $variables;
+  public function setVariable($name = NULL, $value = NULL) {
+    if (!empty($name)) {
+      $this->variables[$name] = $value;
     }
-    else {
-      $variables[$name] = $value;
-    }
-
   }
 
   /**
    * Return variables.
+   *
+   * @return array
+   *   The array of variables.
    */
-  public function adobeAnalyticsGetVariables() {
-
-    return $this->adobeAnalyticsSetVariable();
+  public function getVariables() {
+    return $this->variables;
   }
 
 }
diff --git a/src/Form/AdobeanalyticsAdminSettings.php b/src/Form/AdobeanalyticsAdminSettings.php
index 633b072..200b1b1 100644
--- a/src/Form/AdobeanalyticsAdminSettings.php
+++ b/src/Form/AdobeanalyticsAdminSettings.php
@@ -21,7 +21,7 @@ class AdobeanalyticsAdminSettings extends ConfigFormBase {
   /**
    * Get Editable configuratons.
    *
-   * @return 'adobeanalytics.settings'
+   * @return array
    *   Gets the configuration names that will be editable
    */
   protected function getEditableConfigNames() {
@@ -37,96 +37,86 @@ class AdobeanalyticsAdminSettings extends ConfigFormBase {
     $config = $this->config('adobeanalytics.settings');
 
     $form['general'] = [
-        // Fieldset changed to details in drupal 8.
       '#type' => 'details',
-      '#title' => t('General settings'),
+      '#title' => $this->t('General settings'),
       '#open' => TRUE,
       '#weight' => '-10',
     ];
 
     $form['general']['adobeanalytics_js_file_location'] = [
       '#type' => 'textfield',
-      '#title' => t("Complete path to AdobeAnalytics Javascript file"),
-      '#default_value' => $config->get("adobeanalytics_js_file_location"),
+      '#title' => $this->t('Complete path to AdobeAnalytics Javascript file'),
+      '#default_value' => $config->get('adobeanalytics_js_file_location'),
     ];
 
     $form['general']['adobeanalytics_image_file_location'] = [
       '#type' => 'textfield',
-      '#title' => t("Complete path to AdobeAnalytics Image file"),
-      '#default_value' => $config->get("adobeanalytics_image_file_location"),
+      '#title' => $this->t('Complete path to AdobeAnalytics Image file'),
+      '#default_value' => $config->get('adobeanalytics_image_file_location'),
     ];
 
     $form['general']['adobeanalytics_version'] = [
       '#type' => 'textfield',
-      '#title' => t(
-          "AdobeAnalytics version (used by adobeanalytics for debugging)"
-      ),
-      '#default_value' => $config->get("adobeanalytics_version"),
+      '#title' => $this->t('AdobeAnalytics version (used by adobeanalytics for debugging)'),
+      '#default_value' => $config->get('adobeanalytics_version'),
     ];
 
     $form['general']['adobeanalytics_token_cache_lifetime'] = [
       '#type' => 'textfield',
-      '#title' => t("Token cache lifetime"),
-      '#default_value' => $config->get("adobeanalytics_token_cache_lifetime"),
-      '#description' => t(
-          'The time, in seconds, that the AdobeAnalytics token 
-          cache will be valid for. The token cache will always be cleared at the 
-          next system cron run after this time period, or when this form is saved.'
+      '#title' => $this->t('Token cache lifetime'),
+      '#default_value' => $config->get('adobeanalytics_token_cache_lifetime'),
+      '#description' => $this->t(
+        'The time, in seconds, that the AdobeAnalytics token
+         cache will be valid for. The token cache will always be cleared at the
+         next system cron run after this time period, or when this form is saved.'
       ),
     ];
 
     $form['roles'] = [
       '#type' => 'details',
-      '#title' => t('User role tracking'),
+      '#title' => $this->t('User role tracking'),
       '#open' => TRUE,
-      '#description' => t(
-          'Define which user roles should, or should not be tracked
-         by AdobeAnalytics.'
-      ),
+      '#description' => $this->t('Define which user roles should, or should not be tracked by AdobeAnalytics.'),
       '#weight' => '-6',
     ];
 
+    $default_value = ($config->get("adobeanalytics_role_tracking_type")) ? $config->get("adobeanalytics_role_tracking_type") : 'inclusive';
     $form['roles']['adobeanalytics_role_tracking_type'] = [
       '#type' => 'select',
-      '#title' => t('Add tracking for specific roles'),
+      '#title' => $this->t('Add tracking for specific roles'),
       '#options' => [
-        'inclusive' => t('Add to the selected roles only'),
-        'exclusive' => t('Add to all roles except the ones selected'),
+        'inclusive' => $this->t('Add to the selected roles only'),
+        'exclusive' => $this->t('Add to all roles except the ones selected'),
       ],
-      '#default_value' => $config->get(
-          "adobeanalytics_role_tracking_type", 'inclus
-          ive'
-      ),
+      '#default_value' => $default_value,
     ];
 
     $roles = array();
     foreach (user_roles() as $role) {
       $roles[$role->id()] = $role->label();
     }
-    $adobeanalytics_config_track_roles = $config->get(
-          "adobeanalytics_track_roles"
-      );
+    $adobeanalytics_config_track_roles = $config->get('adobeanalytics_track_roles');
 
     $form['roles']["adobeanalytics_track_roles"] = [
       '#type' => 'checkboxes',
       '#options' => $roles,
       '#default_value' => empty($adobeanalytics_config_track_roles) ?
-      array_keys($roles) : $config->get("adobeanalytics_track_roles"),
+      array_keys($roles) : $config->get('adobeanalytics_track_roles'),
     ];
 
     $form['variables'] = [
       '#type' => 'details',
-      '#title' => t('Custom Variables'),
+      '#title' => $this->t('Custom Variables'),
       '#open' => FALSE,
-      '#description' => t('You can define tracking variables here.'),
+      '#description' => $this->t('You can define tracking variables here.'),
       '#weight' => '-3',
     ];
     $this->adobeAnalyticsExtraVariablesForm($form);
 
     $form['advanced'] = [
       '#type' => 'details',
-      '#title' => t('Advanced'),
-      '#description' => t('You can add custom AdobeAnalytics code here.'),
+      '#title' => $this->t('Advanced'),
+      '#description' => $this->t('You can add custom AdobeAnalytics code here.'),
       '#open' => FALSE,
       '#weight' => '-2',
     ];
@@ -137,7 +127,7 @@ class AdobeanalyticsAdminSettings extends ConfigFormBase {
         age";} else {s.prop9 = "[current-page:title]";}';
     $form['advanced']['adobeanalytics_codesnippet'] = [
       '#type' => 'textarea',
-      '#title' => t('JavaScript Code'),
+      '#title' => $this->t('JavaScript Code'),
       '#default_value' => $config->get('adobeanalytics_codesnippet'),
       '#rows' => 15,
       '#description' => $description,
@@ -160,7 +150,7 @@ class AdobeanalyticsAdminSettings extends ConfigFormBase {
 
     $config = $this->config('adobeanalytics.settings');
     $existing_variables = $config->get('adobeanalytics_extra_variables');
-    $headers = array(t('Name'), t('Value'));
+    $headers = array(t('Name'), $this->t('Value'));
     $form['variables']['adobeanalytics_variables'] = [
       '#type' => 'table',
       '#header' => $headers,
@@ -214,7 +204,7 @@ class AdobeanalyticsAdminSettings extends ConfigFormBase {
       '#size' => 40,
       '#maxlength' => 40,
       '#title_display' => 'invisible',
-      '#title' => t('Name'),
+      '#title' => $this->t('Name'),
       '#default_value' => ($key_name != '' ? $key_name : ''),
       '#attributes' => ['class' => ['field-variable-name']],
     ];
@@ -223,14 +213,14 @@ class AdobeanalyticsAdminSettings extends ConfigFormBase {
       '#size' => 40,
       '#maxlength' => 40,
       '#title_display' => 'invisible',
-      '#title' => t('Value'),
+      '#title' => $this->t('Value'),
       '#default_value' => ($key_value != '' ? $key_value : ''),
       '#attributes' => ['class' => ['field-variable-value']],
     ];
 
     if (empty($key_name) && empty($key_value)) {
-      $form['variables']['adobeanalytics_variables'][$index]['name']['#description'] = t('Example: prop1');
-      $form['variables']['adobeanalytics_variables'][$index]['value']['#description'] = t('Example: [current-page:title]');
+      $form['variables']['adobeanalytics_variables'][$index]['name']['#description'] = $this->t('Example: prop1');
+      $form['variables']['adobeanalytics_variables'][$index]['value']['#description'] = $this->t('Example: [current-page:title]');
     }
     return $form;
   }
