WordPress.org

Ready to get started?Download WordPress

Forums

Google Analytics for WordPress
Google eCommerce Not Tracking Sales (15 posts)

  1. szym9341
    Member
    Posted 2 years ago #

    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.

  2. mfshearer72
    Member
    Posted 2 years ago #

    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!

  3. borreped
    Member
    Posted 2 years ago #

    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?

  4. hifidesign
    Member
    Posted 2 years ago #

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

  5. cj3wilso
    Member
    Posted 2 years ago #

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

  6. ChainsawDR
    Member
    Posted 2 years ago #

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

  7. cj3wilso
    Member
    Posted 2 years ago #

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

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

  8. ChainsawDR
    Member
    Posted 2 years ago #

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

    Thanks again

    ChainsawDR

  9. cj3wilso
    Member
    Posted 2 years ago #

    Glad I could help! Let me know if any problems :)

  10. ChainsawDR
    Member
    Posted 2 years ago #

    Hi cj3wilso,

    The if statement...

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

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

    Thanks

    ChainsawDR

  11. cj3wilso
    Member
    Posted 2 years ago #

    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") {
    ?>

  12. ChainsawDR
    Member
    Posted 2 years ago #

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

    Thanks for all your help!!!!!!

  13. cj3wilso
    Member
    Posted 2 years ago #

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

  14. ChainsawDR
    Member
    Posted 2 years ago #

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

  15. Baden
    Member
    Posted 2 years ago #

    Exactly what I was looking for, thank you!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic