Created
January 5, 2015 02:36
-
-
Save RabeaWahab/3c7a92573941d9dfe171 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use UnitedPrototype\GoogleAnalytics; | |
// initiate the tracker | |
$tracker = new GoogleAnalytics\Tracker($accountId, $account_domain); | |
// Assemble Visitor information | |
// (could also get unserialized from database) | |
$visitor = new GoogleAnalytics\Visitor(); | |
$visitor->setIpAddress($_SERVER['REMOTE_ADDR']); | |
$visitor->setUserAgent($_SERVER['HTTP_USER_AGENT']); | |
$visitor->setScreenResolution('1024x768'); | |
// Assemble Session information | |
$google_session = new GoogleAnalytics\Session(); | |
// Assemble Page information | |
$page = new GoogleAnalytics\Page('/checkout'); | |
$page->setTitle('Checkout'); | |
/** | |
* Google Analytics | |
* Event Tracking | |
**/ | |
// Create events to be tracked , examples: | |
$event1 = new GoogleAnalytics\Event('Checkout', 'Payment-Method', $payment_method); | |
$event2 = new GoogleAnalytics\Event('Checkout', 'Shipping-Method', $shipping_method); | |
$event3 = new GoogleAnalytics\Event('Checkout', 'Currency', $currency_code); | |
$event4 = new GoogleAnalytics\Event('Checkout', 'Coupon-Used', $coupon_code); | |
// Fire track event | |
$tracker->trackEvent($event1, $google_session, $visitor); | |
$tracker->trackEvent($event2, $google_session, $visitor); | |
$tracker->trackEvent($event3, $google_session, $visitor); | |
$tracker->trackEvent($event4, $google_session, $visitor); | |
/** | |
* Google Analytics | |
* Transaction Tracking | |
**/ | |
$trans = new GoogleAnalytics\Transaction(); | |
$trans->setOrderId($order_id); | |
$trans->setTotal($total); | |
$trans->setTax($tax_amount); | |
$trans->setShipping($shipping_amount); | |
$trans->setAffiliation('website'); | |
// Create an item | |
$new_item = new GoogleAnalytics\Item(); | |
$new_item->setOrderId($order_id); | |
$new_item->setName($product_name); | |
$new_item->setCategory($category_name); | |
$new_item->setPrice($price); | |
$new_item->setQuantity($qty_ordered); | |
$new_item->setSku($sku); | |
// Add item to transaction | |
$trans->addItem($new_item); | |
// Fire transaction | |
$tracker->trackTransaction($trans, $google_session, $visitor); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment