Anura Docs

Script Integration

Anura Script is our preferred method as it collects more information on the visitor, thereby finding more fraud. Anura Script is robust, enabling it to capture and identify more fraud in client campaigns. We encourage all integrators to use Anura Script, wherever possible, to provide the most insight possible to your campaigns.

Script Integration - Request

Placing the following JavaScript snippet at the end of your page's <head> tag will allow Anura to obtain data about, and generate a result value for each visitor to your site.

JavaScript
<script type="text/javascript">
(function(){
    var anura = document.createElement('script');
    if ('object' === typeof anura) {
        var request = {
            instance: yourAssignedInstanceId,
            // source: 'optionalSourceTrackingId',
            // campaign: 'optionalCampaignTrackingId',
            // exid: 'optionalSingleUseExternalId',
            // additional: 'optionalAdditionalData',
            // variable: 'optionalResponseObjectVariable',
            // callback: 'optionalCallbackFunction'
        };
        var params = [];
        for (var x in request) params.push(x+'='+encodeURIComponent(request[x]));
        params.push(Math.floor(1E12*Math.random()+1));
        anura.type = 'text/javascript';
        anura.async = true;
        anura.src = 'https://script.anura.io/request.js?'+params.join('&');
        var script = document.getElementsByTagName('script')[0];
        script.parentNode.insertBefore(anura, script);
    }
})();
</script>

You also have the option of using a "one line" piece of JavaScript, as some platforms and integrations do not allow the use of full scripts. Please ensure the replacement of example parameter values with their actual values when utilizing the one line script.

JavaScript
<script type="text/javascript" src="https://script.anura.io/request.js?instance={INSTANCE_ID}&source={MACRO}&campaign={MACRO}&{CACHEBUSTER}"></script>

Parameter string values should always be URL encoded when using a "one line" integration.

Parameters

Required Type Description Note
instance integer Your instance ID.
Optional Type Description Note
source string A variable, declared by you, to identify "source" traffic within Anura's dashboard interface.
campaign string A subset variable of "source," declared by you, to identify "campaign" traffic within Anura's dashboard interface.
exid string A unique single use external ID, declared by you, that is used to query a specific result from Anura's servers.
additional string An array of Additional Data declared as a JSON encoded string. Read more about using Additional Data.
variable string The variable name of the JavaScript object that response data will be assigned to. This variable contains the response ID, in addition to other data, that will allow you to make real-time decisions.
callback string The name of the JavaScript function to be executed once the response is received. Response data will be passed to the callback function as the first argument.
cachebuster * integer A random multi-digit integer added to the end of the query string to prevent caching of Anura's Script. * The cachebuster value should only be used for "one line" script implimentations.

Source, campaign, exid, variable, and callback parameters are limited to a maximum of 128 characters.

Source and campaign parameters may not equal the following values: "all sources", "all campaigns", "&", "*", "?", "%".

Variable and callback parameters are allowed to start with: "$", "_", or "a-z" characters, followed by "a-z" and "0-9" characters.

Security

Anura Script offers an optional "domain locking" feature to protect against unauthorized use of your instance ID. Once enabled, only requests from client authorized domains will be accepted for processing. Please talk to support about enabling the script domain locking feature.

Script Integration - Response

If you want to be proactive and use response data to make decisions within the context of your page, you will need to access the "response" object. The JavaScript examples below demonstrates 2 unique methods of how to use the response object to query for a "result" using the response ID or EXID.

Preferred Response Method - optionalCallbackFunction()

JavaScript
<script type="text/javascript">
// use a defined optional callback function
function optionalCallbackFunction(response) {
    // if the response ID or EXID is available
    if (response.getId() || response.getExId()) {
        // get the result from Anura servers...
        getResult(response);
    }
}
// get the result from Anura servers using the response object
function getResult(response) {
    var method = 'POST';
    var params = ['instance=yourAssignedInstanceId'];
    if (response.getId()) params.push('id='+encodeURIComponent(response.getId()));
    if (response.getExId()) params.push('exid='+encodeURIComponent(response.getExId()));
    var url = 'https://script.anura.io/result.json'+('GET' === method ? '?'+params.join('&'): '');
    // internet explorer 8-9
    if (window.XDomainRequest) {
        var http = new XDomainRequest();
        if (http) {
            http.open(method, document.location.protocol === 'https:' ? url: url.replace('https:', 'http:'));
            http.onprogress = function(){}
            http.ontimeout = function(){}
            http.onerror = function(){}
            http.onload = function(){anuraResultHandler(this);}
            setTimeout(function(){http.send('POST' === method ? params.join('&'): '');}, 0);
        }
    // other browsers
    } else if (window.XMLHttpRequest) {
        var http = new XMLHttpRequest();
        if (http && 'withCredentials' in http) {
            http.open(method, url, true);
            if ('POST' === method) http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            http.onload = function(){anuraResultHandler(this);}
            http.send('POST' === method ? params.join('&'): '');
        }
    }
}
// handle the Anura result
function anuraResultHandler(http) {
    // continue with your custom result handler...
}
</script>

