diff --git a/google_tag_manager.admin.inc b/google_tag_manager.admin.inc
index e1c0e5a..44fbc53 100644
--- a/google_tag_manager.admin.inc
+++ b/google_tag_manager.admin.inc
@@ -8,9 +8,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  * 	http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -46,6 +46,46 @@ function google_tag_manager_admin_settings_form($form_state) {
 		'#type' => 'textfield',
 	);
 
+  // Custom variables.
+  $form['google_tag_manager_custom_vars'] = array(
+    '#collapsed' => TRUE,
+    '#collapsible' => TRUE,
+    '#theme' => 'google_tag_manager_admin_custom_vars_table',
+    '#title' => t('Custom variables'),
+    '#tree' => TRUE,
+    '#type' => 'fieldset',
+  );
+
+  $custom_vars = variable_get('google_tag_manager_custom_vars', array());
+
+  for($i = 0; $i < count($custom_vars) +1; $i++) {
+    $form['google_tag_manager_custom_vars'][$i]['name'] = array(
+      '#default_value' => !empty($custom_vars[$i]['name']) ? $custom_vars[$i]['name'] : '',
+      '#description' => t('The custom variable name.'),
+      '#maxlength' => 255,
+      '#size' => 20,
+      '#title' => t('Custom variable name #@slot', array('@slot' => $i)),
+      '#title_display' => 'invisible',
+      '#type' => 'textfield',
+      '#token_types' => array('node'),
+    );
+    $form['google_tag_manager_custom_vars'][$i]['value'] = array(
+      '#default_value' => !empty($custom_vars[$i]['value']) ? $custom_vars[$i]['value'] : '',
+      '#description' => t('The custom variable value.'),
+      '#maxlength' => 255,
+      '#title' => t('Custom variable value #@slot', array('@slot' => $i)),
+      '#title_display' => 'invisible',
+      '#type' => 'textfield',
+      '#token_types' => array('node'),
+    );
+  }
+
+  $form['google_tag_manager_custom_vars']['token_tree'] = array(
+    '#theme' => 'token_tree',
+    '#token_types' => array('node'),
+    '#dialog' => TRUE,
+  );
+
 	return system_settings_form($form);
 }
 
@@ -61,6 +102,43 @@ function google_tag_manager_admin_settings_form_validate($form, &$form_state) {
 	if (!preg_match('/^GTM-\w+$/', $form_state['values']['google_tag_manager_account'])) {
 		form_set_error('google_tag_manager_account', t('A valid Google Tag Manager container ID is case sensitive and is formatted like GTM-XXXX'));
 	}
+
+  foreach ($form_state['values']['google_tag_manager_custom_vars'] as $i => $custom_var) {
+    $custom_var['name'] = trim($custom_var['name']);
+    $custom_var['value'] = trim($custom_var['value']);
+    // Unset empty pairs from the array.
+    if(empty($custom_var['name']) && empty($custom_var['value'])) {
+      unset($form_state['values']['google_tag_manager_custom_vars'][$i]);
+      continue;
+    }
+  }
 }
 
+/**
+ * Layout for the custom variables table in the admin settings form.
+ */
+function theme_google_tag_manager_admin_custom_vars_table($variables) {
+  $form = $variables['form'];
+
+  $header = array(
+    array('data' => t('Name')),
+    array('data' => t('Value')),
+  );
+
+  $rows = array();
+  foreach (element_children($form) as $key => $id) {
+    $rows[] = array(
+      'data' => array(
+        drupal_render($form[$id]['name']),
+        drupal_render($form[$id]['value']),
+      ),
+    );
+  }
+
+  $output = theme('table', array('header' => $header, 'rows' => $rows));
+  $output .= drupal_render($form['token_tree']);
+  return $output;
+}
+
+
 // vim: set filetype=php expandtab tabstop=2 shiftwidth=2 autoindent smartindent:
diff --git a/google_tag_manager.module b/google_tag_manager.module
index 26aa498..1e49508 100644
--- a/google_tag_manager.module
+++ b/google_tag_manager.module
@@ -8,9 +8,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  * 	http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -93,6 +93,17 @@ function google_tag_manager_page_alter(&$page) {
 }
 
 /**
+ * Implements hook_theme().
+ */
+function google_tag_manager_theme() {
+  return array(
+    'google_tag_manager_admin_custom_vars_table' => array(
+      'render element' => 'form',
+    ),
+  );
+}
+
+/**
  * Outputs the Google Tag Manager JavaScript snippet.
  * @param string $containerId
  * @param string $customName
@@ -102,7 +113,15 @@ function _google_tag_manager_snippet($containerId = '', $customName = 'dataLayer
 		throw new Exception('Container ID is required');
 	}
 
-	$snippet = <<<EOL
+  // Load and insert each custom variable.
+  $json = array();
+  $custom_vars = variable_get('google_tag_manager_custom_vars', array());
+  foreach($custom_vars as $var) {
+    $json[token_replace($var['name'])] = token_replace($var['value']);
+  }
+  $snippet = '<script>' . $customName . ' = ['  . drupal_json_encode($json) .'] </script>';
+
+	$snippet .= <<<EOL
 <!-- Google Tag Manager -->
 <noscript><iframe src="//www.googletagmanager.com/ns.html?id=$containerId"
 height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
