googleanalyticscounter

Widget to show statistics of your website using Google Analytics API
9 followers

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/a111111w22222p987654321/
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:
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:
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)

Total 7 comments

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

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

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:

  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
Day

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