You are here

crazyegg.module in Crazy Egg Integration 6

Same filename and directory in other branches
  1. 8 crazyegg.module
  2. 7 crazyegg.module

File

crazyegg.module
View source
<?php

/**
 * Implements hook_permission().
 */
function crazyegg_perm() {
  return array(
    'administer crazy egg',
  );
}

/**
 * Implements hook_menu().
 */
function crazyegg_menu() {
  $items['admin/settings/crazyegg'] = array(
    'title' => 'Crazy Egg',
    'description' => 'Configure Crazy Egg heat maps on your website.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'crazyegg_admin_settings_form',
    ),
    'access arguments' => array(
      'administer crazy egg',
    ),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'includes/admin.inc',
  );
  return $items;
}

/**
 * Implementation of hook_help().
 */
function crazyegg_help($path, $arg) {
  switch ($path) {
    case 'admin/settings/crazyegg':
      return t('<a href="@url">Crazy Egg</a> is an analytics tool that provides website heatmaps and eye tracking.', array(
        '@url' => 'http://www.crazyegg.com',
      ));
  }
}

/**
 * Implements hook_footer() to insert JavaScript to the appropriate scope/region of the page.
 */
function crazyegg_footer($main = 0) {
  global $user;
  $account_id = variable_get('crazyegg_account_id', '');
  $crazyegg_enabled = variable_get('crazyegg_enabled', TRUE);
  if ($account_id && $crazyegg_enabled) {
    $scope = 'footer';
    $account_path = str_pad($account_id, 8, "0", STR_PAD_LEFT);
    $account_path = substr($account_path, 0, 4) . '/' . substr($account_path, 4, 8);
    $account_path = "pages/scripts/" . $account_path . ".js";
    $script_host = "dnn506yrbagrg.cloudfront.net";
    $script = '
      setTimeout(function(){var a=document.createElement("script");
      var b=document.getElementsByTagName(\'script\')[0];
      a.src=document.location.protocol+"//' . $script_host . '/' . $account_path . '";
      a.async=true;a.type="text/javascript";b.parentNode.insertBefore(a,b)}, 1);
      ';
    drupal_add_js($script, 'inline', 'footer');
  }
}

Functions

Namesort descending Description
crazyegg_footer Implements hook_footer() to insert JavaScript to the appropriate scope/region of the page.
crazyegg_help Implementation of hook_help().
crazyegg_menu Implements hook_menu().
crazyegg_perm Implements hook_permission().