Jump to:

2081 Posts in 1001 Topics by 452 members

E-Commerce Modules

SilverStripe Forums » E-Commerce Modules » SwipeStripe Google Anaytics Ecommerce Tracking

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba, simon_w

Page: 1
Go to End
Author Topic: 855 Views
  • helenclarko
    Avatar
    Community Member
    25 Posts

    SwipeStripe Google Anaytics Ecommerce Tracking Link to this post

    Hi All,

    I have been looking around for ways to add The Google Analytics Ecommerce tracking code into SwipeStripe for the last couple of days.

    I have had no success, but was wondering if I was going about this the right way.

    I have been editing the Order.php file in the "Swipestripe/Code/Order" Directory, as I believe this is the page displayed when the user finishes purchasing items.

    Can someone please let me know if the following looks correct, or if there is anything I should be doing?

    The following has been added to Order.php:

    class Order_Controller extends ContentController {
       public function init() {
          parent::init();
          Requirements::insertHeadTags("<script type='text/javascript'>
    var gaJsHost = (('https:' == document.location.protocol ) ? 'https://ssl.' : 'http://www.');
    document.write(unescape('%3Cscript src='' + gaJsHost + 'google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E'));
    </script>
    <script type='text/javascript'>
    try{
    var pageTracker = _gat._getTracker('UA-CODE-1');
    pageTracker._trackPageview();
    pageTracker._addTrans(
    '#$ID', // transaction ID - required
    'Company Name', // affiliation or store name
    '$Total.Nice', // total - required
    '6.00' // shipping
    );

    // 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
    pageTracker._addItem(
    '#$ID', // transaction ID - necessary to associate item with transaction
    '#$ID', // SKU/code - required
    '$Item.Object.Title', // product name
    '$Item.UnitPrice.Nice', // unit price - required
    '$Item.Quantity' // quantity - required
    );

    pageTracker._trackTrans(); //submits transaction to the Analytics servers
    } catch(err) {}

    </script>");
       }
    }

    Hopefully someone can point me in the right direction.

    Thanks
    -helenclarko

  • helenclarko
    Avatar
    Community Member
    25 Posts

    Re: SwipeStripe Google Anaytics Ecommerce Tracking Link to this post

    Hello all,

    I have achieved the effect I was after!

    I simply added the following to the top of the Order.ss file:

    I do suggest making a copy of the "/swipestripe/templates/Includes/Order.ss" file and putting it into your "themes/{themename}/templates/Includes" folder.

    <% control Items %>
    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol ) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    try{
    var pageTracker = _gat._getTracker("UA-CODE-HERE");
    pageTracker._trackPageview();
    pageTracker._addTrans(
       "#$Order.ID",          // transaction ID - required
       "NAME HERE",   // affiliation or store name
       "$Order.Total.Nice",   // total - required
       "",          // tax
       "",          // shipping
       "",             // city
       "",             // state or province
       ""          // country
       );

    // 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
    pageTracker._addItem(
       "#$Order.ID",          // transaction ID - necessary to associate item with transaction
       "$Title",            // SKU/code - required
       "$Object.Title",      // product name
       "",                // category or variation
       "$UnitPrice.Nice",       // unit price - required
       "$Quantity"          // quantity - required
       );

    pageTracker._trackTrans(); //submits transaction to the Analytics servers
    } catch(err) {}
    </script>
    <% end_control %>

    You will need to replace *NAME HERE* and *CODE HERE* of course.

    I decided not to use the Shipping or Tax, although both wouldn't be too hard to add.

    Thanks,
    -helenclarko

  • frankmullenger
    Avatar
    Forum Moderator
    51 Posts

    Re: SwipeStripe Google Anaytics Ecommerce Tracking Link to this post

    Glad you figured this out without too much trouble - just noticed the code you have below is in the Includes/Order.ss template that is also used in the email notifications, not sure if this will have a negative effect or not.

    If you wanted to run this code just on the page that the customer is returned to after payment you could just move your code to Layout/AccountPage_order.ss.

    You could also check successful payment if you like using $Order.Paid which will return true if order has been successfully paid for.

    Cheers,
    Frank

  • helenclarko
    Avatar
    Community Member
    25 Posts

    Re: SwipeStripe Google Anaytics Ecommerce Tracking Link to this post

    Hi Frank,

    Thanks for your reply.

    I will defiantly keep an eye on google analytics over the next week, but I believe google wont accept double of the same order.
    I realize using the script this way is not good practice and google may be receiving unnecessary data, but I will be keeping a close eye on it over the next week.

    I'm glad you mentioned the checking of successful payments, however the bulk of our orders are through invoice and can be left unpaid for weeks.
    Running the Google tracking code as it is at the moment allows me to capture all transactions.
    As a negative side effect the bulk of those orders will not have been paid on the day the order was made, leaving google analytics with false information.

    Thanks again for your time,
    -helenclarko

    855 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.