Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jalle19/yii-ga
Google Analytics extension for the Yii framework
https://github.com/jalle19/yii-ga
Last synced: about 2 months ago
JSON representation
Google Analytics extension for the Yii framework
- Host: GitHub
- URL: https://github.com/jalle19/yii-ga
- Owner: Jalle19
- Created: 2013-07-09T11:30:38.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-06-03T12:17:52.000Z (over 10 years ago)
- Last Synced: 2024-10-12T13:26:18.154Z (3 months ago)
- Language: PHP
- Size: 173 KB
- Stars: 2
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
yii-ga
======Google Analytics extension for the Yii framework. It supports general tracking as well as tracking e-commerce transactions.
See https://developers.google.com/analytics/devguides/ for general information about Google Analytics integration.
Installation
------------Install the application using Composer and make sure you've included Composer's autoloader in your bootstrap file. After that you will need to add the following to your application configuration:
```php
// 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
),
),
),```
Usage
-----To register basic tracking support, add `Yii::app()->ga->registerTracking();` to your main layout file (assuming you want to track the whole site).
To register e-commerce transactions, adapt the following snippet to your needs (see the class files for which properties are available for transactions and transaction items):
```php
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);```
License
-------This application is licensed under the [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
Credits
-------Thanks to [@crisu83](https://github.com/Crisu83/) for giving me some pointers!