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 Xsecrets » Mon Jan 31, 2011 10:21 pm

jcgadgets wrote:
Xsecrets wrote:
Brocberry wrote:For those of us who send our customers to off-site to make payment, we need to give the gateway a page to send the customer back to once the transaction is complete... and then we tell GA which that page is I think. What page can we send the customer back to in OC for GA to recognise a complete transaction?

index.php?route=common/success most of the gateways will set this for you automatically.


Do you know if the PayPal Standard module has this set automatically?


Thank you,
Jared

yes it does.
Xsecrets
 
Posts: 5042
Joined: Sat Oct 24, 2009 7:51 pm
Location: FL US

Re: Google Analytics Ecommerce Tracking

Postby Xsecrets » Mon Jan 31, 2011 10:25 pm

jcgadgets wrote:I also wanted to see if what we have concluded here coincides with what others have come up in this thread?:

viewtopic.php?f=20&t=18926&hilit=ecomm

Or if perhaps we can get some ideas from there. Which modification method is "better"?


Thank you,
Jared

I think either one will work if you can figure them out since both seem to be very disjointed. Honestly google analytics with ecom support really should be put in the core. I mean seriously this is a shopping cart if you are going to bother providing analytics support in the core why wouldn't you add the ecommerce part since that should pretty much always be the main purpose of an opencart install.
Xsecrets
 
Posts: 5042
Joined: Sat Oct 24, 2009 7:51 pm
Location: FL US

Re: Google Analytics Ecommerce Tracking

Postby jcgadgets » Mon Jan 31, 2011 10:37 pm

Xsecrets wrote:...Honestly google analytics with ecom support really should be put in the core. I mean seriously this is a shopping cart if you are going to bother providing analytics support in the core why wouldn't you add the ecommerce part since that should pretty much always be the main purpose of an opencart install.


- Couldn't agree more! Couldn't have said it better. Very odd really, why it's not in the core. I wonder if it's planned for 1.5.0...

I guess I will just stick to this one, as this is the one I've already implemented. I'll watch and see if the next sale is captured (my site has only been live for just under a month, so the sales are coming in slowly as per nearly non-existent search rankings at the moment).

Thanks for the PayPal answer too :)


Thank you,
Jared
jcgadgets
 
Posts: 115
Joined: Sun Oct 31, 2010 8:49 am

Re: Google Analytics Ecommerce Tracking

Postby philbydevil » Wed Feb 02, 2011 11:50 am

I'm trying to write a vQmod for this but can't seem to get it working. Has anyone had any luck implementing these code changes?
I Image cmd-f, cmd-c, cmd-v, cmd-z + vQmod.
My favourite page...
v1.5.4.1
User avatar
philbydevil
 
Posts: 828
Joined: Thu Dec 02, 2010 9:20 pm
Location: Sunshine Coast, Australia

Re: Google Analytics Ecommerce Tracking

Postby justinv » Thu Feb 03, 2011 3:13 am

I have edited my original post - it should work now. There were a couple of steps that were missing, follow steps 5 and 6 to provide access to order details on the checkout page.

Thanks
Justin
justinv
 
Posts: 660
Joined: Tue Oct 12, 2010 5:24 am

Re: Google Analytics Ecommerce Tracking

Postby philbydevil » Thu Feb 03, 2011 5:09 am

Awesome justinv! That seems to be working now. Will get the vQmod cleaned up (and add some instructions) and upload it shortly.
I Image cmd-f, cmd-c, cmd-v, cmd-z + vQmod.
My favourite page...
v1.5.4.1
User avatar
philbydevil
 
Posts: 828
Joined: Thu Dec 02, 2010 9:20 pm
Location: Sunshine Coast, Australia

Re: Google Analytics Ecommerce Tracking

Postby philbydevil » Thu Feb 03, 2011 8:24 am

vQmod uploaded.

Be sure to read the installation instructions (install.txt) prior to use or it won't work.

Thanks for the code justinv ;)
Attachments
vQmod - Google Analytics E-commerce.zip
(3.59 KiB) Downloaded 352 times
I Image cmd-f, cmd-c, cmd-v, cmd-z + vQmod.
My favourite page...
v1.5.4.1
User avatar
philbydevil
 
