function _piwik_visibility_pages in Piwik Web Analytics 8
Same name and namespace in other branches
- 5 piwik.module \_piwik_visibility_pages()
- 6.2 piwik.module \_piwik_visibility_pages()
- 6 piwik.module \_piwik_visibility_pages()
- 7.2 piwik.module \_piwik_visibility_pages()
- 7 piwik.module \_piwik_visibility_pages()
Tracking visibility check for pages.
Based on visibility setting this function returns TRUE if JS code should be added to the current page and otherwise FALSE.
1 call to _piwik_visibility_pages()
- piwik_page_attachments in ./
piwik.module - Implements hook_page_attachments().
File
- ./
piwik.module, line 635 - Drupal Module: Piwik.
Code
function _piwik_visibility_pages() {
static $page_match;
// Cache visibility result if function is called more than once.
if (!isset($page_match)) {
$config = \Drupal::config('piwik.settings');
$visibility_request_path_mode = $config
->get('visibility.request_path_mode');
$visibility_request_path_pages = $config
->get('visibility.request_path_pages');
// Match path if necessary.
if (!empty($visibility_request_path_pages)) {
// Convert path to lowercase. This allows comparison of the same path
// with different case. Ex: /Page, /page, /PAGE.
$pages = Unicode::strtolower($visibility_request_path_pages);
if ($visibility_request_path_mode < 2) {
// Compare the lowercase path alias (if any) and internal path.
$path = \Drupal::service('path.current')
->getPath();
$path_alias = Unicode::strtolower(\Drupal::service('path.alias_manager')
->getAliasByPath($path));
$page_match = \Drupal::service('path.matcher')
->matchPath($path_alias, $pages) || $path != $path_alias && \Drupal::service('path.matcher')
->matchPath($path, $pages);
// When $visibility_request_path_mode 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_request_path_mode xor $page_match);
}
elseif (\Drupal::moduleHandler()
->moduleExists('php')) {
$page_match = php_eval($visibility_request_path_pages);
}
else {
$page_match = FALSE;
}
}
else {
$page_match = TRUE;
}
}
return $page_match;
}