PHP code example of jalle19 / yii-ga

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

    

jalle19 / yii-ga example snippets


// change this path if necessary
Yii::setPathOfAlias('yiiga', realpath(__DIR__.'/../../vendor/jalle19/yii-ga/src/yiiga'));
...
return array(
	...
	'components'=>array(
		...
		'ga'=>array(
			'class'=>'yiiga\components\GoogleAnalytics',
			'accountId'=>'UA-XXXXXXX-X',
			'cookieDomain'=>'www.example.com', // optional
			'currency'=>'euro', // only needed if you're going to use e-commerce transactions
		),
	),
),




/* @var $order Order */

// Create a new transaction
$transaction = new yiiga\models\Transaction();
$transaction->orderId = $order->id;
$transaction->city = $order->city;
$transaction->country = $order->country;
$transaction->total = $order->total;
$transaction->tax = $order->tax;

// Add the order items to the transaction
foreach ($order->items as $orderItem)
{
	$item = new yiiga\models\TransactionItem();
	$item->sku = $orderItem->sku;
	$item->name = $orderItem->name;
	$item->price = ($orderItem->price + $orderItem->tax);
	$item->quantity = $orderItem->quantity;

	$transaction->addItem($item);
}

// Register the transaction
Yii::app()->ga->addTransaction($transaction);