Posts: 828
Joined: Thu Dec 02, 2010 9:20 pm
Location: Sunshine Coast, Australia

Re: Google Analytics Ecommerce Tracking

Postby philbydevil » Thu Feb 03, 2011 8:53 am

According to Google, it seems that all products need SKUs to be tracked correctly. Not sure if this is correct or not.

EDIT: the SKU seems to be the product_id (from the DB) so they don't need to be set manually in Admin.

One thing that I am noticing with my test transactions is that in GA, under E-Commerce, "Categories" is reporting the "Product Categories" as the model number of product/s, not the actual category.
I Image cmd-f, cmd-c, cmd-v, cmd-z + vQmod.
My favourite page...
v1.5.4.1
User avatar
philbydevil
 
Posts: 828
Joined: Thu Dec 02, 2010 9:20 pm
Location: Sunshine Coast, Australia

Re: Google Analytics Ecommerce Tracking

Postby jcgadgets » Wed Mar 02, 2011 9:31 pm

Hi all,

I just wanted to report that, unfortunately, this does not seem to be working for me :( I'm quite certain I implemented everything correctly, as I asked questions on the things I was not 100% certain about. I got a sale a few days ago, and just checked Google Analytics. Unfortunately, it was not reported there.

I'm going to give that other thread I mentioned a shot and see what happens.


Thank you!
Jared
jcgadgets
 
Posts: 115
Joined: Sun Oct 31, 2010 8:49 am

Re: Google Analytics Ecommerce Tracking

Postby justinv » Thu Mar 03, 2011 10:18 pm

Common problem is javascript errors on your page - if you have a js error, your analytics will not fire.

Create a free product and do some test purchases on it on your site, you should be able to see those come through or notice if there are js errors on the page using web developer toolbar in FF or the little icon bottom left in IE.
justinv
 
Posts: 660
Joined: Tue Oct 12, 2010 5:24 am

Re: Google Analytics Ecommerce Tracking

Postby jcgadgets » Fri Mar 04, 2011 7:30 am

Hey thanks!

I will try that out!


Thank you,
Jared
jcgadgets
 
Posts: 115
Joined: Sun Oct 31, 2010 8:49 am

Re: Google Analytics Ecommerce Tracking

Postby Brocberry » Sat Mar 19, 2011 5:10 pm

Xsecrets wrote:
Brocberry wrote:For those of us who send our customers off-site to make payment, we need to give the gateway a page to send the customer back to once the transaction is complete... and then we tell GA which that page is I think. What page can we send the customer back to in OC for GA to recognise a complete transaction?

index.php?route=common/success most of the gateways will set this for you automatically.


Thanks but I'm not sure I understand... that url, is that the real url for opencart and as it happens the same url for most other carts?
Brocberry
 
Posts: 47
Joined: Mon May 31, 2010 7:31 pm
Location: England

Re: Google Analytics Ecommerce Tracking

Postby traceofwind » Wed May 04, 2011 11:29 am

Hi Justinv, everyone

Two questions, if I may:

(1) Does this require the GA module to be installed (if GA code has been added to header.tpl manually)?
(2) Does the async GA snippet go before or after "<?php echo $google_analytics; ?>"?

NB: I have been tracking OpenCart via GA for some time (using the include method in the body tag) and have since switched to the async GA method, placing the code (below) in the header.tpl. I have never installed the GA module supplied with OpenCart's, however -I added the code myself. I was wondering then, if this would work for me or if someone could explain what the '<?php echo $google_analytics; ?>' code does?

Excerpt from my header.tpl (account number removed):
Code: Select all
<script type="text/javascript">
   var _gaq = _gaq || [];
   _gaq.push(['_setAccount', 'UA-xxxxxxx-xx']);
   _gaq.push(['_trackPageview']);
   (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 echo $google_analytics; ?>
</head>


Thanks in advance, all the best!

Gary
traceofwind
 
Posts: 82
Joined: Thu Jul 01, 2010 10:37 pm

Re: Google Analytics Ecommerce Tracking

Postby justinv » Thu May 05, 2011 7:56 am

Hi Gary,

The GA module gives you a text area in your admin where you can put your GA code from Google.

The echo $google_analytics; code puts whatever you put in admin onto your page. So putting your async GA code directly in the header.tpl is the same as enabling the GA module and putting the async GA code into your admin text area. Apart from by default, the echo $google_analytics; is in the footer, so on a default install it would go before the closing </body> tag.

In summary you should do one or the other - either enable the GA module, or paste your code directly into your header. Enabling the module would be preferable, as it's better to play by the rules.
justinv
 
Posts: 660
Joined: Tue Oct 12, 2010 5:24 am

Re: Google Analytics Ecommerce Tracking

Postby traceofwind » Fri May 13, 2011 3:02 pm

Hi,

I can't quite get this working. I have updated the relevant pages (1) footer.php, (2) header.php, (3) success.php, (4) order.php, (5) footer.tpl, (6) header.tpl and (7) success.tpl -but to no avail. Specifically, the Google Ecommerce tracking script does not appear in the source code upon Order Confirmation (success) page.

I am testing my site using 'Cash on delivery' payment method -that shouldn't cause any problems -should it?

Additionally, I would rather not use the vqMod as my files are already modified. At this point I'd appreciate any advice -I can't see what is wrong. My only clue is that Dreamweaver tells me there is a problem with the code syntax on the following lines:

Code: Select all
'<?php echo $orderDetails['order_id']; ?>',
...
'<?php echo $orderDetails['total']; ?>',


Any ideas?

Best regards,
Gary

PS,
Justinv -you may want to add to the first post, that the success.tpl code should be added before the '<?php echo $footer; ?>' code. Currently it doesn't specify where to insert the code.

EDIT-
Justin, your code for success.tpl, may I ask why you used this Asynchronous code in the body and not the header, or why did you not use the 'Traditional' code as per Google's own Ecommerce example code? It is my understanding that Async code (that you have kindly provided) is intended for the <head></head> tags -not to be included in the <body></body> tags -as the Traditional code is.
traceofwind
 
Posts: 82
Joined: Thu Jul 01, 2010 10:37 pm

Re: Google Analytics Ecommerce Tracking

Postby stonehinged » Fri May 27, 2011 1:07 pm

Shouldn't your code closing tag:

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']; ?>"
       ]);
   <? } ?>


