Forçando o GA na tela de sucesso do Magento
<?php
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$price = $order->getGrandTotal();
$frete = $order->getShippingAmount();
$subtotalDireto = $order->getSubtotal();
$estado = $order->getBillingAddress()->getRegion();
$cidade = $order->getBillingAddress()->getCity();;
echo "Subtotal: R$ ".number_format($subtotalDireto, 2, ',', '');
echo " - Frete: R$ ".number_format($frete, 2, ',', '');
echo " - Total: R$ ".number_format($price, 2, ',', '');
echo " - Estado: ".$estado;
echo " - Cidade: ".$cidade;
$items = $order->getAllItems();
$itemcount=count($items);
?>
<!-- BEGIN GOOGLE ANALYTICS CODEs -->
<script type="text/javascript">
//<![CDATA[
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-23053096-1']);
_gaq.push(['_trackPageview', '/cielo/compra/confirmada/<?=$this->getOrderId()?>/']);
//_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'<?=$this->getOrderId()?>', // transaction ID - required
'Leoeletro - Compra com cielo', // affiliation or store name
'<?=$price?>', // total - required
'', // tax
'<?=$frete?>', // shipping
'<?=$cidade?>', // city
'<?=$estado?>', // state or province
'BRA' // country
]);
<?php
foreach ($items as $itemId => $item)
{
echo "
_gaq.push(['_addItem',
' ".$item->getId()." ', // order ID
' ".$item->getSku()." ', // SKU
' ".$item->getName()." ', // product name
'',
' ".$item->getPrice()." ', // product price
' ".$item->getQtyToInvoice()." ' // order quantity
]);
";
}
?>
_gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
//]]>
</script>
<!-- END GOOGLE ANALYTICS CODE -->
<!-/////////////////////////// RESULTADO ->
<!-- BEGIN GOOGLE ANALYTICS CODEs -->
<script type="text/javascript">
//<![CDATA[
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-23053096-1']);
_gaq.push(['_trackPageview', '/cielo/compra/confirmada/25099/']);
//_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'25099', // transaction ID - required
'Leoeletro - Compra com cielo', // affiliation or store name
'20.7300', // total - required
'', // tax
'16.7300', // shipping
'Rio de Janeiro', // city
'Rio de Janeiro', // state or province
'BRA' // country
]);
_gaq.push(['_addItem',
' 2167 ', // order ID
' cielo ', // SKU
' cielo ', // product name
'',
' 1.0000 ', // product price
' 4 ' // order quantity
]);
_gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
//]]>
</script>