Skip to content

Instantly share code, notes, and snippets.

@tvpmb
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save tvpmb/ad6144f967f879fe9ae0 to your computer and use it in GitHub Desktop.

Select an option

Save tvpmb/ad6144f967f879fe9ae0 to your computer and use it in GitHub Desktop.
TVPage Magento PHP Conversion Tracking Script
<!-- START TVPAGE CONVERSION SCRIPT -->
<?php
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$items = $order->getAllVisibleItems();
$trackItems = Array();
foreach($items as $i) {
$trackItems[] = '{ sku: "'.$i->getSku().'", price:"'.$i->getBasePrice().'", quantity:'.$i->getQtyOrdered().' }';
}
$trackData = implode(",", $trackItems);
?>
<script type="text/javascript">
(function() {
var tvpa = document.createElement('script'); tvpa.type = 'text/javascript'; tvpa.async = true;
tvpa.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://a.tvpage.com/tvpa.min.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(tvpa, s);
})();
var _tvpa = _tvpa || [];
_tvpa.push(['config', {
tr: "XXX", // Data source ID
li: "YYY" // Account ID
}]);
_tvpa.push(['track', 'products',[ <?php echo $trackData;?> ]]);
</script>
<!-- END TVPAGE CONVERSION SCRIPT -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment