You are here

function piwik_init in Piwik Web Analytics 6.2

Same name and namespace in other branches
  1. 6 piwik.module \piwik_init()

Implementation of hook_init().

File

./piwik.module, line 58
Drupal Module: Piwik

Code

function piwik_init() {
  global $user;
  $id = variable_get('piwik_site_id', '');

  // 1. Check if the piwik account number has a value.
  // 2. Track page views based on visibility value.
  // 3. Check if we should track the currently active user's role.
  if (preg_match('/^\\d{1,}$/', $id) && _piwik_visibility_pages() && _piwik_visibility_user($user)) {

    // Add link tracking.
    $link_settings = array();
    $link_settings['trackMailto'] = variable_get('piwik_trackmailto', 1);
    drupal_add_js(array(
      'piwik' => $link_settings,
    ), 'setting', 'header');
    drupal_add_js(drupal_get_path('module', 'piwik') . '/piwik.js', 'module', 'header');
  }
}