Stinky Ink News

Google Analytics - Revenue Tracking for Actinic v8 and v9

We have developed this code over a period of a couple of weeks, and are donating it free to any Actinic users who would like to enable Google E-Commerce tracking within Analytics.
Once this code is enabled the information that you can mine from Analytics is absolutely top notch.

I am willing to give you this code for nothing – but (there is always a but!) I want a decent link back from your site to me, there – not too painful was it?.
To make it easy I have listed five different links here and would ask you to look at your nearest printer and choose the relevant code for that manufacturer, if your printer is not listed, use the last one:

Got a HP Printer? Copy and insert on your page:

  1. <a href="http://www.stinkyinkshop.co.uk/acatalog/hp__Hewlett_Packard__inkjet_cartridges.html">
  2. HP Inkjet Cartridges
  3. </a>

Got an Epson Printer? Copy and insert on your page:

  1. <a href="http://www.stinkyinkshop.co.uk/acatalog/Epson_Inkjet_Cartridges.html">
  2. Epson Ink Cartridges
  3. </a>

Got a Canon Printer? Copy and insert on your page:

  1. <a href="http://www.stinkyinkshop.co.uk/acatalog/Canon_Printers_Inkjet_Cartridges.html">
  2. Canon Ink Cartridges
  3. </a>

Got a Lexmark Printer? Copy and insert on your page:

  1. <a href="http://www.stinkyinkshop.co.uk/acatalog/Lexmark_Inkjet_Supplies.html">
  2. Lexmark Ink
  3. </a>

Not Sure? Copy and insert on your page:

  1. <a href="http://www.stinkyinkshop.co.uk">
  2. Printer Ink
  3. </a>

On to the code…

This guide assumes you have already installed analytics on the rest of your site. If not, the article How do I add tracking code to my website? should help you out.

Enable e-commerce tracking

Enable E-Commerce Tracking in Analytics

Install the scripts

