# Visii Analytics script

Many users are used with integrating Google Analytics in their applications. That is why, for ease of use we also provide a va.js script that can be inserted into your page and a track function to call whenever you have analytics data you think Visii could use.

!function(){var a=window.visii=window.visii||[];a.invoked?window.console&&console.error&&console.error("Visii analytics snippet was added twice."):(a.invoked=!0,a.track=function(){var e=Array.prototype.slice.call(arguments);return a.push(e),a},a.load=function(e){var o=document.createElement("script");o.type="text/javascript",o.async=!0;var i="https://cdn.visii.com/visii.com/va"+("function"==typeof window.fetch?"":"p")+".js";o.src=i;var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(o,t),a.config=e},a.load({
  organisation:"<organisation>",
  dataset:"<dataset>",
  token:"<token>",
  userCookie:"<user-cookie>"
}),a.track("Page Loaded", {page_type:"other"}))}();

Replace in the above script your dataset details:

Field Type Required Value Description
organisation String yes The organisation name
dataset String yes The dataset name
token String yes The dataset API token
user-cookie String no The cookie name that contains an user identifier

# Usage

To send analytics to Visii, just call the track function:

Field Type Required Value Description
event-name String yes The event name
data Object no Details associated with the event
window.visii.track("event-name", dataObject);

The track function is using internally the /track endpoint described in the Analytics API.

See below a few examples of using the track function. The dataObject has a predefined structure for Standard Events and a more flexible structure for Custom Events.

va.track("Product Clicked", {
	product_id: "735583523"
});
va.track("Order Completed", {
	currency: "USD",
	tax: 10,
	total_price: 103,
	order_id: "oid293483",
	shipping: 5,
	items: [
		{
			price: 22,
			sku: "p29473",
			quantity: 1
		},
		{
			price: 33,
			sku: "p22473",
			quantity: 2
		}
	]
});
Last Updated: 5/1/2020, 1:55:31 AM