This extention is a wrapper of GAPI (gapi-google-analytics-php-interface)
https://code.google.com/p/gapi-google-analytics-php-interface/
and optionally show statistics via yii-chartjs
http://www.yiiframework.com/extension/yii-chartjs/
Requirements ¶
Yii
Google Analytics account
yii-chartjs [OPTIONAL]
Usage ¶
1- Put this extension in your extensions folder.
2 - Put the following code in params.php
,'ga_email' => 'your@email.com'
,'ga_password' => 'yourpassword'
,'ga_profile_id' => 'profileid'
Notice ¶
Notice: ga_profile_id is not the classic UA code, but is the Id of your site.
Enter in your google analytics account, example of url
https://www.google.com/analytics/web/?hl=it&pli=1#report/visitors-overview/a111111w22222p**987654321**/
987654321 is the Id of your site.
If you have BadAuthentication error go to this url:
https://accounts.google.com/DisplayUnlockCaptcha and unlock.
3 - Insert the following code in main.php
<?php $this->widget('ext.gaCounter.ExtGoogleAnalyticsCounter', array(
'strTotalVisits' => 'Totale visite',
'strDayVisits' => 'Visite giornaliere')
);?>
If you don't enter text in strTotalVisits or strDayVisits they don't appear.
Screenshot:
Charts ¶
<?php
$this->widget('ext.gaCounter.ExtGoogleAnalyticsCounter', array(
'lastYearChart' => true,
'title' => 'Last year',
'width' => 660,
'height' => 300)
);
$this->widget('ext.gaCounter.ExtGoogleAnalyticsCounter', array(
'lastMonthChart' => true,
'title' => 'Last month',
'width' => 400)
);
$this->widget('ext.gaCounter.ExtGoogleAnalyticsCounter', array(
'customDateChart' => true,
'startDate' => date('Y-m-d', strtotime('-1 week')),
'endDate' => date("Y-m-d"),
'typeChart' => 'day', //day or month. Default is month
'title' => 'Last week') //Optional
);
?>
Screenshot:
Change log ¶
Version 2.6
- Use session for best performance.
Version 2.5 - Fix bug that calculate total visits
- Moved config fields in params (thank you pmaselkowski)
of the day?
Total visite of the day?
Day
I add that function ;)
Configuration options
Hi!
You should move user related data to application component so this could be set in config and not hardcoded in view.
This fields should be configured once and in config only:
'ga_email' => 'you@example.com' , 'ga_password' => 'yourpassword' , 'ga_profile_id' => 'profileid'
Ie.:
'components' => [ 'gaStats' => [ 'class' => 'application.extensions.gaStats.GaStatsConfig', 'email' => 'you@example.com', 'password' => 'password', 'profileId' => 1234566 ],
This would yield two benefits:
Thank you pmaselkowski
Thank you pmaselkowski, this is my first extension, in the new version I moved that fields in params.
Re: Configuration options
Cool, now it looks much better :)
More features
If you would like more features, please leave a comment.
Thanks
That's great! Thank you!
GAPI is deprecated, Do not use.
GAPI is deprecated, Do not use.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.