dev-master
9999999-devretrive results from google analytics
The Requires
by ahmedelsadany
Wallogit.com
2017 © Pedro PelĂĄez
retrive results from google analytics
Using this package you can easily retrieve data from Google Analytics., (*1)
``` bash composer require elsadany/google-analytics dev-master, (*2)
```php /// config/app ->providers Elsadany\Analytics\AnalyticsServiceProvider::class,
publish the config file of this package with this command: ``` bash php artisan vendor:publish, (*3)
The following config file will be published in `config/analyticsConfig.php`
```php
return[
/*
* The view id of which you want to display data.
*/
'view_id'=>'',
/*
the path of your layout
*/
'extend'=>'',
/*
Content Area Name
*/
'ContentArea'=>'',
/*
* Path to the client secret json file. Take a look at the README of this package
* to learn how to get this file. You can also pass the credentials as an array
* instead of a file path.
*/
//the service key path from the root example 'public/service.json'
'service_path'=>''
];
The first thing youâll need to do is to get some credentials to use Google APIâs. Iâm assuming that youâve already created a Google account and are signed in. Head over to Google APIâs site and click "Select a project" in the header., (*4)
, (*5)
Next up we must specify which APIâs the project may consume. In the list of available APIâs click "Google Analytics API". On the next screen click "Enable"., (*6)
, (*7)
Now that youâve created a project that has access to the Analytics API itâs time to download a file with these credentials. Click "Credentials" in the sidebar. Youâll want to create a "Service account key"., (*8)
, (*9)
On the next screen you can give the service account a name. You can name it anything youâd like. In the service account id youâll see an email address. Weâll use this email address later on in this guide. Select "JSON" as the key type and click "Create" to download the JSON file., (*10)
, (*11)
Save the json inside your Laravel project at the location specified in the service_account_credentials_json key of the config file of this package. Because the json file contains potentially sensitive information I don't recommend committing it to your git repository., (*12)
I'm assuming that you've already created a Analytics account on the Analytics site. Go to "User management" in the Admin-section of the property., (*13)
, (*14)
On this screen you can grant access to the email address found in the client_email key from the json file you download in the previous step. Read only access is enough., (*15)
, (*16)
The last thing you'll have to do is fill in the view_id in the config file. You can get the right value on the Analytics site. Go to "View setting" in the Admin-section of the property., (*17)
, (*18)
You'll need the View ID displayed there., (*19)
, (*20)
retrive results from google analytics