// the expanded dataset that includes the subtables of pages. For some reason, Matomo
// doesn't aggregrate this value when there are sub pages, so we have to do it ourselves
$expanded_stats = $this->_supportUniqueVisitors() ? 1 : 0; // Only fetch extra data when it will be used
- $this->_pagesByPeriod = collect($this->getPageUrls(['expanded' => $expanded_stats]))
+ $this->_pagesByPeriod = collect($this->getPageUrls(['expanded' => 1]))
->map(function ($item, $date) {
return $this->_mapPagesByPeriod($item, $date);
});
+
//=== SUMMARY BY PERIOD
// Generate a list of available periods, based on the visits API data.
// If there are no visits for a certain period, we can assume that there won't be any data for other metrics.
protected function _mapPagesByPeriod($item, $date)
{
- //use ($period, $this->fluidbook_id, $hash, $this->_eventsByPeriod) {
if (empty($item)) {
return $item; // Some periods might have no data
}
- // Key results by their label to make it easier to isolate the "page" stats
- // More specifically, we want to get rid of the "/index" data because these aren't true page views
- $labelled = collect($item)->keyBy('label');
-
- if (!isset($labelled['page'])) {
- // If there's are no page stats, we treat it is if there's no data for this period
- // This is necessary because it's possible that there will be an '/index' item but no 'page'
- return [];
+ $data = [];
+ foreach ($item as $k => $v) {
+ if ($v['label'] === 'page') {
+ $data = array_merge($data, $v);
+ } else if ($v['label'] === '/index') {
+ $data['nb_openings'] = $v['nb_hits'];
+ }
}
- // By returning the page data directly (if available), it makes
- // the returned data flatter and easier to process later for sums etc.
- $data = $labelled['page'];
//== Unique Visitors
if ($this->_supportUniqueVisitors()) {
$data['nb_downloads'] = data_get($menu_events, 'download.nb_events', 0);
$data['nb_prints'] = data_get($menu_events, 'print.nb_events', 0);
+ if (empty($data['nb_openings']) || empty($data['nb_visits'])) {
+ return [];
+ }
+
return $data;
}
$pageUrls = collect($this->getPageUrls(['period' => 'range', 'flat' => 1]))
->keyBy('label');
- $this->viewData->openings = $pageUrls['/'];
- unset($pageUrls['/']);
-
//=== Group and combine page stats with related data
$res = [];
for ($page_number = 0; $page_number <= $this->fluidbook->getPagesNumber(); $page_number++) {