Google Analytics Enhanced Ecommerce Tracking for OpenCart

  1. Home
  2. Docs
  3. Google Analytics Enhanced Ecommerce Tracking for OpenCart
  4. Installation
  5. Journal2 User

Journal2 User

Open catalog/view/theme/journal2/js/journal.js

Change 1: Add the following code the end of the page

function gaAddtocart(e){$.ajax({url:"index.php?route=extension/module/google_ecommerce/get_product_info&product_id="+e,type:"post",dataType:"json",success:function(e){e.error?console.log(e.error):gtag("event","add_to_cart",{items:[{id:e.id,name:e.product_name,list_name:e.list_name,brand:e.brand,category:e.category,price:e.price}]})}})}function gaRemovefromcart(e){$.ajax({url:"index.php?route=extension/module/google_ecommerce/get_product_info&product_id="+e,type:"post",dataType:"json",success:function(e){e.error?console.log(e.error):gtag("event","remove_from_cart",{items:[{id:e.id,name:e.product_name,list_name:e.list_name,brand:e.brand,category:e.category,price:e.price}]})}})}

 

Example:

Change 2: Add the following code as shown in two places

gaAddtocart(product_id);

Change 3: Add the following code as shown (only for opencart 2.1.0.1 and higher versions)

gaRemovefromcart(json.product_id);

 

Was this article helpful to you? Yes No