Alternative Response Method - setInterval()

JavaScript
<script type="text/javascript">
// use setInterval to check for the response object every 50 milliseconds
var interval = setInterval(function(){
    if ('object' === typeof optionalResponseObjectVariable) {
        // declare the response object when available
        var response = optionalResponseObjectVariable.getAnura();
        // if the response ID or EXID is available
        if (response.getId() || response.getExId()) {
            // clear defined intervals!
            clearInterval(interval);
            // get the result from Anura servers...
            getResult(response);
        }
    }
}, 50);
// get the result from Anura servers using the response object
function getResult(response) {
    var method = 'POST';
    var params = ['instance=yourAssignedInstanceId'];
    if (response.getId()) params.push('id='+encodeURIComponent(response.getId()));
    if (response.getExId()) params.push('exid='+encodeURIComponent(response.getExId()));
    var url = 'https://script.anura.io/result.json'+('GET' === method ? '?'+params.join('&'): '');
    // internet explorer 8-9
    if (window.XDomainRequest) {
        var http = new XDomainRequest();
        if (http) {
            http.open(method, document.location.protocol === 'https:' ? url: url.replace('https:', 'http:'));
            http.onprogress = function(){}
            http.ontimeout = function(){}
            http.onerror = function(){}
            http.onload = function(){anuraResultHandler(this);}
            setTimeout(function(){http.send('POST' === method ? params.join('&'): '');}, 0);
        }
    // other browsers
    } else if (window.XMLHttpRequest) {
        var http = new XMLHttpRequest();
        if (http && 'withCredentials' in http) {
            http.open(method, url, true);
            if ('POST' === method) http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            http.onload = function(){anuraResultHandler(this);}
            http.send('POST' === method ? params.join('&'): '');
        }
    }
}
// handle the Anura result
function anuraResultHandler(http) {
    // continue with your custom result handler...
}
</script>

Response Object Functions

Function Description Note
getId() Returns the response ID used to query the result from Anura's servers.
getExId() Returns the self declared unique external tracking ID used to query the result from Anura's servers.
getResult() Returns the result value. Requires full response.
getMobile() Returns whether a mobile device was detected. Requires full response.
getAdBlocker() Returns whether an ad blocker was detected. Requires full response and ad blocker detection.
getRuleSets() Returns an array of detected broken rule sets. Requires full response and return rule sets.
getInvalidTrafficType() Returns the type of invalid traffic: "SIVT" or "GIVT". Requires full response and return invalid traffic type.
getError() Returns an error message if one has been declared.
getObject() Returns an object of all data listed above.

If you do not specify a response variable when making a script request, "optionalResponseObjectVariable" will default to "Anura".

A "full response" is available, which provides result data immediately and without the need to connect to the result endpoint. Talk to support about enabling or disabling the full response feature.

Ad blocker detection may be enabled or disabled per instance. Talk to support about whether having the ad blocker detection feature turned on/off is right for you.

Script Integration - Result

Script result values may be obtained by calling the endpoint directly.

Method URL Note
GET, POST https://script.anura.io/result.json HTTPS recommended

Example Request

PHP
<?php
// define parameters
$params = array();
$params["instance"] = yourAssignedInstanceId;
$params["id"] = "yourResponseId";
// setup and initialize curl
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://script.anura.io/result.json?".http_build_query($params));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// perform the request
$response = curl_exec($curl);
// close the curl connection
curl_close($curl);
// continue with your custom result handler...
?>

Parameters

Required Type Description Note
instance integer Your instance ID.
id string The response ID that is used to request the result from Anura's servers.
Optional Type Description Note
exid string The unique external tracking ID, declared by you, that is used to query the result from Anura's servers. Send "exid" instead of "id" when utilizing the exid parameter.

While we strive to have results available within milliseconds, in worst case scenarios, some results may take longer. Therefore, it is okay to perform multiple queries for a response ID that is not found.

Response ID results will be available for 15 minutes and are removed immediately after a successfully query.

Example Response

{
    "result": "bad",
    "mobile": 1,
    "adblocker": 0,
    "rule_sets": [
        "UE",
        "SP"
    ],
    "invalid_traffic_type": "SIVT"
}

Result Values

Result Description
good The visitor has passed our tests and appears to be trustworthy.
warn There are aspects about the visitor that raise concerns. However, we can not say for certain they are bad. It is your decision how to interpret this value.
bad The visitor has failed our testing and should be considered untrustworthy.

Please refer to our script result definitions documentation for more information on these values.

Rule Set Values

Result Description
DI Data Integrity
UE User Environment
DC Data Center
TO Traffic Origin
IP IP Integrity
SP Spoofing
WC Web Crawler

The "rule_sets" array requires "return rule sets" to be enabled. Talk to support about enabling or disabling the return rule sets feature.

The "invalid_traffic_type" string requires "return invalid traffic type" to be enabled. Talk to support about enabling or disabling the return invalid traffic type feature.

Please refer to our rule set definitions documentation for more information on these values.