PHP code example of chappy84 / google-analytics-server-side

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

    

chappy84 / google-analytics-server-side example snippets




$gass = new \Gass\GoogleAnalyticsServerSide;
$gass->setAccount('UA-XXXXXXX-X')
    ->trackPageView();

$gass = new \Gass\GoogleAnalyticsServerSide;
$gass->setAccount('UA-XXXXXXX-X')
    ->setBotInfo(true);

$gass = new \Gass\GoogleAnalyticsServerSide(
    array(
        'account' => 'UA-XXXXXXX-X',
        'botInfo' => true
    )
);

\Gass\GoogleAnalyticsServerSide::trackEvent(
     string $category, 
     string $action, 
    [string $label = null, 
    [int    $value = null, 
    [bool   $nonInteraction = false]]] 
);

$gass = new \Gass\GoogleAnalyticsServerSide(
    array(
        'botInfo' => true,
        'account' => 'UA-XXXXXXX-X',
    )
);

$gass = new \Gass\GoogleAnalyticsServerSide(
    array(
        'botInfo' => array(
            'adapter' => 'BrowsCap',
            \Gass\BotInfo\BrowsCap::OPT_SAVE_PATH => '/var/lib/browscap',
            \Gass\BotInfo\BrowsCap::OPT_INI_FILE => 'full_php_browscap.ini',
        ),
        'account' => 'UA-XXXXXXX-X'
    )
);

$gass = new \Gass\GoogleAnalyticsServerSide(array('account' => 'UA-XXXXXXX-X'));
$browsCapAdapter = new \Gass\BotInfo\BrowsCap;
$gass->setBotInfo($browsCapAdapter);

$gass = new \Gass\GoogleAnalyticsServerSide(
    array(
        'account' => 'UA-XXXXXXX-X',
        'http' => array(
            'adapter' => 'Curl',
            CURLOPT_PROXY => 'http://exampleproxy.local:8080'
        )
    )
);

$gass = new \Gass\GoogleAnalyticsServerSide(array('account' => 'UA-XXXXXXX-X'));
$httpAdapter = new \Gass\Http\Stream;
$gass->setHttp($httpAdapter);