Skip to content

Commit

Permalink
#1.21.5 GA stats fix. Replaced deprecated ga:timeOnSite metric with g…
Browse files Browse the repository at this point in the history
…a:avgSessionDuration
  • Loading branch information
damanic committed Jul 19, 2017
1 parent 2dd4e84 commit afc0576
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
12 changes: 6 additions & 6 deletions classes/cms_analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@ private static function initGaCache($start, $end)
* Fetch statistics data
*/

$current_data = $ga->downloadReport(array('ga:date'), array('ga:visits','ga:bounces','ga:newVisits','ga:timeOnSite','ga:pageviews','ga:visitors'), $start, $end);
$previous_data = $ga->downloadReport(array('ga:date'), array('ga:visits','ga:bounces','ga:newVisits','ga:timeOnSite','ga:pageviews','ga:visitors'), $prevStart, $prevEnd);
$current_data = $ga->downloadReport(array('ga:date'), array('ga:visits','ga:bounces','ga:newVisits','ga:avgSessionDuration','ga:pageviews','ga:visitors'), $start, $end);
$previous_data = $ga->downloadReport(array('ga:date'), array('ga:visits','ga:bounces','ga:newVisits','ga:avgSessionDuration','ga:pageviews','ga:visitors'), $prevStart, $prevEnd);

$pageviews_current = $current_data->totalsForAllResults['ga:pageviews'];
$pageviews_prev = $previous_data->totalsForAllResults['ga:pageviews'];

$visits_current = $current_data->totalsForAllResults['ga:visits'];
$visits_prev = $previous_data->totalsForAllResults['ga:visits'];

$time_current = $current_data->totalsForAllResults['ga:timeOnSite'];
$time_prev = $previous_data->totalsForAllResults['ga:timeOnSite'];
$time_current = $current_data->totalsForAllResults['ga:avgSessionDuration'];
$time_prev = $previous_data->totalsForAllResults['ga:avgSessionDuration'];

$bounces_current = $current_data->totalsForAllResults['ga:bounces'];
$bounces_prev = $previous_data->totalsForAllResults['ga:bounces'];
Expand All @@ -171,8 +171,8 @@ private static function initGaCache($start, $end)
'pageviews_current'=>$pageviews_current,
'pageviews_previous'=>$pageviews_prev,

'time_on_site_current'=>($visits_current > 0 ? round($time_current/$visits_current) : 0),
'time_on_site_previous'=>($visits_prev > 0 ? round($time_prev/$visits_prev) : 0),
'time_on_site_current'=>round($time_current),
'time_on_site_previous'=>round($time_prev),

'bounce_rate_current'=>($visits_current > 0 ? $bounces_current/$visits_current : 0),
'bounce_rate_previous'=>($visits_prev > 0 ? $bounces_prev/$visits_prev : 0),
Expand Down
6 changes: 6 additions & 0 deletions classes/cms_googleanalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public function login()

$client = new Google_Client();
$client->setClassConfig('Google_Cache_File', array('directory' => PATH_APP.'/temp/Google_Client/'));

if (isset($CONFIG['TRACE_LOG']['GOOGLE'])){
$client->setLoggerClass('Google_Logger_File');
$client->setClassConfig('Google_Logger_File', array('file' => $CONFIG['TRACE_LOG']['GOOGLE']));
}

$client->setApplicationName("Lemonstand_V1");
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
Expand Down
3 changes: 2 additions & 1 deletion updates/version.dat
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,5 @@
#1.21.1 Minor improvement to GA authentication: cache file uses lemonstand temp directory.
#1.21.2 Upgraded GA tracking to Universal Analytics, analytics.js library
#1.21.3 Fixed syntax error on GA ecommerce:addTransaction
#1.21.4 Added event cms:onBeforeSaveContentBlock
#1.21.4 Added event cms:onBeforeSaveContentBlock
#1.21.5 GA stats fix. Replaced deprecated ga:timeOnSite metric with ga:avgSessionDuration

0 comments on commit afc0576

Please sign in to comment.