NAV Navbar
Logo

Installation

<script type="text/javascript" id="script">
  var AIDAX_CLIENT_KEY="YOUR_KEY";!function(e,t){var a=["user","query","session","event","delete_tags","whois","ready","toggle_debug"],r=(e.ax=e.ax||function(){return e.ax.factory("event").apply(this,arguments)})._container=[],n=e.ax.factory=function(t){return function(){var a=Array.prototype.slice.call(arguments);return r.unshift({method:t,args:a}),e.ax}};e.ax.is_unique=function(){return-1===t.cookie.indexOf("ax_unique=")};for(var i=0;i<a.length;i++){var o=a[i];e.ax[o]=n(o)}var c=t.createElement("script");c.type="text/javascript",c.async=!0,c.src="//api.aidax.com.br/aidax.js";var s=t.getElementsByTagName("script")[0];s.parentNode.insertBefore(c,s)}(window,document);
</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(event_id) {
    // this function executes after the event is saved.
  }
});

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(event_id) {
    // this function executes after the event is saved
  }
});

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>&converted=<optional, y or n>

All successful requests return HTTP 204 No Content

Add session properties

ax.session({
  property1: "value",
  property2: "value"
},function(){
  // this function executes after the session is saved
  });

Server-side

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

Include the user identity on the tracking and additional info

ax.user({
  id: "USER ID",
  properties: {
    property1: "value",
    property2: "value"
  },
  callback: function() {
    // this function executes after the user is saved
  },
  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>

Send server-side batches

curl https://api.aidax.com.br/batch?key=<key>&items=<JSON array of objects> -H "Content-Type: application/json"

// Where the objects inside the items parameter should follow the standard:

{
  "type": "should be event, user or session",
  "uid": "the user ID",
  "fields": {
    "p": {
      // object containing the event/user/session properties
    },
    "tags": [], // if the type supports tags]
    "converted": false // if the type supports conversion,
    "name": "event name",
    "id": "event id"
  }
}

Add property values only if they are new

If you want to make sure some properties are saved only if they don’t have a value yet, add a suffix $once to the name of the property(works for users, sessions and events)

ax.session({
  "loggedin$once": true
}); // updates the field only if it doesn't exist yet

Add property values only if they are higher or lower

ax.session({
  "counter$higher": 100
}); // updates the field only if counter is lower than the new value or it doesn't exist yet

ax.session({
  "temperature$lower": 5
}); // updates the field only if temperature is higher than the new value or it doesn't exist yet

Increment property values

ax.session({
  "counter$plus": 100
}); // Add 100 to the counter field

ax.session({
  "temperature$minus": 5
}); // subtract 5 of the temperature field

Add conflict-resolution logic

You can add a conflict resolution to event, session, user and batch calls. Whenever data would be overwritten(everytime, unless it is a new event), your logic will apply and in case it matches a conflict, you can also interfere on the data that will be merged.

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>&conflict=<special JSON array>

The conflict parameter can be added to the usual data captures and it should follow this standard:

// conflict JSON array, this example don't let the event overwrite if the actual age property is greater than the new age property OR the gender is male
[{
  "if": [{ // this is an array of logical filters
    "field": "properties.age" // besides accepting fields, it also can interact with the existing record with $old_doc and new data with $new_doc, if missing, $old_doc is default
    "comparator": "gt", // can be 'gt' (Greater Than), 'ge' (Greater or Equal), 'lt' (Less Than), 'le' (Less or Equal), 'ne' (Not Equal) or 'eq' (Equals)
    "value": "$new_doc.properties.age" // if you want to specify a field instead of a raw value, use the prefix $old_doc or $new_doc
  },{
    "field": "properties.gender",
    "comparator": "eq",
    "or": true // the or parameter can be used beginning at the second item of the *if* array
    "value": "M"
    }],
  "then": { // this is optional, should be a object containing data to be merged whenever there is a conflict and it matches your conditions
    "properties": {
      "status": "old_enough"
    }
  }
}]

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>

Marking the session or event as converted

Examples

ax.event({
  name: "signup_success",
  properties: {
    $converted: true
  }
});

ax.session({
  $converted: true
});

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()?;