API VERSION: 1.4.1

Installation

<script type="text/javascript">
  var AIDAX_CLIENT_KEY="YOUR_KEY",
cookie_enabled=function(){return document.cookie="tcax",-1!==document.cookie.indexOf("tcax")};window.ax=window.ax||function(){return window.ax.factory("track").apply(this,arguments)},window.ax.methods=["identify","goal","query","track","charge","update_transaction","delete_tags","increment","whois","ready"],window.ax._container=[],window.ax.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);return window.ax._container.unshift({method:e,args:t}),window.ax}};var cookie={set:function(e,t,r,i,n){var o=new Date,a="",c=typeof t,s="",d="";i=i||"/",r&&(o.setTime(o.getTime()+24*r*60*60*1e3),a="; expires="+o.toUTCString()),s="object"===c&&"undefined"!==c?encodeURIComponent(JSON.stringify({v:t})):encodeURIComponent(t),n&&(d="; secure"),document.cookie=e+"="+s+a+"; path="+i+d},get:function(e){for(var t=e+"=",r=document.cookie.split(";"),i="",n="",o={},a=0;a<r.length;a++){for(var c=r[a];" "==c.charAt(0);)c=c.substring(1,c.length);if(0===c.indexOf(t)){if(i=decodeURIComponent(c.substring(t.length,c.length)),n=i.substring(0,1),"{"==n)try{if(o=JSON.parse(i),"v"in o)return o.v}catch(s){return i}if("undefined"==i)return;return i}}return null},remove:function(e){this.set(e,"",-1)}};window.ax.is_unique=function(){return!cookie.get("aidax_unique")},window.ax.clear_ab=function(e){if(e){if("string"==typeof e&&""!==e){var t=cookie.get("aidax_ab");if(t){var r=JSON.parse(t);delete r[e],cookie.set("aidax_ab",JSON.stringify(r),3,"/")}}}else cookie.remove("aidax_ab")},window.ax.ab=function(e,t){if("string"==typeof e&&""===e&&"object"==typeof t&&Array.isArray(t)){var r,i=cookie.get("aidax_ab"),n={},o=function(e,t){return Math.floor(Math.random()*(t-e+1))+e},a=function(){var i,a,c=[],s=0,d=0;if(Array.isArray(t))r=t[Math.floor(Math.random()*t.length)];else{for(var u in t)t.hasOwnProperty(u)&&(c.push([u,[0===d?d:d+1,r[u]+d]]),d=r[u],s+=+r[u]);for(a=o(0,s),c.sort(function(e,t){return e[1]-t[1]}),i=0;i<c.length;i++)if(a>=c[i][1][0]&&a<=c[i][1][1]){r=c[i][0];break}}n[e]=r};if(i){if(n=JSON.parse(i),n[e])return n[e];a()}else a();return cookie.set("aidax_ab",JSON.stringify(n),30,"/"),r}throw"[AIDAX] Missing ab parameters."};for(var i=0;i<window.ax.methods.length;i++){var method=window.ax.methods[i];window.ax[method]=window.ax.factory(method)}var script=document.createElement("script");script.type="text/javascript",script.async=!0,script.src="//api.aidax.com.br/aidax.js";var firstScript=document.getElementsByTagName("script")[0];firstScript.parentNode.insertBefore(script,firstScript);
</script>

Just include the script at the end of the page body:

How to use

Tracking a custom event

The second parameter is optional

ax.track("EVENT TYPE", {
  property1: "value",
  property2: "value"
});

You can also use a concise format

ax("EVENT TYPE", {
  property1: "value",
  property2: "value"
});

Server-side

curl https://api.aidax.com.br/track?key=<key>&uid=<visitor uid>&origin=<optional session origin>&e=<event type>&p=<event properties in JSON format>

All successful requests return HTTP 204 No Content

Include the user identity on the tracking and additional info

ax.identify("VISITOR UID", {
  property1: "value",
  property2: "value"
});

Server-side

curl https://api.aidax.com.br/identify?key=<key>&previous_uid=<visitor uid>&uid=<visitor uid>&origin=<optional session origin>&p=<visitor attributes in JSON format>

To identify visitor profiles on the system, some attributes have a semantic context to AIDAX, see the table below for the name and format of these fields:

Key Format
country string
state string
city string
street string
neighborhood string
postal_code string
age integer
avatar String with a valid URL
birthday String in the format DD/MM/YYYY
first_name String
last_name String
friendly_name String
gender String containing M or F
phone String in the format (99)9999-9999 or (99)99999-9999
cellphone String in the format (99)9999-9999 or (99)99999-9999
social_id String containing the visitor national ID(Ex.: RG, CPF, SSN, etc.)
title String
description String
work String
website String with a valid URL
facebook String with a valid URL
twitter String with a valid URL
linkedin String with a valid URL
googleplus String with a valid URL

Increment a visitor attribute

ax.increment(ATTRIBUTE_NAME, VALUE, function(data) {
  // returns a object containing a value property with the current attribute value
});

Server-side

curl https://api.aidax.com.br/increment?key=<key>&uid=<visitor uid>&name=<attribute name>&value=<value to increment> -H "Content-Type: application/json"

Get useful info from the actual visitor

ax.query(TYPE, PARAMETERS, CALLBACK);

Server-side

curl https://api.aidax.com.br/query?key=<key>&uid=<visitor uid>&origin=<optional session origin>&type=<query type>&pa=<query parameters in JSON format> -H "Content-Type: application/json"

Get attributes of the actual visitor

ax.query("attributes", function(data) {
   // do something with the returned attributes
});

Find if the visitor belongs to some profile

ax.query("profile", {value: "Client with more than 20 transactions"}, function(data) {
    // returns true or false
});

Find if the actual visitor completed a goal

