NAV Navbar
Logo

Installation

<script type="text/javascript" id="script">
  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("event").apply(this,arguments)},window.ax.methods=["on","once","user","query","session","event","delete_tags","increment","whois","ready","toggle_debug"],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

ax.event({
  id: "8e6a8ee2-13ea-400d-8b25-882177efa026", // pass this parameter if you have the event id to update it
  name: "EVENT NAME", // obligatory
  properties: {
    property1: "foo",
    property2: "bar"
  }, // custom properties
  callback: function(id) {
    // this returns the event ID so you can update it later.
  }
});

You can also use a concise format

ax({
  id: "8e6a8ee2-13ea-400d-8b25-882177efa026", // pass this parameter if you have the event id to update it
  name: "EVENT NAME", // obligatory
  properties: {
    property1: "foo",
    property2: "bar"
  }, // custom properties
  callback: function(id) {
    // this returns the event ID so you can update it later.
  }
});

Server-side

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

All successful requests return HTTP 204 No Content

Add session properties

ax.session({
  property1: "value",
  property2: "value"
});

Server-side

curl https://api.aidax.com.br/session?key=<key>&uid=<user id>&origin=<optional session origin>&p=<session properties in JSON format>

Include the user identity on the tracking and additional info

ax.user({
  id: "USER ID",
  properties: {
    property1: "value",
    property2: "value"
  },
  migrate: true //optional parameter to migrate old user data in this session to the new user. Default is true
});

Server-side

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

Increment a user/session property

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

Server-side

curl https://api.aidax.com.br/increment?key=<key>&uid=<user id>&type=<user or session>&name=<property name>&value=<value to increment> -H "Content-Type: application/json"

Get info from the actual user

ax.query({
  type: "type", // user, session, profile, event or metric
  value: "id", //required for profile and event
  callback: function(data) {
     // ...
  }
});

Server-side

curl https://api.aidax.com.br/query?key=<key>&uid=<user id>&origin=<optional session origin>&type=<query type>&value=<query value if needed> -H "Content-Type: application/json"

Get information of the actual user

ax.query({
  type: "user",
  callback: function(data) {
    // do something with the returned user information
  }
});

Get session properties of the actual session

ax.query({
  type: "session",
  callback: function(data) {
     // do something with the returned properties
  }
});

Find if the user belongs to some profile

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

Get info of a tracked event on the actual user

ax.query({
  type: "event",
  value: "656bfd14-6f71-4367-814b-c45c368f5771",
  callback: function(data) {
    // do something with the event data
  }
});

Get a metric result by using a request key previously saved in AIDAX Metadash

ax.query({
  type: "metric",
  value: "8c5e7adb-882b-4283-8188-a9288626df24", // request key
  callback: function(data) {
    // do something with the metric result
  }
});

Know if the visit is unique

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

ax.is_unique();

Adding tags to events and users

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

Examples

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

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

// Deleting tags

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

// if you are deleting tags from a event
ax.delete_tags("event", ID, TAGS);

Deleting tags on the server-side

curl https://api.aidax.com.br/delete/tags?key=<key>&uid=user id>&origin=<optional session origin>&type=<user or event>&id=<event id or skip it if you are deleting user tags>&tags=<a string or a JSON array of tags>

Intercept 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>

Then listen to two banner event to get its data and do whatever you want


// for impression
ax.once("banner:BANNER TITLE", function(data, element) {
  // data returns { cost: NUMBER, cost_type: TYPE, clicked: true/false }, element is the banner HTML container
});

// for banner click
ax.once("banner_clicked:BANNER TITLE", function(data, element) {
  // data returns { cost: NUMBER, cost_type: TYPE, clicked: true/false }, element is the banner HTML container
});

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/event?key=<KEY>&name=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)

We developed a nice tool called Metadash for extracting data, metrics and funnels from your domain and custom workflow creation, alongside the API calls to reuse on any programming language. Check it out!

Obtain the user identity

ax.whois(function(identity) {
  // returns the current user id
});

