View Single Post
Old 07-31-2017, 03:18 AM
  zone1creative's Avatar 
zone1creative zone1creative is offline

Join Date: Jan 2009
Location: Hove, UK
Posts: 341

Default 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

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

You can use the following

{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
Pinakin Patel
Zone1 Creative Ltd
Reply With Quote