Community Forums

Google Analytics Ecommerce Tracking

Free manual modifications can be contributed here. Modifications are manual snippets of code that are pasted into the forums for others to use.

Re: Google Analytics Ecommerce Tracking

Postby countzer0 » Tue Nov 22, 2011 8:37 pm

Kim_A wrote:Should i remove the normal tracking code if i use this mod?


No, all this mod does is to place a special Google Analytics tracking tag on the checkout completion page which passes the value of the transaction and the order details to the GA servers. This allows GA to calculate conversion data, for example to see the revenue from an AdWords campaign.

You will still need to leave the standard GA tag enabled in OpenCart.
Brighton Guitars, happily using OpenCart 1.5.3.1.
countzer0
 
Posts: 47
Joined: Sat Jun 18, 2011 3:09 pm

Re: Google Analytics Ecommerce Tracking

Postby Concept211 » Wed Jan 04, 2012 9:32 pm

countzer0: You had a very slight error in the code that was throwing a PHP error when loading the "success" page after checkout. It's been fixed (see attached).

Also posted in the extensions repository for everyone's convenience:
http://www.opencart.com/index.php?route ... on_id=4511

Thanks for your help!
Attachments
vQmod - Google Analytics E-commerce.zip
(1.98 KiB) Downloaded 338 times
User avatar
Concept211
 
Posts: 39
Joined: Thu Oct 13, 2011 5:40 pm

Re: Google Analytics Ecommerce Tracking

Postby countzer0 » Thu Jan 05, 2012 9:13 am

Concept211 - thanks so much! This was driving me nuts as the error only seemed to happen on the live success page, not the test. Well done for spotting it.
Brighton Guitars, happily using OpenCart 1.5.3.1.
countzer0
 
Posts: 47
Joined: Sat Jun 18, 2011 3:09 pm

Re: Google Analytics Ecommerce Tracking

Postby bendy00123 » Thu Jan 05, 2012 4:56 pm

hello

for the VQmod, step 7 : Make sure that you have "E-Commerce Tracking" turned on in your Google Analytics account.

where do i find this ? im unable to find it when im at the dashboard, serached for 1/2hr now..
bendy00123
 
Posts: 30
Joined: Tue Oct 11, 2011 11:30 pm

Re: Google Analytics Ecommerce Tracking

Postby countzer0 » Thu Jan 05, 2012 5:16 pm

Searching GA Help Centre for "e-commerce tracking" gives this as the first result: http://support.google.com/analytics/bin ... er=1009612
Brighton Guitars, happily using OpenCart 1.5.3.1.
countzer0
 
Posts: 47
Joined: Sat Jun 18, 2011 3:09 pm

Re: Google Analytics Ecommerce Tracking

Postby spitos » Mon Jan 09, 2012 4:31 pm

For anyone wanting comprehensive tracking with google analytics that just works and is easy to setup, with full instructions and free support. Checkout Google Analytics Expert:
http://www.opencart.com/index.php?route=extension/extension/info&extension_id=4496

Features:
E-Commerce Tracking, Goal & Funnel Reporting, Event Tracking, Search Tracking, support for Google Adwords, Multi-Store compatibility, EU Cookie Law compliance & more in a vqmod script.

Full E-commerce & Order tracking - See which products were ordered with data for Model/SKU, Product Name, Quantity, Product Price.

Full Product & Product Options Tracking and Reporting including Product Category, Shipping Costs & Taxes.

Also compatible with the popular Shoppica & Shoppica 2 themes & Bingo's popular one step / one page checkout extensions.
Last edited by spitos on Fri Jun 22, 2012 12:59 pm, edited 3 times in total.
Image Get it here
Google Analytics Expert - E-Commerce Tracking including Product Options, Goal & Funnel Reporting, Event Tracking, Search Tracking, Multi-Store compatibility & EU Cookie Law compliance. Works with Shoppica too!

Free Mods:
Remove Wishlist | Remember text in search box
Other Extensions:
Remove product counts, Opencart speedup & Improve page load time | All Extensions
User avatar
spitos
 
