PHP code example of jakubpas / gapi

1. Go to this page and download the library: Download jakubpas/gapi 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/ */

    

jakubpas / gapi example snippets



use JakubPas\Gapi;

$url = 'http://Url.of.page.under.analysis.net';
$ga = new Gapi('[email protected]', 'password');
$filter = 'pagePath == ' . $url;
$startDate = date("Y-m-d", 0);
$endDate = date("Y-m-d");

try {
    $ga->requestReportData(
        943763,
        array('pagePath'),
        array('pageviews'),
        null,
        $filter,
        $startDate,
        $endDate,
        1,
        2000
    );
    $pageViews = $ga->getMetrics()['pageviews'];
} catch (Exception $e) {
    $pageViews = 0;
}

echo $pageViews;