You are here

protected function GoogleAnalyticsCounterAppManager::sumPageviews in Google Analytics Counter 8.3

Look up the count via the hash of the paths.

Parameters

$aliases:

Return value

string Count of views.

2 calls to GoogleAnalyticsCounterAppManager::sumPageviews()
GoogleAnalyticsCounterAppManager::gacDisplayCount in src/GoogleAnalyticsCounterAppManager.php
Get the count of pageviews for a path.
GoogleAnalyticsCounterAppManager::gacUpdateStorage in src/GoogleAnalyticsCounterAppManager.php
Save the pageview count for a given node.

File

src/GoogleAnalyticsCounterAppManager.php, line 323

Class

GoogleAnalyticsCounterAppManager
Class GoogleAnalyticsCounterAppManager.

Namespace

Drupal\google_analytics_counter

Code

protected function sumPageviews($aliases) {

  // $aliases can make pageview_total greater than pageviews
  // because $aliases can include page aliases, node/id, and node/id/, translations
  // redirects and other URIs which are all the same node.
  $hashes = array_map('md5', $aliases);
  $path_counts = $this->connection
    ->select('google_analytics_counter', 'gac')
    ->fields('gac', [
    'pageviews',
  ])
    ->condition('pagepath_hash', $hashes, 'IN')
    ->execute();
  $sum_pageviews = 0;
  foreach ($path_counts as $path_count) {
    $sum_pageviews += $path_count->pageviews;
  }
  return $sum_pageviews;
}