Posts: 258
Joined: Mon May 23, 2011 10:19 am
Location: UK

Re: Google Analytics Ecommerce Tracking

Postby countzer0 » Thu Jan 19, 2012 12:19 pm

I _still_ cannot get this vQmod to work. Looking in the xml file, the vQmod makes changes to the following files:

catalog/controller/checkout/success.php
catalog/model/checkout/order.php
catalog/view/theme/default/template/common/success.tpl

Looking in my vqcache folder, I can find the following cached modified scripts:

vq2-catalog_model_checkout_order.php
vq2-catalog_view_theme_default_template_common_success.tpl

but there is no vq2-catalog_controller_checkout_success.php. Does this mean that the mods to catalog/controller/checkout/success.php are not being made? There are no errors in my vQmod error log.

I'd appreciate any help.
Brighton Guitars, happily using OpenCart 1.5.3.1.
countzer0
 
Posts: 47
Joined: Sat Jun 18, 2011 3:09 pm

Re: Google Analytics Ecommerce Tracking

Postby nikythebest » Fri Mar 02, 2012 12:27 pm

I installed module but it seems something is wrong. Is no tracking all the transactions. Is missing some of my transactions. Anyone know why?
nikythebest
 
Posts: 38
Joined: Wed Sep 14, 2011 7:54 pm

Re: Google Analytics Ecommerce Tracking

Postby Concept211 » Fri Mar 02, 2012 1:22 pm

Hey all,

For some reason it looks like this isn't working properly. I'm not the creator of the code, I simply converted it to a vQmod but it looks like the original code isn't tracking any sales. If anyone has a fix, please post it so that we can update the vQmod and allow everyone to use it.

thanks!
User avatar
Concept211
 
Posts: 39
Joined: Thu Oct 13, 2011 5:40 pm

Re: Google Analytics Ecommerce Tracking

Postby theking1010 » Sun Mar 04, 2012 5:58 pm

Hi, I have PayPal as my only form of payment. When the customer purchases the item, the customer leaves the Paypal site and does not click go back to the Store site, where the store site GA code is on the success.tpl page, and then triggers the transaction data capture in GA.

How can this issue be fixed to where the GA transaction data is captured if the customer does not click on the link on PayPal to return to the Store site?

Thanks!
Elvis
theking1010
 
Posts: 14
Joined: Tue Nov 15, 2011 3:12 pm

Re: Google Analytics Ecommerce Tracking

Postby designbuyers » Sun Mar 04, 2012 9:36 pm

Is this method work with 1.5.2.1 ?
OpenCart :
The best Open Source Cart for eCommerce
User avatar
designbuyers
 
Posts: 150
Joined: Tue Nov 09, 2010 8:25 am

Re: Google Analytics Ecommerce Tracking

Postby theking1010 » Tue Mar 06, 2012 1:02 pm

I am running version 1.5.1.3. Can you help?
theking1010
 
Posts: 14
Joined: Tue Nov 15, 2011 3:12 pm

Re: Google Analytics Ecommerce Tracking

Postby marcelwoo » Wed Mar 07, 2012 3:39 am

Thanks! works like a charm!
Here:
Code: Select all
   <?php foreach($orderProducts as $product) { ?>
      _gaq.push(['_addItem',
          "<?php echo $product['order_id']; ?>",
          "<?php echo $product['product_id']; ?>",
          <?php echo json_encode($product['name']); ?>,
          "<?php echo $product['model']; ?>",
          "<?php echo $product['price']+($product['price']*$product['tax']/100); ?>",
          "<?php echo $product['quantity']; ?>"
       ]);
   <? } ?>


If I want to change $product['modle'] to category name (not category id), how should I do it? thx
"We help each other to grow". That's the opencart community!

All free mods
Home Based Ebay business Opportunity(not ads)
User avatar
marcelwoo
 
Posts: 291
Joined: Mon Mar 28, 2011 5:45 pm

