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 Anura Script response object functions using an optional callback function.

Optional Callback Function

JavaScript
<script type="text/javascript">
// FOR DEMONSTRATION PURPOSES ONLY!
function optionalCallbackFunction() {
    // if the Anura object has been declared
    if (!!Anura) {
        // declare your back-end server response handler function
        function backendServerResponseHandler() {
            // redirect the user to the returned destination url
            window.location = this.responseText;
        }
        // send the response ID to your back-end server for result-based redirection
        var http = new XMLHttpRequest();
        http.addEventListener('load', backendServerResponseHandler);
        http.open('POST', 'https://anura.io/example-redirect');
        http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
        http.send('responseId='+Anura.getAnura().getId());
    }
}
</script>

The JavaScript example shown above demonstrates a basic callback that will send the returned response ID to a back-end server using the getId() response object function. The back-end server in this example will be querying the Anura result endpoint and returning a destination URL to which the visitor will be redirected.

Querying the result endpoint from server-side, using a response ID, or EXID, is the most secure way to actively use Anura, as there is little or no exposure of sensitive result data on the client-side.

Response Object Functions

Function Description Note
getId() Returns the Anura response ID used to query the result from Anura's servers.
getExId() Returns the self-declared external tracking ID used to query the result from Anura's servers.
hasResult() Returns true when the result value is available.
queryResult(callback) A function used to query the result value from Anura's servers within the context of your JavaScript code. The queryResult() function should be executed from your response callback and may only be used once per session. The response ID, or EXID, is automatically referenced from response data and does not need to be declared. The callback parameter is used to execute a declared callback function, which may also be passed anonymously. Response object functions are passed to the callback as the first argument.
isGood() Returns true when the result value is "good". Requires full response or prior use of the queryResult() function.
isWarning() Returns true when the result value is "warn". Requires full response or prior use of the queryResult() function.
isBad() Returns true when the result value is "bad". Requires full response or prior use of the queryResult() function.
getResult() Returns the result value string. Requires full response or prior use of the queryResult() function.
getRuleSets() Returns an array of broken rule sets. Return rule sets must be enabled. Requires full response or prior use of the queryResult() function.
getInvalidTrafficType() Returns the type of invalid traffic: "SIVT" or "GIVT". Return invalid traffic type must be enabled. Requires full response or prior use of the queryResult() function.
isMobile() Returns true when a mobile device has been detected Requires full response or prior use of the queryResult() function.
getMobile() Returns the numeric value of mobile device detection: 0 or 1. Requires full response or prior use of the queryResult() function.
hasAdBlocker() Returns true when an ad blocker has been detected. Ad blocker detection must be enabled. Requires full response or prior use of the queryResult() function.
getAdBlocker() Returns the numeric value of ad blocker detection: 0 or 1. Ad blocker detection must be enabled. Requires full response or prior use of the queryResult() function.
getError() Returns an error message if one has been declared.
getResponseObject() Returns an object of available response data.
getResultObject() Returns an object of available result data. Requires prior use of the queryResult() function.
getObject() Returns a combined object of available response and result data.

If you do not specify the variable parameter when making a script request, "Anura" will be declared by default.

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.

Refer to our callback functions documentation for more information about what data values are available and when.