I’m developing an e-commerce using Wicket to render pages. I have a “BasePage” with the main layout and, in my “thank you for purchasing” page, I want to add Google Analytics e-commerce tracking code. As reference, the JS code like this:
<script type="text/javascript>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345678-9']);
_gaq.push(['_addTrans', '123', '', '12.56', '', '5.00']);
_gaq.push(['_addItem', '123', 'sku-1', 'Product 1', 'Category X', '12.56', '1']);
_gaq.push(['_addItem', '123', 'sku-2', 'Product 2', 'Category Y', '13.45', '1']);
_gaq.push(['_trackTrans']);
(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>
HTML code for cart and checkout was easy, but how can I generate this JS dynamically with Wicket?
Yes just to have a simple use of IHeaderContributor. Btw, are you using a framework for your wicket e-commerce? I have been trying to integrate one or two without much luck.