diff --git a/comscore_direct.admin.inc b/comscore_direct.admin.inc
deleted file mode 100644
index 883d865..0000000
--- a/comscore_direct.admin.inc
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-/**
- * @file
- * Common settings for comScore Direct tag. hansdotcom@gmail.com.
- * comscore_direct_form.
- *
- */
-function comscore_direct_form() {
-  global $base_url;
-  $form = array();
-  $form['comscore_direct_id'] = array(
-      '#title' => t('comScore site id'),
-      '#type' => 'textfield',
-      '#description' => t('comScore ID (required)'),
-      '#default_value' => variable_get('comscore_direct_id', ''),
-      '#required' => TRUE,
-  );
-  $form['comscore_direct_genre'] = array(
-      '#title' => t('comScore Genre of content'),
-      '#type' => 'textfield',
-      '#description' => t('Alphanumeric value used for client specific custom classification (optional)'),
-      '#default_value' => variable_get('comscore_direct_genre', '')
-  );
-  $form['comscore_direct_package'] = array(
-      '#title' => t('comScore Package'),
-      '#type' => 'textfield',
-      '#description' => t('Alphanumeric value for customized aggregation to reflect sections or site centric advertising packages (optional)'),
-      '#default_value' => variable_get('comscore_direct_package', '')
-  );
-  $form['comscore_direct_clientseg'] = array(
-      '#title' => t('comScore Client Segment ID'),
-      '#type' => 'textfield',
-      '#description' => t('Alphanumeric value for Publisher’s own segment for the machine the content asset is being served to (optional)'),
-      '#default_value' => variable_get('comscore_direct_clientseg', '')
-  );
-  $form['comscore_direct_baseurl'] = array(
-    '#title' => t('Base URL'),
-    '#type' => 'textfield',
-    '#description' => t('This is your site URL and will be used for the c4 parameter.  If empty, the default will be: %base_url', array('%base_url' => $base_url)),
-    '#default_value' => variable_get('comscore_direct_baseurl', ''),
-  );
-  return system_settings_form($form);
-}
-
-/*
- * Form validation
- *
- */
-function comscore_direct_form_validate($form, &$form_state) {
-  $comscore_customer_id = $form_state['values']['comscore_direct_id'];
-  if (!is_numeric($comscore_customer_id)) {
-    form_set_error('mls_comscore_id', t('You must enter an integer for comScore customer code.'));
-  }
-  elseif ($comscore_customer_id <= 0) {
-    form_set_error('mls_comscore_id', t('comScore customer code must be positive.'));
-  }
-}
diff --git a/comscore_direct.info b/comscore_direct.info
deleted file mode 100644
index 069277a..0000000
--- a/comscore_direct.info
+++ /dev/null
@@ -1,4 +0,0 @@
-name = comScore Direct 
-description = Adds an admin interface for comScore settings and generates comScore tags to the footer of your site.
-package = "comScore"
-core = 7.x
diff --git a/comscore_direct.info.yml b/comscore_direct.info.yml
new file mode 100644
index 0000000..cf19e8a
--- /dev/null
+++ b/comscore_direct.info.yml
@@ -0,0 +1,3 @@
+name: comscore
+type: module
+core: 8.x
diff --git a/comscore_direct.install b/comscore_direct.install
deleted file mode 100644
index a4fcf04..0000000
--- a/comscore_direct.install
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-/* @file
- *
- */
- 
-/*
- * Implementation of hook_uninstall().
- *
- * Remove all the comscore_direct settings from the variables table if uninstalled.
- *
- */
-function comscore_direct_uninstall() {
-  $query = db_delete('variable')
-    ->condition('name', 'comscore\_direct\_%', 'LIKE')
-    ->execute();
-}
diff --git a/comscore_direct.links.menu.yml b/comscore_direct.links.menu.yml
new file mode 100644
index 0000000..adb35f2
--- /dev/null
+++ b/comscore_direct.links.menu.yml
@@ -0,0 +1,4 @@
+comscore_direct.settings:
+  title: 'Comscore direct settings'
+  parent: system.admin_config_services
+  route_name: comscore_direct.settings
diff --git a/comscore_direct.module b/comscore_direct.module
index 8deb8b6..2e9dbb5 100644
--- a/comscore_direct.module
+++ b/comscore_direct.module
@@ -1,73 +1,41 @@
 <?php
