You are here

protected function GoogleAnalyticsEventTracking::pathMatch in Google Analytics Event Tracking 8.2

Same name and namespace in other branches
  1. 8 src/GoogleAnalyticsEventTracking.php \Drupal\google_analytics_et\GoogleAnalyticsEventTracking::pathMatch()

Evaluates whether the tracker is effective for the current path.

Parameters

\Drupal\google_analytics_et\Entity\GoogleAnalyticsEventTrackerInterface $tracker:

Return value

bool

1 call to GoogleAnalyticsEventTracking::pathMatch()
GoogleAnalyticsEventTracking::isTrackerActive in src/GoogleAnalyticsEventTracking.php
Evaluates whether the provided event tracker is active in current context.

File

src/GoogleAnalyticsEventTracking.php, line 114

Class

GoogleAnalyticsEventTracking

Namespace

Drupal\google_analytics_et

Code

protected function pathMatch(GoogleAnalyticsEventTrackerInterface $tracker) {
  if (!$tracker
    ->status()) {
    return FALSE;
  }
  $paths = rtrim($tracker
    ->get('paths'));

  // If no paths provided this tracker will match all paths.
  if (empty($paths)) {
    return TRUE;
  }
  $path = $this->currentPath
    ->getPath();
  $path_alias = $this->aliasManager
    ->getAliasByPath($path);
  $path_alias = Unicode::strtolower($path_alias);
  $path_match = $this->pathMatcher
    ->matchPath($path_alias, $paths) || $this->pathMatcher
    ->matchPath($path, $paths);

  // When $tracker->path_negate has a value of 1, the asset is
  // added on all pages except those listed in $tracker->paths.
  // When set to 0, it is added only on those pages listed in
  // $tracker->paths.
  return $tracker
    ->get('path_negate') xor $path_match;
}