ax.query("goal", {value: "Site membership", persistent: true}, function(data) {
    // returns true or false depending on the goal status, or null if the visitor doesn't have the goal. The persistent parameter tells if the goal is by visitor or by session
});

Get info of a tracked event on the actual visitor

ax.query("event", {value: "pageview"}, function(data) {
    // returns an array containing the 10 last events of the type asked on the actual visitor
});

Get info on a visitor transaction

ax.query("transaction", {value: "127dc952-c2eb-47fb-bea8-595bb7435225"}, function(data) {
    // returns an object containing the info or null if it doesn't exist
});

Setting a goal status on the visitor journey

ax.goal("GOAL TITLE", true|false, true|false, {
  property1: "value",
  property2: "value"
});

Server-side

curl https://api.aidax.com.br/goal?key=<key>&uid=<visitor e-mail>&origin=<optional session origin>&gt=<goal title>&gs=<goal status, y or n>&gip=<persistent or transitory, y or n>&p=<goal properties in JSON format>

The second parameter is the goal status and the third tells if the goal is persistent(by visitor) or transitory(by session).

Know if the visit is unique

Returns true if it’s the first visitor access in 30 days

ax.is_unique();

Charge an ammount

ax.charge(AMMOUNT, *STATUS, *PROPERTIES, *CALLBACK);

// Example:

ax.charge(99); // status true
ax.charge(99, false, {
  property1: "foo",
  property2: "bar"
}, function(tid) {
    // do something with the transaction id
});

ax.current_transaction_id; // this property always contains the last transaction id from charge/update_transaction calls

Server-side

curl https://api.aidax.com.br/create/transaction?key=<key>&uid=visitor email>&origin=<optional session origin>&p=<transaction properties in JSON format>&v=<transaction ammount>&st=<transaction status, should be y or n>

Update a transaction

ax.update_transaction(TID, *VALUE, *STATUS, *PROPERTIES, *CALLBACK);

Server-side

curl https://api.aidax.com.br/update/transaction?key=<key>&uid=visitor email>&origin=<optional session origin>&tid=<transaction id>&p=<transaction properties in JSON format>&v=<transaction ammount>&st=<transaction status, should be y or n>

Adding tags to events, transactions, visitors and goals

You can add a special property “$tags” to any event/transaction/identify/goal execution. Think of it as a collection of unique strings(no more than 40 characters each) to better segment your data.

Examples

ax.track("tv_series", {
  $tags: ["Daredevil","House of Cards", "Breaking Bad"]
});

ax.identify({
  $tags: ["writer", "actor", "musician"]
});

ax.goal("posted content", true, true, {
  $tags: ["sports", "football"]
});

ax.charge(99, true, {
  $tags: ["beer", "apple", "meat"]
});

// Deleting tags

// if you are deleting tags from the current visitor:
ax.delete_tags("visitor", "writer");

// if you are deleting tags from visitor_goals, session_goals or transactions
ax.delete_tags(TYPE, ID, TAGS); // type should be one of "visitor_goal", "session_goal" or "transaction"

ax.delete_tags("visitor_goal", "posted content", ["sports","football"]);
ax.delete_tags("transaction", TRANSACTION_ID, "beer");

Deleting tags on the server-side

curl https://api.aidax.com.br/delete/tags?key=<key>&uid=visitor email>&origin=<optional session origin>&type=<visitor, session_goal, visitor_goal or transaction>&id=<visitor_goal/session_goal title, transaction id or skip it if you're deleting visitor tags>&tags=<a string or a JSON array of tags>

Track banner impressions/interactions

Add the attribute data-ax-content-view to the banner container and data-ax-content-click to the banner link

<div data-ax-content-view="BANNER TITLE" data-ax-content-cost="10" data-ax-content-cost-type="cpc">
    <img src="http://test.com/test.png">
    <a href="http://calltoaction.com" data-ax-content-click="BANNER TITLE">Click here</a>
</div>

Do a A/B test

// Optional: Clean your A/B test
ax.clear_ab("Subscription Button Color"); // or clean every test with ax.clear_ab()

var color = ax.ab("Subscription Button Color", ["red", "green", "blue"]);
// use the color variable with a random value selected(in this case, with 33% chance for each one);

// or configure different weights for each value
var color = ax.ab("Subscription Button Color", {"red": 25, "green": 60, "blue": 15});

Redirecting after a server-side capture

<a href="http://api.aidax.com.br/track?key=<KEY>&e=clicked_google_link&uid=john@doe.com&redir=http://www.google.com.br">Go to Google</a>

Obtaining data, metrics and funnels, adding profiles, hooks and actions(email, notification or webhook)

Obtain the visitor identity

ax.whois(function(identity) {
  // returns the current visitor uid
});

Chaining methods

ax("EVENT").goal("GOAL");

Execute code after AIDAX is fully loaded

ax.ready(function() {
  // your code
});

Executing AIDAX actions via special URL parameters

It’s possible to execute some simple actions by URL, in the example below, after AIDAX is fully loaded, it will identify the visitor with the ax_uid parameter and save a simple event called “External Event”:

http://www.test.com/?ax_uid=test@test.com&ax_event=External%20Event&ax_uid_nickname=JohnDoe

Valid parameters:

ax_uid: Identified the visitor with the parameter value
ax_uid_property_name=property_value: Adds to the current ax_uid call extra properties
ax_event: Saves a simple event with the parameter value
ax_event_property_name=property_value: Adds to the current ax_event call extra properties
ax_vgoal: Saves a persistent goal with status true and the parameter value as the name
ax_sgoal: Saves a transitory goal with status true and the parameter value as the name
ax_vgoal_property_name=property_value: Adds to the current ax_goal call extra properties
ax_sgoal_property_name=property_value: Adds to the current ax_sgoal call extra properties