I'm trying to get Avantlink's code into my order confirmation page. The code should look like this when it's done:
<script type="text/javascript">
var _AvantMetrics = _AvantMetrics || [];
_AvantMetrics.push(['order',{ order_id:'[ORDER_ID]', amount:'[ORDER_AMOUNT]', state:'[BILLING_STATE]', country:'[BILLING_COUNTRY]' }]);
_AvantMetrics.push(['item',{ order_id:'[ORDER_ID]', parent_sku:'[ITEM_PARENT_SKU]', variant_sku:'[ITEM_VARIANT_SKU]', price:'[ITEM_PRICE]', qty:'[ITEM_QUANTITY]' }]);
</script>
Using this stack exchange article as a reference for adding success page confirmation: Add tracking code to success.phtml
Trying to put this into the bottom of success.phtml
<script type="text/javascript">
var _AvantMetrics = _AvantMetrics || [];
<?php
$newOrderId = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
$newOrder = Mage::getModel('sales/order')->load($newOrderId);
$items = $newOrder->getAllItems();
$currency = Mage::app()->getStore()->getCurrentCurrencyCode();
$billingAddress = $newOrder->getBillingAddress();
echo "_AvantMetrics.push(['order',{ order_id:'{$newOrder->getId()}', amount:'{$newOrder->getGrandTotal()}', state:'{$billingAddress->getRegionId();}', country:'{$billingAddress->getCountry();}' }]);";
foreach ($items as $item){
echo "_AvantMetrics.push(['item',{ order_id:'{$newOrder->getId()}', parent_sku:'{$item->getSku()}', variant_sku:'{$item->getSku()}', price:'{$item->getPrice()}', qty:'{$item->getQtyOrdered()}' }]);";
} ?>
</script>
But it doesn't work. When I do this, the success page breaks. Where am I going wrong?