How to track visitors e-commerce transactions

To do interesting targeting for personalizing your online business, you can track your visitors purchases with SiteGainer. This feature is meant for targeting your audience rather than tracking e-commerce data in your statistics.

Push

sitegainer.transaction.push({
	"orderID":124, 						// Required
	"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
			"value":600,  				// Product Value
			"category":"Candy" 			// Product Category
		},
		{
			"name":"Nike pants",		// Product name
			"value":400,				// Product Value
			"category":"Pants"			// Product Category
		}
	]
});

If you are not sure if SiteGainer 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
			"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);

Get

If you want to query your visitors 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;
}