PHP code example of slm / google-analytics

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

    

slm / google-analytics example snippets


/**
 * Web property ID (something like UA-xxxxx-x)
 */
'id' => '',

public function fooAction ()
{
    $ga = $this->getServiceLocator()->get('google-analytics');
}

$ga->setEnableTracking(false);

$ga->setEnablePageTracking(false);

use SlmGoogleAnalytics\Analytics\Event;

$event = new Event('Videos', 'Play');
$ga->addEvent($event);

use SlmGoogleAnalytics\Analytics\Ecommerce\Transaction;
use SlmGoogleAnalytics\Analytics\Ecommerce\Item;

$transaction = new Transaction('1234', '28.28');

$item = new Item('5678', '11.99', '2', 'Blue elephant');
$transaction->addItem($item);

$ga->addTransaction($transaction);

$ga->setAnonymizeIp(true);

'google_analytics' => array(
    'anonymize_ip' => true,
),

$ga->setDomainName('example.com');
$ga->setAllowLinker(true);

'google_analytics' => array(
    'domain_name'  => 'example.com',
    'allow_linker' => true,
),

use SlmGoogleAnalytics\Analytics\CustomVariable;

$index = 1;
$name  = 'Section';
$value = 'Life & Style';
$var   = new CustomVariable($index, $name, $value);

$ga->addCustomVariable($var);

$scope = CustomVariable::SCOPE_SESSION;
$var   = new CustomVariable($index, $name, $value, $scope);

$ga->setEnableDisplayAdvertising(true);

'google_analytics' => array(
    'enable_display_advertising' => true,
),

 /**
 * Set the type of javascript to use for Google Analytics
 *
 * Allowed values: "google-analytics-ga" or "google-analytics-universal".
 */
'google_analytics' => array(
    'script' => 'google-analytics-universal',
),

curl -s http://getcomposer.org/installer | php
php composer.phar install