protected function _addCustomVars() { $this->_formatedResponse->perf = new stdClass(); // prepare time and memory calculation $field = 'customVarValue' . SH404SEF_ANALYTICS_TIME_CUSTOM_VAR; $totalPages = 0; $totalTime = 0; $totalMemory = 0; // now iterate over time and memory records foreach ($this->_rawData['page-creation-time'] as $entry) { $record = intval($entry->dimension[$field]); // make it an int, this will remove dev data that had decimals // sanitize $record = $record < 3 ? 0 : $record; // we only calculate averaged on pages we have time and ram data for if (!empty($record)) { // separate time and memory $time = $record >> 4; // bits 5 and up $memory = $record & 15; // bits 1 to 4 // aggregate $totalPages += $entry->pageviews; $totalTime += Sh404sefHelperAnalytics::declassifyTime($time) * $entry->pageviews; $totalMemory += Sh404sefHelperAnalytics::declassifyMemory($memory) * $entry->pageviews; } } // calculate averages time and ram now $this->_formatedResponse->perf->avgPageCreationTime = empty($totalPages) ? 0 : $totalTime / $totalPages; $this->_formatedResponse->perf->avgMemoryUsed = empty($totalPages) ? 0 : $totalMemory / $totalPages; // logged in users handling $field = 'customVarValue' . SH404SEF_ANALYTICS_USER_CUSTOM_VAR; $groups = Sh404sefHelperGeneral::getUserGroups(); $loggedInPages = 0; foreach ($this->_rawData['logged-in-users'] as $entry) { $userType = urldecode($entry->dimension[$field]); // if user was logged in, any group, including "Public Frontend" if (in_array($userType, $groups)) { // include # of pages $loggedInPages += $entry->pageviews; } } $this->_formatedResponse->perf->loggedInUserRate = empty($this->_formatedResponse->global->pageviews) ? 0 : $loggedInPages / $this->_formatedResponse->global->pageviews; }