PHP code example of megaads / ga-service

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

    

megaads / ga-service example snippets


$KEY_FILE_LOCATION =  '../config/client-secrets.json';
$name = 'Chiaki';
$filter = [
    'viewId' => 'xxxxxxxx',
    'from' => '2020-02-01',
    'to' => '2020-02-25',
    'metrics' => [
       'ga:sessions', 'ga:users', 'ga:bounces'
    ]
];
$gaTransfer = new \GaServices\GoogleAnalytic();
$items = $gaTransfer->report($name, $KEY_FILE_LOCATION, $filter);

\\ Get cost ads of account
$adsCostAccount = new \GaServices\AdsCostAccount();
$fileConfig = '../config/adsapi_php.ini';
$customerId = 'xxx-xxx-xxxx';
$filter = ['from' => '2020-01-01', 'to' => '2020-01-29']
$cost = $adsCostAccount->report($customerId, $fileConfig, $filter);