How to track visitors e-commerce transactions

If you wish to see transactional data (Total revenue, Avg. revenue/goal, Avg. revenue/visitor) in your statistics you can add the function below on your 'Thank you' / Order confirmation page. You will need to populate the values and also handle currency conversion before the function is fired. 

sitegainer.transaction.push({
    "orderID":"124",                        // Required (String) (Only for targeting, will not be sent to statistics)
    "orderValue":1000	                    // Required (Number) (Use . for decimal numbers Ex: 100.50)
});

The transaction goal will automatically appear in statistics once data for this is registered.

 

Important!

  • Make sure that the order values you're about to push has loaded and are in the correct format (string) before the push executes.
  • We will only use orderID and orderValue to calculate the statistics, the other values are optional and can only be used for audience or other tracking purposes.
  • We do not handle currencies so you need to convert all to the same currency for the calculations to be correct.

 

If you also wish use this function to target a specific audience you have the option to set all or some of the other values as seen in the code example below. We will however as mentioned not show this further information in the statistics.

 

Push

sitegainer.transaction.push({
    "orderID":"124",                        // Required (Only for targeting, will not be sent to statistics)
    "orderValue":"1000",                    // Required
    "currency":"EUR",                   // Optional - String  (Only for targeting, will not be sent to statistics)
    "paymentMethod":"CreditCard",       // Optional - String  (Only for targeting, will not be sent to statistics)
    "shipping":30,                      // Optional - Numerical Value (Only for targeting, will not be sent to statistics)
    "items":                            // Optional - Array (Only for targeting, will not be sent to statistics)
    [   
        {
            "name":"Jelly Beans",       // Product name (Only for targeting, will not be sent to statistics)
            "value":600,                // Product Value (Only for targeting, will not be sent to statistics)
            "category":"Candy"          // Product Category (Only for targeting, will not be sent to statistics)
        },
        {
            "name":"Nike pants",        // Product name (Only for targeting, will not be sent to statistics)
            "value":400,                // Product Value (Only for targeting, will not be sent to statistics)
            "category":"Pants"          // Product Category (Only for targeting, will not be sent to statistics)
        }
    ]
});

 

If you are not sure if Symplify is loaded when you run this. Use this setup to make sure:

var sg_trans_int = setInterval(function() {
    if(typeof sitegainer !== 'undefined' && sitegainer.transaction !== 'undefined') {
        sitegainer.transaction.push({
            "orderID":"124",                        // Required  (Only for targeting, will not be sent to statistics)
            "orderValue":"1000",                    // Required
            "currency":"EUR",                   // Optional - String  (Only for targeting, will not be sent to statistics)
            "paymentMethod":"CreditCard",       // Optional - String  (Only for targeting, will not be sent to statistics)
            "shipping":30,                      // Optional - Numerical Value (Only for targeting, will not be sent to statistics)
        });
        clearInterval(sg_trans_int);
    }
},500);

 

Result

mceclip0.png

If everything is set up correctly you will get a Transaction block on your project result page. This will besides Conversions also present Total revenue and Avg. Order Value.

 

Get

If you want to query your visitor's transactions, you can do it like this

sitegainer.transaction.get({
    'query':'itemsQuantity',                    // itemsQuantity ( total quantity of items after filter ), ordersQuantity ( total quantity of orders after filter ) ,totalSum ( total value of orders after filter )
    'filter':{
        'startDate':'2017-10-15',               // Can also contain time
        'endDate':'2017-12-15',                 // Can also contain time
        'itemName': {
            'contains':'Jelly Beans 2'
        },
        'itemCategory': {
            'contains':'Pants'  
        },
        'currency': {
            'exact_match':'EUR' 
        },
        'paymentMethod': {
            'exact_match':'CreditCard'
        }
    }
});

// Match types: "exact_match" / "contains" / "regex". Regex should be formatted like this: 'regex': /ni.*e/

 

For using this as a custom audience, follow this example:

if(sitegainer.transaction.get({
        'query':'totalSum',                 // Get the total sum of the ordervalue
        'filter':{          
            'itemName':{        
                'contains':'Jelly Beans'    // For product which name contains Jelly Beans
            }
        }
    }) > 200) { // If number is larger than 2
    // Visitor has purchased more than 2 Jelly Bean
    return true;
}

 

 

 

Was this article helpful?
0 out of 0 found this helpful