Re: Google Analytics Ecommerce Tracking

Postby moneycarlo » Tue May 01, 2012 4:09 am

I updated to 1.5.2.2(r990) and added the missing fields like tax, shipping info etc.
I also changed the way the product price was being calculated. The numbers never came out correctly for my use and just seemed odd.
The old calculation was (i suspect they meant the price was supposed to be multiplied by the tax rate and not the actual tax?):
$product['price']+($product['price']*$product['tax']/100)

I changed it to:
$product['price']+$product['tax'];

Now, I'm no php/sql expert so the way i did it may not be the most efficient or proper, but what I do know, is that's working fine for me.
I cant promise I can answer any issues but will try.
Thanks!

** Sorry, there's a couple bugs I need to fix so I pulled the mod. Will re-up when I correct. Thanks and sorry **
Last edited by moneycarlo on Fri May 11, 2012 3:51 pm, edited 1 time in total.
moneycarlo
 
Posts: 147
Joined: Tue Sep 27, 2011 7:40 pm

Re: Google Analytics Ecommerce Tracking

Postby Concept211 » Tue May 01, 2012 12:12 pm

Thanks moneycarlo!
User avatar
Concept211
 
Posts: 39
Joined: Thu Oct 13, 2011 5:40 pm

Re: Google Analytics Ecommerce Tracking

Postby stonehinged » Mon May 07, 2012 7:03 pm

Moneycarlo, the tracking code is not rendering when I view the source on the success page using your vQmod.

