You are here

function _hotjar_should_be_added in Hotjar 6

Same name and namespace in other branches
  1. 7 hotjar.module \_hotjar_should_be_added()

Check Hotjar code should be added.

1 call to _hotjar_should_be_added()
hotjar_add_js in ./hotjar.module
Insert JavaScript to the appropriate scope/region of the page.

File

./hotjar.module, line 115
Drupal Module: Hotjar.

Code

function _hotjar_should_be_added() {
  static $page_match;
  if (isset($page_match)) {
    return $page_match;
  }
  $settings = hotjar_get_settings();
  $visibility = $settings['hotjar_visibility_pages'];
  $setting_pages = $settings['hotjar_pages'];
  if (empty($setting_pages)) {
    $page_match = TRUE;
    return $page_match;
  }
  $pages = drupal_strtolower($setting_pages);
  if ($visibility < 2) {
    $path = drupal_strtolower(drupal_get_path_alias($_GET['q']));
    $page_match = drupal_match_path($path, $pages);
    if ($path != $_GET['q']) {
      $page_match = $page_match || drupal_match_path($_GET['q'], $pages);
    }

    // When $visibility has a value of 0, the tracking code is displayed on
    // all pages except those listed in $pages. When set to 1, it
    // is displayed only on those pages listed in $pages.
    $page_match = !($visibility xor $page_match);
  }
  else {
    $page_match = FALSE;
  }
  return $page_match;
}