nibinpaul / yii2-google-analytics
Show google analaytics data in your Dashboard using Google Analytics Embeded API
Installs: 778
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- google/apiclient: ^2.0
- yiisoft/yii2: ~2.0.0
This package is auto-updated.
Last update: 2024-04-08 06:20:12 UTC
README
Show google analaytics data chart in your dashboard using Google Analytics Embeded API.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist nibinpaul/yii2-google-analytics "*"
or add
"nibinpaul/yii2-google-analytics": "*"
to the require section of your composer.json
file.
Usage
Once the extension is installed, simply use it in your code by :
<?= \nibinpaul\analytics\Analytics::widget(['analyticsID'=>'ga:*********]); ?>
- Required properties
- analyticsID Google analyticsID.You can get the this value from this link.
- Optional properties
- startDate Start date for fetching Analytics data. Requests can specify a start date formatted as YYYY-MM-DD, or as a relative date (e.g., today, yesterday, or NdaysAgo where N is a positive integer). Defaut to - 30daysAgo
- endDate End date for fetching Analytics data. Request can specify an end date formatted as YYYY-MM-DD, or as a relative date (e.g., today, yesterday, or NdaysAgo where N is a positive integer). Defaut to today
- metrics A list of comma-separated metrics, such as ga:sessions,ga:bounces.Default to ga:sessions.
- dimensions A list of comma-separated dimensions for your Analytics data, such as ga:browser,ga:city. Default to ga:browser
- container_id The div id to be generated default to analayticsData.Add if uses more than one widget.
- extraFields The extra fields as array which are specified in this link
- chartType (string)The type of chart to be dispalay. The values may be LINE,BAR,TABLE etc..
Google Authentication
Google Authentication is Required to recive the data.
Go to the Google developers console
Create a new project (or use an existing project)
Open the project
Enable Analytics API
In Credentials page Create service account key or use Existing key. Download the file in json Format.
Put the file in @app/assets/certificate/service-account-credentials.json(rename the file).
Add the mailId of Service Account (we just created) into user Give ServiceAccount Access to the Analytics.(Add new user with Service-account-ID with Read & Analyze permissions)