Code: Select all
<?php if(isset($orderDetails) && isset($orderProducts) && isset($orderShipping) && isset($orderTax)) { ?>

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
  _gaq.push(['_addTrans',
    '<?php echo $orderDetails['order_id']; ?>',
    'STORE NAME',
    '<?php echo $orderDetails['total']; ?>',
    '<?php echo $orderTax[0]['value']; ?>',
    '<?php echo $orderShipping[0]['value']; ?>',
    '<?php echo $orderDetails['shipping_city']; ?>',
    '<?php echo $orderDetails['shipping_zone']; ?>',
    '<?php echo $orderDetails['shipping_country']; ?>'
   ]);

   <?php foreach($orderProducts as $product) { ?>
      _gaq.push(['_addItem',
          "<?php echo $product['order_id']; ?>",
          "<?php echo $product['product_id']; ?>",
          <?php echo json_encode($product['name']); ?>,
          "<?php echo $product['model']; ?>",
          "<?php echo $product['price']+$product['tax']; ?>",
          "<?php echo $product['quantity']; ?>"
       ]);
   <?php } ?>
   
   _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
(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>
<?php } ?>


Let me add the obvious... I have replaced the setAccount variable with mine ;D
Last edited by stonehinged on Tue May 08, 2012 3:48 pm, edited 1 time in total.
STONEHINGED
Handcrafted, Semi-Precious Jewelry
http://www.stonehinged.com/
User avatar
stonehinged
 
Posts: 113
Joined: Wed Aug 18, 2010 1:10 am
Location: US

Re: Google Analytics Ecommerce Tracking

Postby Svpernova09 » Tue May 08, 2012 1:42 pm

I've followed the instructions in the original post and I'm getting this error when I view source on the success page:

Code: Select all
<b>Notice</b>: Undefined variable: orderstuff in <b>catalog/view/theme/default/template/common/success.tpl</b> on line <b>5


The confusing part is line 5 seems meaningless. it's a comment of a JavaScript.

I've tried adding this code:
Code: Select all
<?php echo("<pre>"); print_r($orderstuff); echo("</pre>");
$thistotal = $orderstuff['total'];
echo("thistotal: $thistotal<BR>");
$thisorderid = $orderstuff['order_id'];
echo("thisorderid: $thisorderid<BR>");
?>


And it runs and shows the correct variables. But the fields are blank when I view the source.
OpenCart Version 1.5.1.3
catalog/controller/checkout/success.php
Code: Select all
   public function index() {
      if (isset($this->session->data['order_id'])) {
         $this->load->model('checkout/order');
         $this->data['orderDetails'] = $this->model_checkout_order->getOrder($this->session->data['order_id']);
         $this->data['orderProducts'] = $this->model_checkout_order->getOrderProducts($this->session->data['order_id']);
         $this->cart->clear();
         
         unset($this->session->data['shipping_method']);
         unset($this->session->data['shipping_methods']);
         unset($this->session->data['payment_method']);
         unset($this->session->data['payment_methods']);
         unset($this->session->data['guest']);
         unset($this->session->data['comment']);
         unset($this->session->data['order_id']);   
         unset($this->session->data['coupon']);
         unset($this->session->data['reward']);
         unset($this->session->data['voucher']);
         unset($this->session->data['vouchers']);
      }   

catalog/model/checkout/order.php
Code: Select all
public function getOrderProducts($order_id) {
    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");

            return $query->rows;
        } 


Any help would be appreciated.
Svpernova09
 
Posts: 1
Joined: Tue May 08, 2012 1:07 pm

Re: Google Analytics Ecommerce Tracking

Postby moneycarlo » Tue May 08, 2012 10:15 pm

stonehinged wrote:Moneycarlo, the tracking code is not rendering when I view the source on the success page using your vQmod.

Code: Select all
<?php if(isset($orderDetails) && isset($orderProducts) && isset($orderShipping) && isset($orderTax)) { ?>

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
  _gaq.push(['_addTrans',
    '<?php echo $orderDetails['order_id']; ?>',
    'STORE NAME',
    '<?php echo $orderDetails['total']; ?>',
    '<?php echo $orderTax[0]['value']; ?>',
    '<?php echo $orderShipping[0]['value']; ?>',
    '<?php echo $orderDetails['shipping_city']; ?>',
    '<?php echo $orderDetails['shipping_zone']; ?>',
    '<?php echo $orderDetails['shipping_country']; ?>'
   ]);

   <?php foreach($orderProducts as $product) { ?>
      _gaq.push(['_addItem',
          "<?php echo $product['order_id']; ?>",
          "<?php echo $product['product_id']; ?>",
          <?php echo json_encode($product['name']); ?>,
          "<?php echo $product['model']; ?>",
          "<?php echo $product['price']+$product['tax']; ?>",
          "<?php echo $product['quantity']; ?>"
       ]);
   <?php } ?>
   
   _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
(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>
<?php } ?>


Let me add the obvious... I have replaced the setAccount variable with mine ;D


Did you check your google account? Mine doesn't show it in the source either, but I use a proxy tool to see the values being sent. You can see this using something like firebug.
moneycarlo
 
Posts: 147
Joined: Tue Sep 27, 2011 7:40 pm

Re: Google Analytics Ecommerce Tracking

Postby moneycarlo » Tue May 08, 2012 10:28 pm

I don't know what orderstuff is. I never created or used that so I have no idea where that came from..you'll have to figure that out. Maybe it needs an isset?
comment it out and see what happens? Did you look at your google data or use a tool like firebug to see if the results posted?

Also, this could be an issue with 1.5.1.3 vs 1.5.2.2. I know a part of the order.php file was changed between these versions. I believe the addOrder was the change in 1.5.2.2:
public function addOrder($data)
moneycarlo
 
Posts: 147
Joined: Tue Sep 27, 2011 7:40 pm

Re: Google Analytics Ecommerce Tracking

Postby moneycarlo » Tue May 08, 2012 10:35 pm

I think if one changes my script it could work with 1.5.1.3:
change:
public function addOrder($data)

to:
public function create($data)

And i THINK that should work. no promises though since i'm no longer on that version, so someone can test it out and report back.
moneycarlo
 
Posts: 147
Joined: Tue Sep 27, 2011 7:40 pm

PreviousNext

Return to Modifications

Who is online

Users browsing this forum: No registered users and 4 guests

Hosted by Arvixe Web Hosting