Chaining methods

ax({
  name: "EVENT"
}).user({
  properties: {
    subscribed: true
  }
});

Execute code after AIDAX is fully loaded

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

Custom properties standards

When you track a event, session property or user information you can add many properties, but they should obey this standard:

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 user 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: Identifies the user 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_sp_property_name=property_value: Adds to the current ax_session call extra properties

Server-side API example

Python

import http.client

conn = http.client.HTTPConnection("api.aidax.com.br")

payload = '{"name": "EVENT_NAME","uid": "johndoe@example.com","key": "AIDAX_CLIENT_KEY"}'

headers = {
    'content-type': "application/json",
}

conn.request("POST", "/event", payload, headers)

Java

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");

RequestBody body = RequestBody.create(mediaType, "{
\"name\": \"EVENT_NAME\",
\"key\": \"AIDAX_CLIENT_KEY\",
\"uid\": \"johndoe@example.com\"}");

Request request = new Request.Builder()
  .url("http://api.aidax.com.br/event")
  .post(body)
  .addHeader("content-type", "application/json")
  .build();

Response response = client.newCall(request).execute();

PHP

<?php

$request = new HttpRequest();
$request->setUrl('http://api.aidax.com.br/event');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'content-type' => 'application/json'
));

$request->setBody('{
 "name": "EVENT_NAME",
 "uid": "johndoe@example.com",
 "key": "AIDAX_CLIENT_KEY"
}');

try {
  $response = $request->send();
  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

?>

Node.js

var request = require("request");

var options = { method: 'POST',
  url: 'http://api.aidax.com.br/event',
  headers: {
   'content-type': 'application/json'
  },
  body: {
    "name": "EVENT_NAME",
    "uid": "johndoe@example.com",
    "key": "AIDAX_CLIENT_KEY"
  },
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

Perl

use HTTP::Request::Common;
use LWP::UserAgent;

print LWP::UserAgent->new
->request(POST http://api.aidax.com.br/event,
Content_Type => application/json,
Content => {"name": "EVENT_NAME","uid": "johndoe@example.com","key": "AIDAX_CLIENT_KEY"})
->decoded_content;

Ruby

require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("http://api.aidax.com.br/event")

header = {'Content-Type': 'application/json'}
user = {name: "EVENT_NAME",uid: "johndoe@example.com",key: "AIDAX_CLIENT_KEY"}

# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri, header)
request.body = user.to_json

# Send the request
response = http.request(request)

Go

func main() {
    url := "http://api.aidax.com.br/event"
    fmt.Println("URL:>", url)

    var jsonStr = []byte(`{"name": "EVENT_NAME","uid": "johndoe@example.com","key": "AIDAX_CLIENT_KEY"}`)
    req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
}

Elixir

header = [{"Accept", "application/json"},
              {"Content-Type", "application/json"}
             ]    
body = "{\"name\": \"EVENT_NAME\",\"key\": \"AIDAX_CLIENT_KEY\",\"uid\": \"johndoe@example.com\"}"
response = HTTPotion.post("http://api.aidax.com.br/event", [body: body, headers: header])

C#

using (var client = new HttpClient())
{
    HttpResponseMessage response = new HttpResponseMessage();
    try
    {
        response = await client.PostAsync("http://api.aidax.com.br/event", new StringContent(
           new JavaScriptSerializer().Serialize(new {
             name = "EVENT_NAME",
             uid = "johndoe@example.com",
             key = "AIDAX_CLIENT_KEY"
           }), Encoding.UTF8, "application/json"));
    }
    catch (Exception ex)
    {
        throw ex
    }
    return response;
 }

Rust

let mut map = HashMap::new();
map.insert("name", "EVENT_NAME");
map.insert("uid", "johndoe@example.com");
map.insert("key", "AIDAX_CLIENT_KEY");

let client = reqwest::Client::new()?;
let res = client.post("http://api.aidax.com.br/example")?
    .json(&map)?
    .send()?;