PHP code example of panakour / analytics
1. Go to this page and download the library: Download panakour/analytics library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
panakour / analytics example snippets
'providers' => [
...
Panakour\Analytics\GoogleAnalyticsServiceProvider::class
]
'aliases' => [
...
'Analytics' => Panakour\Analytics\Facades\Analytics::class
]
Analytics::setDateRange('2016-10-01', '2016-11-25');
Analytics::get();
Analytics::setDateRange('2016-10-01', '2016-11-25');
Analytics::setMaxResults(20);
Analytics::setMetrics(['ga:entrances', 'ga:pageviews', 'ga:bounceRate']);
Analytics::setDimension(['ga:pagePath', 'ga:pageTitle']);
Analytics::setDimensionFilter('ga:pagePath', 'REGEXP', '/i-want-to-get-all-data-that-has-this-page-path');
Analytics::setOrder('ga:pageviews', 'VALUE', 'DESCENDING');
return Analytics::get();
use Panakour\Analytics\Contracts\Analytics;
class GoogleAnalyticsController
{
//inject analytics interface
public function get(Analytics $analytics)
{
$analytics->setDateRange('2016-12-01', '2016-12-20');
$analytics->setMaxResults(11);
$analytics->setMetrics(['ga:pageviews', 'ga:uniquePageviews', 'ga:avgTimeOnPage', 'ga:entrances', 'ga:bounceRate']);
$analytics->setDimension(['ga:pagePath', 'ga:pageTitle']);
$analytics->setDimensionFilter('ga:pagePath', 'REGEXP', '(\/this-value-in-path\/|\/or-this-value-in-path\/)');
$analytics->setOrder('ga:pageviews', 'VALUE', 'DESCENDING');
return $analytics->get();
}
}
shell
php artisan vendor:publish --provider="Panakour\Analytics\GoogleAnalyticsServiceProvider"