Jump to content

[Tutorial] Integrate Google Analytics to the mobile theme


Recommended Posts

By default Google Analytics is not integrated to the mobile version even if the GG Analytics module is activated in the back office.

Also simply add the Google Analytics code on the template file header.tpl won't work because the mobile theme use mobile jQuery.

However there is a solution to adapt the GG Analytics code to mobile jQuery explained here: http://www.jongales....-jquery-mobile/

 

So in order to add Google Analytics to the mobile theme...

- in themes/prestashop_mobile/header.tpl just before </head> add

{literal}
<script type="text/javascript">
  	 var _gaq = _gaq || [];
  	 (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>
{/literal}

 

- in themes/prestashop_mobile/footer.tpl just before </body> add

{literal}
<script type="text/javascript">
$('[data-role=page]').live('pageshow', function (event, ui) {
  	 try {
	_gaq.push(['_setAccount', 'YOUR GG ANALYTICS ID']);

	hash = location.hash;

	if (hash) {
   	 _gaq.push(['_trackPageview', hash.substr(1)]);
	} else {
   	 _gaq.push(['_trackPageview']);
	}
  	 } catch(err) {

  	 }

});
</script>
{/literal}

 

Remember to replace YOUR GG ANALYTICS ID by your Google Analytics id!

  • Like 2
Link to comment
Share on other sites

  • 4 weeks later...

With Paypal it should work as the file themes/prestashop_mobile/modules/paypal/views/templates/front/order-confirmation.tpl is there. However for other payment modules you will have to add the confirmation template file to the mobile theme.

Note that if a customer does not come back to the website after the payment is completed the order won't be counted in GA. This problem is for both normal version and mobile version. I have this problem with the 2Checkout module. What I did is set up a custom report counting unique visitors arriving to the payment page. It's pretty accurate as not many customers stop the order process at this step.

Link to comment
Share on other sites

  • 5 weeks later...
×
×
  • Create New...