CleanTalk Anti-Spam "frontend_data" API method description

This method collects the site visitor's data in background. Stored data is identified by the event_token value.

  1. Collect web-form data.
  2. Send data JSON via a POST request to https://moderate.cleantalk.org/api3.0/fronted_data
  3. Parse the response and use received event_token later in check_bot, check_newuser or check_message methods.

 

The method should be used via our script https://moderate.cleantalk.org/ct-bot-detector-wrapper.js which should be included in the site's code

<script src="https://moderate.cleantalk.org/ct-bot-detector-wrapper.js"></script>​

 

Request

Data JSON Example

{
    "js_event": "js event name",
    "page_url": "visitor viewed page url",
    "event_token": "previously_received_token",
    "data": {},
    "method_name": "frontend_data"
}

Data Processing

Necessary information about the data processing.

Parameter Explanation
HTTP Method POST
Data format JSON
URL https://moderate.cleantalk.org/api3.0/frontend_data

Required Parameters

These parameters are required.

Parameter Explanation
method_name Must be "frontend_data".
js_event The name of the JS event. Max length is 32 symbols.
page_url The URL of visitor's viewed page.
data The object with visitor's activity on the site.

Additional parameters

These parameters will improve filtration.

Parameter Explanation
event_token The param is used to link all collected frontend data of the visitor with the request. This data is collected by the special script https://moderate.cleantalk.org/ct-bot-detector-wrapper.js that should be added to the page layout.

Response

Response example

The server's response is independent of the platform.

{
    "event_token": "5...5",
    "data": {
        "operation_status": "SUCCESS"
    },
    "error_no": 0,
    "error_message": ""
}

Response Explanation

Key Explanation
event_token Token of stored data. You may use it again to store data changes in same token.
error_no Zero if success or integer code of error.
error_message Empty if success or short description of error.
data JSON-string with additional data. It will have "operation_status": "SUCCESS" in case of success

Code Examples

Using Wget

CLI example

wget -O- --post-data='{"js_event":"submit","page_url":"http://wp-clean.talk/different-link-to-stuff/","data":{"agent":"bot_detector_1.1.19","timestamp":1721209824},"method_name":"frontend_data"}' https://moderate.cleantalk.org/api3.0/frontend_data

Using PHP

PHP backend

We would like to accentuate the point that you don't need to integrate this method on the server side and all interactions should be on frontend, however if there's a requirement to integrate the method server-side here's a simple example of how to make a call.

                                
<?php use Cleantalk\CleantalkRequest; class FrontendData { protected $_apiUrl = 'https://moderate.cleantalk.org/api3.0/frontend_data'; private $_authKey = 'your_auth_key'; function run() { $data = [ 'auth_key' => $this->_authKey, 'method_name' => 'frontend_data', 'page_url' => 'https://wordpress.demo1.cleantalk.me/contact-form-7/', 'js_event' => 'submit', 'sender_ip' => '1.1.1.1', 'data' => json_decode('{ "agent": "bot_detector_3.1.22", "REFFERRER": "https://wordpress.demo1.cleantalk.me/contact-form-7/", "has_input_focused": true, "headless": false, "page_hits": 3, "cookies_enabled": true, "REFFERRER_PREVIOUS": "https://wordpress.demo1.cleantalk.me/", "screen_info": { "visibleHeight": 922, "fullWidth": 886, "visibleWidth": 886, "fullHeight": 3938 }, "mouse_moved": true, "user_agent": "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0", "timestamp": "2024-07-29 15:29:39", "has_scrolled": true, "typo": [ { "fieldType": "INPUT", "isUseBuffer": false, "isAutocomplete": false, "speedDelta": 62, "label": "Your name*\n", "countOfKey": 3, "firstKeyTimestamp": "2024-07-29 15:29:34", "isAutocompleteExist": false, "lastDelta": 21, "lastKeyTimestamp": "2024-07-29 15:29:34", "fieldName": "your-name" }, { "lastDelta": 0, "fieldName": "apbct__email_id__search_form_48184", "lastKeyTimestamp": "1970-01-01 05:00:00", "isAutocompleteExist": false, "countOfKey": 0, "firstKeyTimestamp": "1970-01-01 05:00:00", "speedDelta": 0, "label": "48184", "isAutocomplete": false, "isUseBuffer": false, "fieldType": "INPUT" } ], "pointer_data": [ [ 267, 703, 105 ], [ 784, 130, 12890 ] ], "has_key_up": true }', true), ]; // Convert to JSON $data = json_encode($data); echo $data . "\n\n"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->_apiUrl); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); $result = curl_exec($ch); curl_close($ch); } } (new FrontendData())->getAction()->run();

Using HTML

The usual way to integrate the frontend_data method is to include our script https://moderate.cleantalk.org/ct-bot-detector-wrapper.js on your site.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://moderate.cleantalk.org/ct-bot-detector-wrapper.js"></script>
</head>
<body>
<form method="post" action="check_bot.php">
    <label for="search_field">What do you search?</label>
    <input type="text" name="search_field" id="search_field" /> <br />
    <input type="submit" />
</form>
</body>
</html>

 

Was this information helpful?

It would also be interesting

Copied to clipboard