function crazyegg_page_alter in Crazy Egg Integration 7
Implements hook_page_alter(). Checks all conditions and injects tracking script into the page if needed
File
- ./
crazyegg.module, line 61 - The official Crazy Egg Plugin for Drupal. The easiest, free way to add your Crazy Egg tracking script to your Drupal site. See https://www.crazyegg.com for details.
Code
function crazyegg_page_alter(&$page) {
$account_id = variable_get('crazyegg_account_id', '');
$crazyegg_enabled = variable_get('crazyegg_enabled', TRUE);
// if module is enabled, there is numeric account ID, user role is allowed and current page matches page targeting setting
if ($crazyegg_enabled && is_numeric($account_id) && crazyegg_is_role_allowed() && crazyegg_is_page_allowed()) {
$account_path = str_pad($account_id, 8, '0', STR_PAD_LEFT);
$account_path = drupal_substr($account_path, 0, 4) . '/' . drupal_substr($account_path, 4, 8);
$script_path = '//script.crazyegg.com/pages/scripts/' . $account_path . '.js';
$crazyegg_scope = variable_get('crazyegg_js_scope', 'header');
drupal_add_js($script_path, array(
'type' => 'external',
'scope' => $crazyegg_scope,
'weight' => 0,
'defer' => TRUE,
));
}
}