Hi,
If you’re going to do it the manual way I figured most of it out. Doesn’t track city or category, but everything else tracks.
Open wpsc-transaction_results.php in
/wp-content/plugins/wp-e-commerce/wpsc-theme/wpsc-transaction_results.php
1. Purchase Tracking
At the bottom of the file add this code (Change UA-XXXXXXX-X to your UA code):
<!– GOOGLE ANALYTICS –>
<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘ UA-XXXXXXX-X ‘]);
_gaq.push([‘_trackPageview’]);
<?php
if ($_GET[“st”]==”Completed”) {
?>
_gaq.push([‘_addTrans’,
‘<?php echo $purchase_log[‘id’]; ?>’, // order ID – required
‘<?php echo get_bloginfo(‘name’); ?>’, // affiliation or store name
‘<?php echo $purchase_log[‘totalprice’]; ?>’, // total – required
‘<?php echo $purchase_log[‘wpec_taxes_total’]; ?>’, // tax
‘<?php echo $purchase_log[‘base_shipping’]; ?>’, // shipping
‘<?php echo ‘NA’; ?>’, // city
‘<?php echo wpsc_get_region( $purchase_log[‘billing_region’] ); ?>’, // state or province
‘<?php echo wpsc_get_country( $purchase_log[‘billing_country’] ); ?>’ // country
]);
<?php
$purchase_log_data_items_sql = mysql_query(“SELECT * FROM wp_wpsc_cart_contents WHERE purchaseid = “.$purchase_log[‘id’])or die(mysql_error());
//$purchase_log_data_items = mysql_fetch_array($purchase_log_data_items_sql);
while($purchase_log_data_item = mysql_fetch_array( $purchase_log_data_items_sql )){
//foreach( $purchase_log_data_items as $purchase_log_data_item ) {
$purchase_log_sku_sql = mysql_query(“SELECT meta_value FROM wp_postmeta WHERE meta_key = ‘_wpsc_sku’ AND post_id = ‘”.$purchase_log_data_item[‘prodid’].”‘ LIMIT 1″)or die(mysql_error());
$sku = mysql_fetch_assoc($purchase_log_sku_sql);
if ($sku[‘meta_value’] == ”){
$sku[‘meta_value’] = “NA”;
}
$purchase_log_data_item_parent_sql = mysql_query(“SELECT post_parent FROM wp_posts WHERE ID = ‘”.$purchase_log_data_item[‘prodid’].”‘ LIMIT 1″)or die(mysql_error());
$parent = mysql_fetch_assoc($purchase_log_data_item_parent_sql);
$purchase_log_data_item_categoryid_sql = mysql_query(“SELECT term_taxonomy_id FROM wp_term_relationships WHERE object_id = ‘”.$purchase_log_data_item[‘post_parent’].”‘ LIMIT 1″)or die(mysql_error());
$categoryid = mysql_fetch_assoc($purchase_log_data_item_categoryid_sql);
$purchase_log_data_item_category_sql = mysql_query(“SELECT name FROM wp_terms WHERE term_id = ‘”.$categoryid[‘term_taxonomy_id’].”‘ LIMIT 1″)or die(mysql_error());
$category = mysql_fetch_assoc($purchase_log_data_item_category_sql);
?>
// add item might be called for every item in the shopping cart
// where your ecommerce engine loops through each item in the cart and
// prints out _addItem for each
_gaq.push([‘_addItem’,
‘<?php echo $purchase_log[‘id’]; ?>’, // order ID – required
‘<?php echo $sku[‘meta_value’]; ?>’, // SKU/code – required
‘<?php echo $purchase_log_data_item[‘name’]; ?>’, // product name
‘<?php echo $category[‘name’]; ?>’, // category or variation
‘<?php echo $purchase_log_data_item[‘price’]; ?>’, // unit price – required
‘<?php echo $purchase_log_data_item[‘quantity’]; ?>’ // quantity – required
]);
_gaq.push([‘_trackTrans’]); //submits transaction to the Analytics servers
<?php
}
}
?>
(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘https://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<!– END GOOGLE ANALYTICS –>
2. General Tracking
For non-purchase tracking add this code to your theme header.php right after the opening body tag (Change UA-XXXXXXX-X to your UA code):
<?php
if ($_GET[“st”]!=”Completed”) {
?>
<!– GOOGLE ANALYTICS –>
<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-XXXXXXX-X’]);
_gaq.push([‘_trackPageview’]);
(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘https://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<!– END GOOGLE ANALYTICS –>
<?php
}
?>