I recently tried out Joost de Valk’s Google Analytics for WordPress (version 4) and was happy to see it supported ecommerce tracking for WP e-Commerce.
I had the latest version of WP e-Commerce installed, version 18.104.22.168, and configured the analytics plugin to track transactions but for some reason my ecommerce purchases were not being tracked by Google Analytics.
I did a bit of digging around and discovered the Analytics plugin was looking for the global variable $cart_log_id from which it could get the transaction details, but this variable did not seem to exist (it did seem to be in pre 3.7.6.x versions of WP e-Commerce though).
I have submitted a patch for this for the forthcoming WP e-Commerce version 3.8 (which is currently in beta and looking great, by the way).
In the meantime, if you’re having this problem here’s how you can fix it…
You’ll need to get your hands a little bit dirty, but fortunately you only have to edit one file. In the WP e-Commerce plugin folder open the transaction_results.php file.
Change the first line that defines global variables to add the $cart_log_id variable:
global $wpdb, $user_ID, $nzshpcrt_gateways, $sessionid, $cart_log_id;
At the end of the file just before the closing php tag we’ll query the database to get the $cart_log_id that will be used by the analytics plugin:
$cart_log_id = $wpdb->get_var( "SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $sessionid . " LIMIT 1" ); ?>
…and hopefully that should fix it.
I haven’t tested this for all versions of WP e-Commerce but it should certainly work on the latest 22.214.171.124 version.