Visser Labs

Wednesday, December 16, 2009

Adding Google Analytics E-Commerce Tracking to WP E-Commerce

Over in the Instinct support forums I’ve been contributing towards implementing Google Analytics E-Commerce Tracking support for WP E-Commerce, I made some progress and am sharing my work below.

My solution only notifies Google Analytics of ‘successful’ transactions and does not support, as yet, the following:

  • total tax
  • state details
  • failed or abandoned sales

Note: This is an intermediate patch requiring PHP and limited phpMyAdmin knowledge, if you’re unsure of anything mentioned below I can install this for you, contact me for more details.

Instructions

  1. Backup transaction_result_functions.php within /wp-content/plugins/wp-e-commerce/ as you will need the original if anything goes wrong.
  2. Open transaction_result_functions.php with your favourite text editor
  3. On line #288, immediately after if($sessionid != null){ paste the contents of my patch
  4. On line #298 replace the Google Analytics tracking ID (e.g. UA-########-#) to your own
  5. Save changes

Test your new Google Analytics E-Commerce Tracking integration by successfully performing a live purchase and viewing the source code of the Transaction Results page, it should look similar to my sample below.

try {
var pageTracker = _gat._getTracker("UA-########-#");
pageTracker._trackPageview();
pageTracker._addTrans(
"3",
"Visser Labs",
"1.00",
"0.00",
"0.00",
"Mountain Creek",
"",
"AU"
);
pageTracker._addItem(
"3",
"0000000001",
"Assassin's Creed II",
"Xbox 360",
"1.00",
"1"
);

That’s it. In later versions I will add an Administrator interface and/or package this as a plugin for WP E-Commerce.

Download

Google Analytics E-Commerce Tracking for WP E-Commerce

6 Comments »

  1. February 1

    I’m sorry. I’m following everything you are saying except step 3 for “paste the contents of my patch.”

    I don’t see your patch anywhere on this page.

    Not sure sure if you mean the content inside your plugin.

    Could you email me exactly what I need to paste?

  2. February 1

    Hi Chris, better than showing you what to paste you can now just install WP E-Commerce Analytics, it’s my patch as a WordPress Plugin.

    Here’s the link:
    http://wordpress.org/extend/plugins/google-analytics-e-commerce-tracking-for-wp-e-commerce/

  3. April 23

    Hi Michael,

    I’m trying to implement the Google Adwords conversion tracking code into WP E-Commerce, do you know how to do that? Here’s a link that might be useful: https://adwords.google.com/support/aw/bin/answer.py?hl=en&answer=115794#

    Problem is that I wasn’t able to find a way, as I’m not a coding expert.

    I would highly appreciate any help you could give me.

    Thanks in advance!

  4. April 23

    Hi DDS, I can look at this when I get some spare time. This will likely happen in the next month, if this is urgent you can expedite this by commissioning this feature.

  5. Mathew
    May 26

    hi MIchael, i did install your plugin in my shop … but nothing is happening in my analytics … am i doing something wrong?

    thanksin advance!

  6. July 8

    I wrote an article about how to enable your adwords conversion tracking if your plugin doesn’t do it automatically for you: WordPress Conversion Tracking

    The basics of the article explains:
    1. Put conversion code in separate php file
    2. Put this in your footer
    3. Add php code to insert code only when users complete conversion

    This solution only works for on-site checkout and won’t solve your problem for Google Checkout, Paypal, etc.

Leave a comment

The perfect comment is interesting, on-topic and/or highly amusing.