Magento Onepage Success Conversion Tracking Design Pattern
- by user1734954
My intent is to track conversions through multiple channels by inserting third party javascript (for example google analytics, optimizely, pricegrabber etc.) into the footer of onepage success .
I've accomplished this by adding a block to the footer reference inside of the checkout success node within local.xml and everything works appropriately.
My questions are more about efficiency and extensibility.
It occurred to me that it would be better to combine all of the blocks into a single block reference and then use a various methods acting on a single call to the various related models to provide the data needed for insertion into the javascript for each of the conversion tracking scripts.
Some examples of the common data that conversion tracking may rely on(pseudo):
Order ID , Order Total, Order.LineItem.Name(foreach) and so on
Currently for each of the scripts I've made a call to the appropriate model passing the customers last order id as the load value and the calling a get() assigning the return value to a variable and then iterating through the data to match the values with the expectations of the given third party service.
All of the data should be pulled once when checkout is complete
each third party services may expect different data in different formats
Here is an example of one of the conversion tracking template files which loads at the footer of checkout success.
$order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$amount = number_format($order->getGrandTotal(),2);
$customer = Mage::helper('customer')->getCustomer()->getData();
?>
<script type="text/javascript">
popup_email = '<?php echo($customer['email']);?>';
popup_order_number = '<?php echo $this->getOrderId() ?>';
</script>
<!-- PriceGrabber Merchant Evaluation Code -->
<script type="text/javascript" charset="UTF-8" src="https://www.pricegrabber.com/rating_merchrevpopjs.php?retid=<something>"></script>
<noscript><a href="http://www.pricegrabber.com/rating_merchrev.php?retid=<something>" target=_blank>
<img src="https://images.pricegrabber.com/images/mr_noprize.jpg" border="0" width="272" height="238" alt="Merchant Evaluation"></a></noscript>
<!-- End PriceGrabber Code -->
Having just a single piece of code like this is not that big of a deal, but we are doing similar things with a number of different third party services.
Pricegrabber is one of the simpler examples.
A more sophisticated tracking service expects a comma separated list of all of the product names, ids, prices, categories , order id etc.
I would like to make it all more manageable so my idea to do the following:
combine all of the template files into a single file
Develop a helper class or library to deliver the data to the conversion template
Goals Include
Extensibility
Minimal Model Calls
Minimal Method Calls
The Questions
1. Is a Mage helper the best route to take?
2. Is there any design pattern you may recommend for the "helper" class?
3. Why would this the design pattern you've chosen be best for this instance?