• I’m trying to help a store owner get his sales info tracked by Google Analytics. We recently installed G. Analytics for WP 4.1.3 and it noticed WP e-Commerce and asked if wanted to track sales (we clicked yes). After multiple transactions, G. Analytics is not reporting any ecomm data, but all other data is being tracked (views, bounce, etc).

    Running: WP eCommerce 3.8.6
    Running: Gold Cart for WP eCommerce 2.9.3
    Running: Google Analytics for WP 4.1.3

    (everything is up-to-date as of 8/24/2011)

    I’ve looked at the /products-page/transactions-results/ html page after placing an order and see the Google JS there, but no transaction related code-block.

    Questions:
    1) What page should I see this transactional JS code?
    2) If everything is up-to-date, what is the best way to start troubleshooting this?

    Thank you.

    -Adam.

Viewing 14 replies - 1 through 14 (of 14 total)
  • I am also having this error. Same specs above except I am still on 2.8 Gold Cart.

    Adam, did you ever resolve this?

    Thanks!

    I’m having the same problem. Everything else is tracked except the sales.

    Running: WP 3.0.5
    Running WP E-commerce 3.7.8
    Running Google Analytics for WP 4.1

    Any solution yet?

    Tom Finley

    (@hifidesign)

    Same boat. I’ve seen no solutions thus far.

    Having the same problem. If anyone figures this out let us know! Thanks ??

    Having same issue, logged a bug report 60 days ago though ?? so going to uninstall plugin and try a manual job next week

    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&#8217; : ‘https://www&#8217;) + ‘.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&#8217; : ‘https://www&#8217;) + ‘.google-analytics.com/ga.js’;
    var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
    })();

    </script>
    <!– END GOOGLE ANALYTICS –>
    <?php
    }
    ?>

    Thanks cj3wilso – I’ll give it a crack at the weekend and let you know how I get on.

    Thanks again

    ChainsawDR

    Glad I could help! Let me know if any problems ??

    Hi cj3wilso,

    The if statement…

    <?php
    if ($_GET[“st”]==”Completed”) {
    ?>

    …wasn’t called for me. Could it be coded a different way?

    Thanks

    ChainsawDR

    Yeah sure. All I did was grab the st parameter in the transaction results URL. When you make a purchase in PayPal it should redirect back to your website.. the URL should look something like this:

    /transaction-results/?sessionid=333&tx=rew6555&st=Completed&amt=100.00&cc=CAD&cm=&item_number=

    I used the parameter “st” to check whether a purchase was made. Whatever page it redirects to, you could grab the page URL with PHP using this:
    $_SERVER[“REQUEST_URI”]
    This will grab the URL after the main domain… so “/test.php” NOT “www.apple.com/test.php”

    <?php
    if ($_SERVER[“REQUEST_URI”]==”/test.php”) {
    ?>

    looking good so far, will check GA in a couple of days.

    Thanks for all your help!!!!!!

    Great. Let me know that it all works out. Glad to help! ??

    perfect, seeing the three test transactions in Google Analytics now. Thanks for all of your help!!!

    Exactly what I was looking for, thank you!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Google eCommerce Not Tracking Sales’ is closed to new replies.