Using the Analytics SDK to query, I inform the values for dimensions
, metrics
, start-date
and end-date
.
I get the query result with the correct data as I checked in the Anaytics
panel, but the date is returned as if it was the previous month.
In the example below, I pass the following dates as parameters to the documentation :
'start-date' => string '2016-06-01' (length=10)
'end-date' => string '2016-06-07' (length=10)
The query API
:
$lastDays = $this->getAnalytics(
$viewId = $this->getDefaultView(),
$startDate = '2016-06-01',
$endDate = '2016-06-07',
$metrics = 'ga:sessions, ga:bounces, ga:goalCompletionsAll, ga:pageviews',
[
'dimensions' => 'ga:date',
'output' => 'dataTable',
]
);
getAnalytics
method:
public function getAnalytics($viewId = 0, $startDate = null, $endDate = null, $metrics = null, $options = null){
if(!$viewId){
return false;
}
$GoogleAnalyticsAPI = Yii::$app->GoogleAnalytics->auth();
return $GoogleAnalyticsAPI->data_ga->get(
'ga:' . $viewId,
$startDate,
$endDate,
$metrics,
$options
);
}
returns the object:
object(backend\modules\aplicacao\lib\google\src\Google\Service\Google_Service_Analytics_Accounts)[156]
protected 'collection_key' => string 'items' (length=5)
protected 'internal_gapi_mappings' =>
array (size=0)
empty
protected 'itemsType' => string 'Google_Service_Analytics_Account' (length=32)
protected 'itemsDataType' => string 'array' (length=5)
public 'itemsPerPage' => int 1000
public 'kind' => string 'analytics#gaData' (length=16)
public 'nextLink' => null
public 'previousLink' => null
public 'startIndex' => null
public 'totalResults' => int 7
public 'username' => null
protected 'modelData' =>
array (size=8)
'id' => string 'xxxxxxxxxxxxxxxxxx' (length=190)
'query' =>
array (size=7)
'start-date' => string '2016-06-01' (length=10)
'end-date' => string '2016-06-07' (length=10)
'ids' => string 'xxxxxxxxxxxxxxxxxx' (length=11)
'dimensions' => string 'ga:date' (length=7)
'metrics' =>
array (size=4)
...
'start-index' => int 1
'max-results' => int 1000
'selfLink' => string 'xxxxxxxxxxxxxxxxxx' (length=190)
'profileInfo' =>
array (size=6)
'profileId' => string 'xxxxxxxxxxxxxxxxxx' (length=8)
'accountId' => string 'xxxxxxxxxxxxxxxxxx' (length=8)
'webPropertyId' => string 'xxxxxxxxxxxxxxxxxx' (length=14)
'internalWebPropertyId' => string 'xxxxxxxxxxxxxxxxxx' (length=8)
'profileName' => string 'xxxxxxxxxxxxxxxxxx' (length=16)
'tableId' => string 'xxxxxxxxxxxxxxxxxx' (length=11)
'containsSampledData' => boolean false
'columnHeaders' =>
array (size=5)
0 =>
array (size=3)
...
1 =>
array (size=3)
...
2 =>
array (size=3)
...
3 =>
array (size=3)
...
4 =>
array (size=3)
...
'totalsForAllResults' =>
array (size=4)
'ga:sessions' => string '137' (length=3)
'ga:bounces' => string '75' (length=2)
'ga:goalCompletionsAll' => string '0' (length=1)
'ga:pageviews' => string '447' (length=3)
'dataTable' =>
array (size=2)
'cols' =>
array (size=5)
...
'rows' =>
array (size=7)
...
protected 'processed' =>
array (size=0)
empty
The returned columns contain:
array (size=1)
'c' =>
array (size=5)
0 =>
array (size=1)
'v' => string 'Date(2016, 05, 01)' (length=18)
1 =>
array (size=1)
'v' => string '28' (length=2)
2 =>
array (size=1)
'v' => string '15' (length=2)
3 =>
array (size=1)
'v' => string '0' (length=1)
4 =>
array (size=1)
'v' => string '100' (length=3)
array (size=1)
'c' =>
array (size=5)
0 =>
array (size=1)
'v' => string 'Date(2016, 05, 02)' (length=18)
1 =>
array (size=1)
'v' => string '20' (length=2)
2 =>
array (size=1)
'v' => string '6' (length=1)
3 =>
array (size=1)
'v' => string '0' (length=1)
4 =>
array (size=1)
'v' => string '81' (length=2)
array (size=1)
'c' =>
array (size=5)
0 =>
array (size=1)
'v' => string 'Date(2016, 05, 03)' (length=18)
1 =>
array (size=1)
'v' => string '31' (length=2)
2 =>
array (size=1)
'v' => string '21' (length=2)
3 =>
array (size=1)
'v' => string '0' (length=1)
4 =>
array (size=1)
'v' => string '89' (length=2)
array (size=1)
'c' =>
array (size=5)
0 =>
array (size=1)
'v' => string 'Date(2016, 05, 04)' (length=18)
1 =>
array (size=1)
'v' => string '20' (length=2)
2 =>
array (size=1)
'v' => string '17' (length=2)
3 =>
array (size=1)
'v' => string '0' (length=1)
4 =>
array (size=1)
'v' => string '35' (length=2)
array (size=1)
'c' =>
array (size=5)
0 =>
array (size=1)
'v' => string 'Date(2016, 05, 05)' (length=18)
1 =>
array (size=1)
'v' => string '10' (length=2)
2 =>
array (size=1)
'v' => string '5' (length=1)
3 =>
array (size=1)
'v' => string '0' (length=1)
4 =>
array (size=1)
'v' => string '36' (length=2)
array (size=1)
'c' =>
array (size=5)
0 =>
array (size=1)
'v' => string 'Date(2016, 05, 06)' (length=18)
1 =>
array (size=1)
'v' => string '11' (length=2)
2 =>
array (size=1)
'v' => string '5' (length=1)
3 =>
array (size=1)
'v' => string '0' (length=1)
4 =>
array (size=1)
'v' => string '37' (length=2)
array (size=1)
'c' =>
array (size=5)
0 =>
array (size=1)
'v' => string 'Date(2016, 05, 07)' (length=18)
1 =>
array (size=1)
'v' => string '17' (length=2)
2 =>
array (size=1)
'v' => string '6' (length=1)
3 =>
array (size=1)
'v' => string '0' (length=1)
4 =>
array (size=1)
'v' => string '69' (length=2)
I could not find anything to indicate that there were changes in API
. Is there any parameter that should be passed?