-/**
- * @file
- * Common settings for all comScore settings. Contact: hansdotcom@gmail.com.
- */
 
 /**
- * Implementation of hook_permission().
+ * @file
+ * Comscore module.
  */
-function comscore_direct_permission() {
-  return array(
-    'administer comscore direct' => array(
-      'title' => t('Administer comScore direct')
-    )
-  );
-}
 
-/**
- * Implementation of hook_menu().
- */
-function comscore_direct_menu() {
-  $items = array();
-  $items['admin/config/system/comscore_direct'] = array(
-    'type' => MENU_NORMAL_ITEM,
-    'title' => 'comScore',
-    'description' => 'Settings for comScore tag',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('comscore_direct_form'),
-    'file' => 'comscore_direct.admin.inc',
-    'access callback' => 'user_access',
-    'access arguments' => array('administer comscore direct'),
-  );
-  return $items;
-}
+use Drupal\comscore_direct\ComscoreEvent;
+use Drupal\comscore_direct\ComscoreEvents;
+use Drupal\comscore_direct\ComscoreInformation;
+use Drupal\comscore_direct\InlineScript;
+use Drupal\Core\Url;
 
 /**
- * Implementation of hook_page_alter().
+ * Implements hook_page_attachments().
  */
-function comscore_direct_page_alter(&$page) {
-
-  // Exclude tag from admin pages.
-  if (path_is_admin(current_path())) {
+function comscore_direct_page_attachments(array &$attachments) {
+  $route_match = \Drupal::routeMatch();
+  if ($route_match->getRouteObject()->getOption('_admin_route')) {
     return;
   }
 
-  global $base_url;
-  $com_base_url = variable_get('comscore_direct_baseurl', '');
-  $path = (!empty($com_base_url) ? $com_base_url : $base_url) . request_uri();
-  $com_id = check_plain(variable_get('comscore_direct_id', ''));
-  $com_genre = check_plain(variable_get('comscore_direct_genre', ''));
-  $comid_package = check_plain(variable_get('comscore_direct_package', ''));
-  $comid_client = check_plain(variable_get('comscore_direct_clientseg', ''));
+  $current_url = Url::fromRoute('<current>')->toString(TRUE)->getGeneratedUrl();
+  $comscore_information = ComscoreInformation::fromConfig(\Drupal::config('comscore_direct.settings'), $current_url);
+
+  /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher */
+  $event_dispatcher = \Drupal::service('event_dispatcher');
+  $event_dispatcher->dispatch(ComscoreEvents::RENDER, new ComscoreEvent($comscore_information));
 
-    if (!empty($com_id)) {
-      $page['page_bottom']['comscore direct'] = array(
-        '#type' => 'markup',
-        '#markup' => '<!-- Begin comScore Tag -->
-          <script>
-            var _comscore = _comscore || [];
-            _comscore.push({ c1: "2", c2: "' . $com_id . '", c3: "", c4: "' . $path . '", c5: "' . $com_genre . '", c6: "' . $comid_package . '", c15: "' . $comid_client . '" });
-            (function() {
-              var s = document.createElement("script"), el = document.getElementsByTagName("script")[0]; s.async = true;
-              s.src = (document.location.protocol == "https:" ? "https://sb" : "http://b") + ".scorecardresearch.com/beacon.js";
-              el.parentNode.insertBefore(s, el);
-            })();
-          </script>
-          <noscript>
-            <img src="http://b.scorecardresearch.com/p?c1=2&c2=' . $com_id . '&c3=&c4=' . $path . '&c5=' . $com_genre . '&c6=' . $comid_package . '&c15=' . $comid_client . '&cv=2.0&cj=1" />
-          </noscript>
-      <!-- End comScore Tag -->'
-        );
-    }
+  $inline_script = (new InlineScript());
+  $script = $inline_script->getScriptRenderable($comscore_information);
+  $noscript = $inline_script->getNoScriptRenderable($comscore_information);
+  $attachments['#attached']['html_head'][] = [
+    $script,
+    'comscore_tracking_script',
+  ];
+  $attachments['#attached']['html_head'][] = [
+    $noscript,
+    'comscore_tracking_noscript',
+  ];
 }
diff --git a/comscore_direct.permissions.yml b/comscore_direct.permissions.yml
new file mode 100644
index 0000000..db6ad2d
--- /dev/null
+++ b/comscore_direct.permissions.yml
@@ -0,0 +1,2 @@
+administer comscore direct:
+  title: Administer comScore direct
diff --git a/comscore_direct.routing.yml b/comscore_direct.routing.yml
new file mode 100644
index 0000000..f5f5fcf
--- /dev/null
+++ b/comscore_direct.routing.yml
@@ -0,0 +1,6 @@
+comscore_direct.settings:
+  path: '/admin/config/services/comscore_direct'
+  defaults:
+    _form: \Drupal\comscore_direct\Form\ComscoreSettingsForm
+  requirements:
+    _permission: 'administer comscore direct'
diff --git a/config/install/comscore_direct.settings.yml b/config/install/comscore_direct.settings.yml
new file mode 100644
index 0000000..538fde0
--- /dev/null
+++ b/config/install/comscore_direct.settings.yml
@@ -0,0 +1,4 @@
+site_id: ''
+genre: ''
+package: ''
+clientseg: ''
diff --git a/config/schema/comscore_direct.schema.yml b/config/schema/comscore_direct.schema.yml
new file mode 100644
index 0000000..8846c4c
--- /dev/null
+++ b/config/schema/comscore_direct.schema.yml
@@ -0,0 +1,12 @@
+comscore_direct.settings:
+  type: config_object
+  label: 'Node settings'
+  mapping:
+    site_id:
+      type: numeric
+    genre:
+      type: string
+    package:
+      type: string
+    clientseg:
+      type: string
diff --git a/src/ComscoreEvent.php b/src/ComscoreEvent.php
new file mode 100644
index 0000000..d2e4de2
--- /dev/null
+++ b/src/ComscoreEvent.php
@@ -0,0 +1,48 @@
+<?php
+
+namespace Drupal\comscore_direct;
+
+use Symfony\Component\EventDispatcher\Event;
+
+class ComscoreEvent extends Event {
+
+  /**
+   * The comscore information.
+   *
+   * @var \Drupal\comscore_direct\ComscoreInformation
+   */
+  protected $comscoreInformation;
+
+  /**
+   * Creates a new ComscoreEvent instance.
+   *
+   * @param \Drupal\comscore_direct\ComscoreInformation $comscoreInformation
+   *   The comscore information.
+   */
+  public function __construct(ComscoreInformation $comscoreInformation) {
+    $this->comscoreInformation = $comscoreInformation;
+  }
+
+  /**
+   * Gets the comscore information.
+   *
+   * @return \Drupal\comscore_direct\ComscoreInformation
+   */
+  public function getComscoreInformation() {
+    return $this->comscoreInformation;
+  }
+
+  /**
+   * Sets the comscore information.
+   *
+   * @param \Drupal\comscore_direct\ComscoreInformation $comscore_information
+   *   The comscore information.
+   *
+   * @return $this;
+   */
+  public function setComscoreInformation(ComscoreInformation $comscore_information) {
+    $this->comscoreInformation = $comscore_information;
+    return $this;
+  }
+
+}
diff --git a/src/ComscoreEvents.php b/src/ComscoreEvents.php
new file mode 100644
index 0000000..19a4246
--- /dev/null
+++ b/src/ComscoreEvents.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace Drupal\comscore_direct;
+
+class ComscoreEvents {
+
+  CONST RENDER = 'comscore_direct.render';
+
+}
diff --git a/src/ComscoreInformation.php b/src/ComscoreInformation.php
new file mode 100644
index 0000000..59001ad
--- /dev/null
+++ b/src/ComscoreInformation.php
@@ -0,0 +1,133 @@
+<?php
+
+namespace Drupal\comscore_direct;
+
+use Drupal\Core\Config\Config;
+
+class ComscoreInformation {
+
+  protected $siteId;
+
+  protected $genre;
+
+  protected $package;
+
+  protected $segment;
+
+  protected $currentUrl;
+
+  /**
+   * Creates a new ComscoreInformation instance.
+   *
+   * @param $siteId
+   * @param $genre
+   * @param $package
+   * @param $segment
+   * @param $currentUrl
+   */
+
+  public function __construct($siteId, $genre, $package, $segment, $currentUrl) {
+    $this->siteId = $siteId;
+    $this->genre = $genre;
+    $this->package = $package;
+    $this->segment = $segment;
+    $this->currentUrl = $currentUrl;
+  }
+
+  /**
+   * @return mixed
+   */
+  public function getSiteId() {
+    return $this->siteId;
+  }
+
+  /**
+   * @return mixed
+   */
+  public function getGenre() {
+    return $this->genre;
+  }
+
+  /**
+   * @param mixed $genre
+   *
+   * @return $this
+   */
+  public function setGenre($genre) {
+    $this->genre = $genre;
+    return $this;
+  }
+
+  /**
+   * @return mixed
+   */
+  public function getPackage() {
+    return $this->package;
+  }
+
+  /**
+   * @param mixed $package
+   *
+   * @return $this
+   */
+  public function setPackage($package) {
+    $this->package = $package;
+    return $this;
+  }
+
+  /**
+   * @return mixed
+   */
+  public function getSegment() {
+    return $this->segment;
+  }
+
+  /**
+   * @param mixed $segment
+   *
+   * @return $this
+   */
+  public function setSegment($segment) {
+    $this->segment = $segment;
+    return $this;
+  }
+
+  /**
+   * @return mixed
+   */
+  public function getCurrentUrl() {
+    return $this->currentUrl;
+  }
+
+  /**
+   * @param mixed $currentUrl
+   *
+   * @return $this
+   */
+  public function setCurrentUrl($currentUrl) {
+    $this->currentUrl = $currentUrl;
+    return $this;
+  }
+
+  /**
+   * Creates a new comscore information object from configuration.
+   *
+   * @param \Drupal\Core\Config\Config $config
+   *   The comscore_direct configuration.
+   *
+   * @param string $current_url
+   *   The current URL.
+   *
+   * @return static
+   */
+  public static function fromConfig(Config $config, $current_url) {
+    return new static(
+      $config->get('site_id'),
+      $config->get('genre'),
+      $config->get('package'),
+      $config->get('segment'),
+      $current_url
+    );
+  }
+
+}
diff --git a/src/Form/ComscoreSettingsForm.php b/src/Form/ComscoreSettingsForm.php
new file mode 100644
index 0000000..46763c3
--- /dev/null
+++ b/src/Form/ComscoreSettingsForm.php
@@ -0,0 +1,95 @@
+<?php
+
+namespace Drupal\comscore_direct\Form;
+
+use Drupal\Core\Form\ConfigFormBase;
+use Drupal\Core\Form\FormStateInterface;
+
+/**
+ * Defines a configuration form for comscore settings.
+ */
+class ComscoreSettingsForm extends ConfigFormBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function getEditableConfigNames() {
+    return ['comscore_direct.settings'];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getFormId() {
+    return 'comscore_direct_settings';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildForm(array $form, FormStateInterface $form_state) {
+    $form = parent::buildForm($form, $form_state);
+
+    $config = $this->config('comscore_direct.settings');
+
+    $form['site_id'] = [
+      '#title' => $this->t('comScore site id'),
+      '#type' => 'textfield',
+      '#description' => $this->t('comScore ID (required)'),
+      '#default_value' => $config->get('site_id'),
+      '#required' => TRUE,
+    ];
+
+    $form['genre'] = [
+      '#title' => $this->t('comScore Genre of content'),
+      '#type' => 'textfield',
+      '#description' => $this->t('Alphanumeric value used for client specific custom classification (optional)'),
+      '#default_value' => $config->get('genre'),
+    ];
+
+    $form['package'] = [
+      '#title' => $this->t('comScore Package'),
+      '#type' => 'textfield',
+      '#description' => $this->t('Alphanumeric value for customized aggregation to reflect sections or site centric advertising packages (optional)'),
+      '#default_value' => $config->get('package'),
+    ];
+
+    $form['clientseg'] = [
+      '#title' => $this->t('comScore Client Segment ID'),
+      '#type' => 'textfield',
+      '#description' => $this->t('Alphanumeric value for Publisher’s own segment for the machine the content asset is being served to (optional)'),
+      '#default_value' => $config->get('clientseg'),
+    ];
+
+    return $form;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function validateForm(array &$form, FormStateInterface $form_state) {
+    parent::validateForm($form, $form_state);
+
+    if (!is_numeric($form_state->getValue('site_id'))) {
+      $form_state->setErrorByName('site_id', $this->t('You must enter an integer for comScore customer code.'));
+    }
+    if ($form_state->getValue('site_id') < 0) {
+      $form_state->setErrorByName('site_id', $this->t('comScore customer code must be positive.'));
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function submitForm(array &$form, FormStateInterface $form_state) {
+    parent::submitForm($form, $form_state);
+
+    $this->config('comscore_direct.settings')
+      ->set('site_id', $form_state->getValue('site_id'))
+      ->set('genre', $form_state->getValue('genre'))
+      ->set('package', $form_state->getValue('package'))
+      ->set('clientseg', $form_state->getValue('clientseg'))
+      ->save();
+  }
+
+}
diff --git a/src/InlineScript.php b/src/InlineScript.php
new file mode 100644
index 0000000..f8f6121
--- /dev/null
+++ b/src/InlineScript.php
@@ -0,0 +1,76 @@
+<?php
+
+namespace Drupal\comscore_direct;
+
+use Drupal\Core\Render\Markup;
+use Drupal\Core\Url;
+
+class InlineScript {
+
+  protected function getData(ComscoreInformation $comscore_information) {
+    $data = [];
+    $data['c1'] = '2';
+
+    if ($site_id = $comscore_information->getSiteId()) {
+      $data['c2'] = $site_id;
+    }
+
+    if ($current_url = $comscore_information->getCurrentUrl()) {
+      $data['c4'] = $current_url;
+    }
+    if ($genre = $comscore_information->getGenre()) {
+      $data['c5'] = $genre;
+    }
+
+    if ($package = $comscore_information->getPackage()) {
+      $data['c6'] = $package;
+    }
+
+    if ($segment = $comscore_information->getPackage()) {
+      $data['c15'] = $segment;
+    }
+    return $data;
+  }
+
+  public function getScriptRenderable(ComscoreInformation $comscore_information) {
+    $data = $this->getData($comscore_information);
+
+    $json = json_encode($data);
+
+    $script = <<<COMSCORE
+ var _comscore = _comscore || [];
+  _comscore.push($json);
+
+ (function() {
+   var s = document.createElement("script"), el = document.getElementsByTagName("script")[0]; s.async = true;
+   s.src = (document.location.protocol == "https:" ? "https://sb" : "http://b") + ".scorecardresearch.com/beacon.js";
+   el.parentNode.insertBefore(s, el);
+ })();
+COMSCORE;
+    return [
+//      '#type' => 'html_tag',
+      '#tag' => 'script',
+      '#value' => Markup::create($script),
+    ];
+  }
+
+  public function getNoScriptRenderable(ComscoreInformation $comscore_information) {
+    $query = $this->getData($comscore_information);
+    $query['cv'] = 2.0;
+    $query['cj'] = 1;
+
+    $url = Url::fromUri('http://b.scorecardresearch.com/p', [
+      'query' => $query,
+    ]);
+    $url_string = $url->toString(TRUE)->getGeneratedUrl();
+    
+    return [
+      '#tag' => 'img',
+      '#attributes' => [
+        'src' => $url_string,
+      ],
+      '#noscript' => TRUE,
+    ];
+  }
+
+}
