Anura Docs

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 example below demonstrates 2 unique methods of how to use the response object to query for a "result" using the response ID or EXID.

JavaScript
<script type="text/javascript">
// method 1: 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);
// method 2: use a defined 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(){
                // continue with your custom result handler...
            };
            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.onreadystatechange = function() {
                // continue with your custom result handler...
            }
            http.send('POST' === method ? params.join('&'): '');
        }
    }
}
</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 rule sets returnability.
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.