omroepgelderland / atinternet-php-api
PHP implementation for the Piano Reporting API.
2.0.0
2024-10-31 18:27 UTC
Requires
- php: ^8.0
- ext-curl: *
- ext-date: *
- ext-json: *
Requires (Dev)
- phpstan/phpstan: ^1.12
- phpunit/phpunit: ^9.6
This package is auto-updated.
Last update: 2024-10-31 18:29:26 UTC
README
This library enables you to get queries from the Piano Analytics Reporting API v3. This is a third-party library. A subscription to Piano Analytics is required.
Requirements
Installation
You can use Composer or Download the Release
Composer
The preferred method is via composer. Follow the installation instructions if you do not already have composer installed.
Once composer is installed, execute the following command in your project root to install this library:
composer require omroepgelderland/atinternet-php-api
Finally, be sure to include the autoloader:
require_once '/path/to/your-project/vendor/autoload.php';
Usage example
- Create an API key in your Piano Analytics account.
- Get the access key and secret key from the API key.
- Find the site ID’s in Piano Analytics access management. Select a site on the page and copy the id from the address bar.
require_once __DIR__.'/../vendor/autoload.php'; 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";