Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Transaction Data
- $orderID = $this->getOrderId();
- $order = Mage::getModel('sales/order')->loadByIncrementId($orderID);
- $orderTotal = $order->getGrandTotal();
- // you can also add affiliation, shipping and tax
- $trans = array('id' => $orderID,
- 'revenue' => $orderTotal);
- // List of Items Purchased
- $items = array();
- foreach ($order->getAllItems() as $item){
- // you can also add SKU and category
- $items[] = array('name' => $item->getName(),
- 'price' => $item->getPrice(),
- 'quantity' => $item->getQtyOrdered(),
- 'sku' => $item->getSku());
- }
- // Function to return the JavaScript representation of a TransactionData object.
- function getTransactionJs(&$trans) {
- return <<<HTML
- ga('ecommerce:addTransaction', {
- 'id': '{$trans['id']}',
- // if you added affiliation, shipping or tax above, include them here as well
- 'revenue': '{$trans['revenue']}'
- });
- HTML;
- }
- // Function to return the JavaScript representation of an ItemData object.
- function getItemJs(&$transId, &$item) {
- return <<<HTML
- ga('ecommerce:addItem', {
- 'id': '$transId',
- // if you added SKU or category above, include them here as well
- 'name': '{$item['name']}',
- 'price': '{$item['price']}',
- 'quantity': '{$item['quantity']}',
- 'sku' : '{$item['sku']}'
- });
- HTML;
- }
- ?>
- <script>
- ga('require', 'ecommerce', 'ecommerce.js');
- <?php
- echo getTransactionJs($trans);
- foreach ($items as &$item) {
- echo getItemJs($trans['id'], $item);
- }
- ?>
- ga('ecommerce:send');
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement