Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/n1crack/analytics
Analytics Package for Google Analytics Data API V4
https://github.com/n1crack/analytics
analytics api google-analytics
Last synced: 1 day ago
JSON representation
Analytics Package for Google Analytics Data API V4
- Host: GitHub
- URL: https://github.com/n1crack/analytics
- Owner: n1crack
- License: mit
- Created: 2021-05-18T22:09:48.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-05-23T19:59:23.000Z (over 3 years ago)
- Last Synced: 2024-10-16T23:06:24.091Z (27 days ago)
- Topics: analytics, api, google-analytics
- Language: PHP
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Analytics Package
Analytics Package for Google Analytics Data API V4
### Installation
Run
```bash
$ composer require ozdemir/analytics
```### Usage
```php
# Main Library
use Ozdemir\Analytics\Analytics;
use Ozdemir\Analytics\Period;# Optional reports, you can use these or create your own custom requests.
use Ozdemir\Analytics\Requests\PageViewsByCountry;
use Ozdemir\Analytics\Requests\PageViewsByReferer;use Ozdemir\Analytics\Requests\PageViews;
use Ozdemir\Analytics\Requests\PageViewsAndUsers;
use Ozdemir\Analytics\Requests\TopBrowsers;
use Ozdemir\Analytics\Requests\TotalUsersByChannels;
use Ozdemir\Analytics\Requests\MostVisitedPages;$config = [
'property' => '11111111', // Google Analytics Property ID
'credentials' => __DIR__ . '/credentials.json' // credentials.json file path or config array
];# we load the library
$analytics = new Analytics($config);# Requests are defined in an array
# Up to 5 requests can be executed in one batch request.
# It is set by Google, so we can't increase this at the moment.
$response = $analytics->fetch([
new PageViewsByReferer(
Period::days(7)
),new PageViewsByCountry(
Period::days(7),
5 # row limit, only returns 5 rows
),
]);# We can use the response value as we want.this is quite configurable.
# get($index): index number is the same order of the defined requests above.
# we can also cache the output as we want. It is very easy with the laravel.
return [
'pageViews' => $response->get(0)->toChartJs(), // ->toJson() is also available.
'pageViewsByCountry' => $response->get(1)->toChartJs(),
];```
#### todo:
- make a better readme / tutorial
- add unit tests