PHP code example of ommu / gapi-google-analytics-php-interface
1. Go to this page and download the library: Download ommu/gapi-google-analytics-php-interface 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/ */
ommu / gapi-google-analytics-php-interface example snippets
$ga = new gapi('[email protected]','oauthkeyfile.p12');
$ga->requestReportData(145141242,array('browser','browserVersion'),array('pageviews','visits'));
foreach($ga->getResults() as $result)
{
echo '<strong>'.$result.'</strong><br />';
echo 'Pageviews: ' . $result->getPageviews() . ' ';
echo 'Visits: ' . $result->getVisits() . '<br />';
}
echo '<p>Total pageviews: ' . $ga->getPageviews() . ' total visits: ' . $ga->getVisits() . '</p>';
foreach($ga->getResults() as $result)
{
echo $result->getUniquePageviews();
echo $result->getPagePath();
}