PHP code example of omroepgelderland / atinternet-php-api

1. Go to this page and download the library: Download omroepgelderland/atinternet-php-api 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/ */

    

omroepgelderland / atinternet-php-api example snippets






use \piano_analytics_api\filter;
use \piano_analytics_api\period;

$site_id = 0;
$access_key = '';
$secret_key = '';

// Create API connection
$at = new \piano_analytics_api\Client($access_key, $secret_key);

// Get page titles and number of visits for each page,
// where the page title is not empty and domain is example.com,
// ordered by the number of visits from high to low.
$request = new \piano_analytics_api\Request($at, [
    'sites' => [$site_id],
    'columns' => [
        'date',
        'article_id',
        'site_id',
        'domain',
        'platform',
        'device_type',
        'os_group',
        'm_unique_visitors',
        'm_visits',
        'm_page_loads'
    ],
    'period' => new period\Day(
        new \DateTime('2023-06-01'),
        new \DateTime('2023-06-10')
    ),
    'sort' => [
        '-m_page_loads'
    ],
    'property_filter' => new filter\ListAnd(
        new filter\IsEmpty(
            'article_id',
            false
        ),
        new filter\Contains(
            'domain',
            [
                'example.nl',
                'www.example.nl'
            ]
        )
    )
]);

// All results
foreach ( $request->get_result_rows() as $item ) {
    echo \json_encode($item)."\n";
}

// Number of results
var_dump($request->get_rowcount());

// Cumulative metrics for all resulting rows
echo \json_encode($request->get_total())."\n";