be instead
Code: Select all
<?php } ?>


I'm also not seeing the ecom tracking code on my success page in the page source... almost like it didn't recognize the <?php if(isset($orderDetails) && isset($orderProducts)) { ?> statement, but I have confirmed the appropriate code to be in my success.php file before $this->cart->clear();

Please advise.
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 traceofwind » Fri May 27, 2011 3:01 pm

Similar to Stonehinged,

I am still experiencing the same issues: no e-commerce tracking code on the success page nor results in Google Analytics.

Also interesting what Stonehinged pointed regarding the closing tag, can anyone else confirm?

All the best
traceofwind
 
Posts: 82
Joined: Thu Jul 01, 2010 10:37 pm

Re: Google Analytics Ecommerce Tracking

Postby stonehinged » Fri May 27, 2011 4:31 pm

Unfortunately, it didn't help with the end result and achieving the data expected. I can't see the Google Ecom tracking at all in page source, but even stranger... no apparent errors in OC admin. It's like the "if" statement is coming back "null" so no code shows up. I may try an "else" statement to see if that content will display for me. If that does, that should fairly well conclude there's an issue with the "if" statement or code it's referring to on the success.php file.
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 stonehinged » Fri May 27, 2011 4:36 pm

So I can confirm with an "else" statement, the "else" condition displays... maybe this helps us debug?
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 traceofwind » Fri May 27, 2011 4:44 pm

Hi Stonehinged,

Nice idea, I had suspected the IF statement but hadn't thought of adding an ELSE statement to help us debug, kudos! I will try some debugging myself on this tangent and report back.

PS, did you try the VQ Mod or did you install manually?
traceofwind
 
Posts: 82
Joined: Thu Jul 01, 2010 10:37 pm

PreviousNext

Return to Modifications

Who is online

Users browsing this forum: No registered users and 10 guests

Hosted by Arvixe Web Hosting