Widget to show statistics of your website using Google Analytics API

This extention is a wrapper of GAPI (gapi-google-analytics-php-interface)

and optionally show statistics via yii-chartjs


Google Analytics account
yii-chartjs [OPTIONAL]


1- Put this extension in your extensions folder.
2 - Put the following code in params.php

,'ga_email' => ''
,'ga_password' => 'yourpassword'
,'ga_profile_id' => 'profileid'


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
987654321 is the Id of your site.

If you have BadAuthentication error go to this url: 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.



$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


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)

Total 8 comments

#19878 report it
Ƒяąȼţąℓ ϻɨɲď at 2016/06/14 08:07pm
GAPI is deprecated, Do not use.

GAPI is deprecated, Do not use.

#15381 report it
howardEagle at 2013/11/03 04:56pm

That's great! Thank you!

#15326 report it
sepu at 2013/10/29 04:33am
More features

If you would like more features, please leave a comment.

#15321 report it
pmaselkowski at 2013/10/28 03:21pm
Re: Configuration options

Cool, now it looks much better :)

#15318 report it
sepu at 2013/10/28 09:28am
Thank you pmaselkowski

Thank you pmaselkowski, this is my first extension, in the new version I moved that fields in params.

#15300 report it
pmaselkowski at 2013/10/25 01:54pm
Configuration options


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' => ''
, 'ga_password' => 'yourpassword'
, 'ga_profile_id' => 'profileid'


 'components' => [
      'gaStats' => [
            'class' => 'application.extensions.gaStats.GaStatsConfig',
            'email' => '',
            'password' => 'password',
            'profileId' => 1234566

This would yield two benefits:

  1. Sensitive data in config file, not in view
  2. Don't need to repeat the same configuration data
#15282 report it
sepu at 2013/10/23 03:22am

I add that function ;)

#15279 report it
fouss at 2013/10/22 02:16pm
of the day?

Total visite of the day?

Leave a comment

Please to leave your comment.

Create extension