PHP code example of tda / laravel-google-analytics-admin

1. Go to this page and download the library: Download tda/laravel-google-analytics-admin 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/ */

    

tda / laravel-google-analytics-admin example snippets


https://www.googleapis.com/auth/analytics.edit

use Tda\LaravelGoogleAnalyticsAdmin\GoogleAnalyticsAdmin;
$analytics = new GoogleAnalyticsAdmin($token);

$accounts = $analytics->listAccounts();

$account = $analytics->getAccount($account);

$params = ['displayName' => 'New Name', 'regionCode' => 'DE'];
$account = $analytics->updateAccount($account, $params);

$analytics->deleteAccount($account);

$properties = $analytics->listProperties($account);

$analytics->getProperty($property);

$params = [
    'parent' => 'accounts/100',
    'currencyCode' => 'EUR',
    'displayName' => "GA 4 property",
    'industryCategory' => 'OTHER',
    "propertyType" => "PROPERTY_TYPE_ORDINARY",
    "timeZone" => "Europe/Berlin",
    'account' => 'accounts/100',
];
$property = $analytics->createProperty($params);

$enums = $analytics->getPropertiesResource();

$params = [
    'displayName' => 'Update GA 4 property', 
    'industryCategory' => 'TECHNOLOGY', 
    'timeZone' => 'America/New_York', 
    'currencyCode' => 'USD'
];
$property = $analytics->updateProperty($property, $params);

$analytics->deleteProperty(property);