API

Enable tracker for a website, send events for analysis

Integration

Incorporate the tracker code into products you want to track. End-to-end metrics allow you to see all customer actions and to link them together in a single chain. Insert this line into the product <header> code:

<script src="//tracker.airgrow.com/api.js"></script>

Before closing the HTML body tag, enter the following code:

<script>
        window.airgrow = new AirgrowTracker("your api code")
</script>

Domain activation

After the first events reach the tracker, in Settings you will see the domains from which these events originated. Enable those from which events are to be collected.

User events

It is frequently necessary to track unique events that cannot be tracked automatically. To do this, insert the following code.

window.airgrow.event("custom event name")

In addition to the event itself, data may also be conveyed - for example, an event parameter. These data will be highlighted in the event list next to the event name, but they will not affect the distinct character of the event name.

window.airgrow.event("custom event name", "custom data")

Sending events from the server

To send events from the server, include the PHP library:

composer require airgrow/php-api

Sending an event for user registration:

require_once __DIR__ . "/vendor/autoload.php";
\Airgrow\Airgrow::setApiKey(KEY, PRODUCT_ID);
\Airgrow\Airgrow::event("registration", ["session" => $_COOKIE["airgrow"]]);

You can find the product ID and key on your dashboard. To associate an action with a user before they have registered you can use an Airgrow token session, which is generated when a meter is linked to a product.

Custom events

Some events perform special functions. These can be used to change user data. They can be sent using both JS and the API.

EventEffect
api:registrationSets the date and time of user registration as not current.
api:paymentRecords a payment made by a user in the database and subsequently allows analysis of payments received. The payment amount must be sent by way of the "data" value.
api:subscriptionSubscribes the user. If this event is sent, user ARPU and MRR can be counted. To cancel a subscription, specify 0 or the amount of the new subscription as the "data" field.

Payment tracking

require_once("airgrow.php");
$airgrow = new Airgrow("your product id", "your key");
$airgrow->event("payment", [
    "user" => "user@email.com",
    "amount" => 300,
    "currency" => "USD"
]);

After registration you can use the "user" field for user identification: ID, email, or username.

Creating cohorts

There are three different ways of creating cohorts:

  1. manually via theUsers interface
  2. setting up an automatic rule for creating cohorts
  3. via programming code when a given event occurs. Several comma-delimited cohorts may be created at once.

window.airgrow.engage({"cohort": "top-100,price-usd"})

The new cohorts will soon appear in the interface.

A/B testing

A/B testing may be used to test various content within the product. You can create experiments using programming or via the interface. For example, the following code will create an experiment that breaks down traffic into three equal parts, and displays the different product values for each third of your customers.

window.airgrow.experiment("experiment-name", ["v1", "v2", "v3"]).then(function(cohort){
    switch (cohort){
        case "v1":
            document.getElementById("price").innerHTML = "$30";
            break;
        case "v2":
            document.getElementById("price").innerHTML = "$40";
            break;
        case "v3":
            document.getElementById("price").innerHTML = "$30";
            break;
    }
})

A weighting coefficient may be used to set a nonuniform distribution. The following code will produce the variant v1 for 50% of customers, v2 for 25%, and v3 for the remaining 25%:

window.airgrow.experiment("experiment-name", {"v1": 2, "v2": 1, "v3": 1})

Traffic break-down percentages may also be specified directly:

window.airgrow.experiment("experiment-name", {"v1": "35%", "v2": "12%", "v3": "53%"})

Not all 100% of the total percentage necessarily has to be set. For example, a value of 10% may be set for one variant. This will establish the selected cohort in 10% of cases, while in the remaining 90% the traffic will not be marked.

Traffic break-down can be set only once. Thereafter you can simply query with what cohort the given visitor is already marked using the experiment name. This query works across all products. In other words, if a user has been marked on the website, this marking may be checked in all your products that are linked to the tracker.

window.airgrow.experiment("experiment-name").then(function(cohort){
    switch (cohort){
        case "v1":
            document.getElementById("price-below").innerHTML = "$30";
            break;
        case "v2":
            document.getElementById("price-below").innerHTML = "$40";
            break;
        case "v3":
            document.getElementById("price-below").innerHTML = "$30";
            break;
    }
})

Integration
Domain activation
User events
Sending events from the server
Custom events
Payment tracking
Creating cohorts
A/B testing