PHP code example of sherin / google-analytics

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

    

sherin / google-analytics example snippets


$credentials = new Credentials();
$credentials->setFromArray($this->getGoogleCredentials());

private function getGoogleCredentials(): array
{
    return [  
        "type" => getenv("GOOGLE_TYPE"),  
        "project_id" => getenv("GOOGLE_TYPE"),  
        "private_key_id" => getenv('GOOGLE_PRIVATE_KEY_ID'),  
        "private_key" => str_replace('\n', PHP_EOL, getenv('GOOGLE_PRIVATE_KEY')),  //Dirty fix because older DotEnv versions does not support multi-lined variables. (since v3.0 but only supports php 7.2.
        "client_email" => getenv('GOOGLE_CLIENT_EMAIL'),  
        "client_id" => getenv('GOOGLE_CLIENT_ID'),  
        "auth_uri" => getenv("GOOGLE_AUTH_URI"),  
        "token_uri" => getenv("GOOGLE_TOKEN_URI"),  
        "auth_provider_x509_cert_url" => getenv("GOOGLE_AUTH_PROVIDER_CERT_URL"),  
        "client_x509_cert_url" => getenv('GOOGLE_CLIENT_CERT_URL')  
    ];
}