Create a new file called roi.js and place the following code into it, make sure you adjust all the items in the OPTIONS section to match your own site.

  1.  
  2.  
  3.  
  4.   if($('.receipt_order_id')) {
  5.  
  6.  
  7.     // — OPTIONS —
  8.     var store_name           = 'YourStoreName';
  9.     var default_country_code = 'UK';
  10.     var default_category     = 'DefaultProductCategory';
  11.     var tracking_code        = 'UA-1234567-1';
  12.  
  13.  
  14.  
  15.  
  16.     var order_id = $('.receipt_order_id').text();
  17.     var total    = $('.receipt_total').text().replace(/[^0-9]/|>, '');
  18.     var tax      = $('.receipt_tax').text().replace(/[^0-9]/|>, '');
  19.     var shipping = $('.receipt_shipping').text().replace(/[^0-9]/|>, '');
  20.     var town     = $('.receipt_town').text();
  21.     var county   = $('.receipt_county').text();
  22.  
  23.     // if country code is set it will be picked up here
  24.     if($('.receipt_country_code').length > 0) {
  25.       var country_code = $('.receipt_country_code').text();
  26.     }
  27.     else {
  28.       var country_code = default_country_code;
  29.     }
  30.  
  31.  
  32.     var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
  33.  
  34.     jQuery.getScript(gaJsHost + "google-analytics.com/ga.js", function(){
  35.      
  36.       var pageTracker = _gat._getTracker(tracking_code);
  37.       pageTracker._setDomainName("none");
  38.       pageTracker._initData();
  39.      
  40.       pageTracker._addTrans(
  41.         order_id,                                   // Order ID
  42.         '',                                         // Affiliation
  43.         total,                                      // Total
  44.         tax,                                        // Tax
  45.         shipping,                                   // Shipping
  46.         town,                                       // City
  47.         county,                                     // State
  48.         country_code                                // Country
  49.       );
  50.      
  51.       $('.receipt_line').each(function(index){
  52.        
  53.         strip_pattern = /\s/;
  54.         reference = $('.receipt_reference', this).text().replace(strip_pattern, '');
  55.         name      = $('.receipt_name', this).text().replace(strip_pattern, '');
  56.         price     = $('.receipt_price', this).text().replace(/[^0-9]/|>, '');
  57.         quantity  = $('.receipt_quantity', this).text().replace(/[^0-9]/|>, '');
  58.  
  59.         // if .receipt_category is set it will be picked up here
  60.         if($('.receipt_category', this).length > 0) {
  61.           category = $('.receipt_category', this).text();
  62.         }
  63.         else {
  64.           category = default_category;
  65.         }
  66.  
  67.         pageTracker._addItem(
  68.           order_id,                                 // Order ID
  69.           reference,                                // SKU
  70.           name,                                     // Product Name
  71.           category,                                 // Category
  72.           price,                                    // Price
  73.           quantity                                  // Quantity
  74.         );
  75.       });
  76.  
  77.       pageTracker._trackTrans();
  78.       pageTracker._trackPageview();
  79.     });

Download jQuery from http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.2.1.min.js rename it to jquery.js

Place roi.js and jquery.js into your actinic ’site’ directory.

Set Actinic Page Type to ‘Receipt’

Set Actinic Page type to Receipt

Place the following changes into the section of ‘Receipt Page Layout’

  1.    <script language="javascript" type="text/javascript" src="jquery.js"></script>
  2.    <script language="javascript" type="text/javascript" src="roi.js"></script>

Wrap Actinic Variables with span tags.

The roi script needs a way of referencing each of the Actinic variables, we can do this by wrapping each of them with a span tag and giving them a class. This could easily work with another shopping cart system as long you have a way of accessing the receipt templates.

.receipt_order_id in ‘Receipt Order Number’ layout

The order number field in Actinic

  1.   <span class="receipt_order_id"><Actinic:Variable Name="TheOrderNumber"/></span>

.receipt_total in ‘Total Row’ layout

The total field in Actinic

  1.  <span class="receipt_total"><Actinic:Variable Name="Total"/></span>

.receipt_tax in ‘Tax 1 Row’ layout

The tax field in Actinic

  1.  <span class="receipt_tax"><Actinic:Variable Name="Tax1"/></span>

.receipt_shipping in ‘Shipping Charge Row’ layout

The shipping field in Actinic

  1.  <span class="receipt_shipping"><Actinic:Variable Name="Shipping"/></span>

.receipt_town & .receipt_county in ‘Receipt Invoice Address Details’ layout

The state field in Actinic

  1.  <span class="receipt_town"><Actinic:Variable Name="InvoiceAddress3"/></span>
  2.  <span class="receipt_county"><Actinic:Variable Name="InvoiceAddress4"/></span>

.receipt_line, .receipt_price in ‘Product Line Row’ layout

The .receipt_line class has to be added so the roi script can loop through each product row.

The product line table row in Actinic

  1. <tr class="receipt_line">
  2.    <td colspan="<Actinic:Variable Name="ProductColSpan"/>" class="cart">
  3.       <actinic:variable name="CartProductDetails" />
  4.    </td>
  5. <actinic:block if="%3cactinic%3avariable%20name%3d%22IsPriceInCart%22%20%2f%3e" >
  6.    <td align="right" class="cart">
  7.       <span class="receipt_price"><Actinic:Variable Name="Price"/></span>
  8.    </td>
  9.    <td align="right" class="cart">
  10.       <Actinic:Variable Name="Cost"/>
  11.    </td>
  12. </actinic:block>
  13. </tr>

.receipt_reference, .receipt_name, .receipt_quantity in ‘Cart Product Details’ layout

The product line table row in Actinic

  1. <span class="receipt_reference"><Actinic:Variable Name="ProdRef"/></span>
  2.  
  3. <span class="receipt_name"><Actinic:Variable Name="ProductNameOnline"/></span>
  4.  
  5. <span class="receipt_quantity"><Actinic:Variable Name="Quantity"/></span>

.receipt_category & .receipt_country_code

If you have a way of setting .receipt_category & .receipt_country_code values they will be automatically used instead of the default variables set in the roi script.

All Done!

Update your site and wait 24 hours for Google to start showing your stats.

5 Responses to “Google Analytics - Revenue Tracking for Actinic v8 and v9”

  1. Actinic Plugins - Stinky Ink Says:

    [...] Implementing Google E-Commerce in Analytics [...]

  2. Derek Says:

    I’m probably being very dumb here but I simply cannot get this to work.
    I have changed everything in the Options as you suggest but I cannot for the life of me figure out what my product category is or what my shop is called in Google Analytics. I’ve tried various combinations and none work. Just where does Google hide these things on the analytics site?
    All the customisation of the receipt page is OK and all the scripts are where they should be. I’m now stumped but I presume the problem lies with the incorrect options.
    Any advice would be gratefully received.

  3. Rob Says:

    You can set the name of your shop and category to anything you want.

    i.e.

    // — OPTIONS —
    store_name = ‘ExoticAndOriental’;
    default_country_code = ‘UK’;
    default_category = ‘Gifts’;
    tracking_code = ‘UA-1234567-1′;

  4. Derek Says:

    Thanks for the swift response.
    I’ve now changed the roi.js as you have suggested with Exotic as the shop & oriental gifts as the category so it’s finger crossed!

  5. Derek Says:

    Sorry guys but it’s just not working. I’ll give it another 24 hours but I do not expect there to be any difference. Obviously I have got something wrong if this is working on your Actinic store so apologies for not being able to configure what would be an excellent revenue tracker.

Leave a Reply

You must be logged in to post a comment.