X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Google Analytics Event Tracking (https://forum.x-cart.com/showthread.php?t=75553)

zone1creative 07-31-2017 03:18 AM

Google Analytics Event Tracking
 
A customer of mine recently wanted to know which products and category pages were the most viewed on his site via Google Analytics.

You can use the Site Content section to see all page loads, but it was more difficult to see just the product for instance.

So I implemented Event tracking for page loads on product, category and static pages on X-Cart 4.

Using this javascript as an example for a product page load

Code:

$(function () {
_gaq.push(['_trackEvent', 'Page Type View', 'Product', '234:Tennis Ball']);
});


You can use the following

Code:

{if $main eq "product"}
 
<script type="text/javascript">
$(function () {$ldelim}
        _gaq.push(['_trackEvent', 'Page Type View', 'Product', '{$product.productid}:{$product.product}']);
{$rdelim});
</script>
 
{elseif $main eq "catalog"}
 
<script type="text/javascript">
$(function () {$ldelim}
        _gaq.push(['_trackEvent', 'Page Type View', 'Category', '{$current_category.categoryid|default:'0'}:{$current_category.category|default:'Home Page'}']);
{$rdelim});
</script>
 
{elseif $main eq "pages"}
 
<script type="text/javascript">
$(function () {$ldelim}
        _gaq.push(['_trackEvent', 'Page Type View', 'Pages', '{$page_data.title}']);
{$rdelim});
</script>
 
{/if}


Here is a full example of the code
https://www.zone1creative.co.uk/know-products-selling-x-cart-store-know-pages-visited/


All times are GMT -8. The time now is 09:43 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.