Connect Your PHP Backend to Agent & LLM Analytics

Overview

Use the REST API to connect your website from a PHP backend. Please contact us if you need help.

Step 1: Copy Your Access Token

Step 2: Start Tracking Visits

Paste in this function that makes an HTTP request to the REST API with detail about an incoming pageview request.

function track_visit_in_dark_visitors() {
    $curl = curl_init('https://api.darkvisitors.com/visits');
    curl_setopt_array($curl, [
        CURLOPT_POST => true,
        CURLOPT_HTTPHEADER => [
            'Authorization: Bearer ' . $YOUR_ACCESS_TOKEN,
            'Content-Type: application/json',
        ],
        CURLOPT_POSTFIELDS => json_encode([
            'request_path' => $_SERVER['REQUEST_URI'],
            'request_method' => $_SERVER['REQUEST_METHOD'],
            'request_headers' => getallheaders(),
        ], JSON_UNESCAPED_SLASHES),
        CURLOPT_NOSIGNAL => true,
        CURLOPT_TIMEOUT_MS => 50,
    ]);
    @curl_exec($curl);
    curl_close($curl);
}

In the endpoints where you serve your pages, call the function for each incoming pageview request. If you can, add this in middleware to track incoming requests to all pages from a single place.

track_visit_in_dark_visitors();

Tips

Step 3: Test Your Integration

If your website is correctly connected, you should see visits from the Dark Visitor agent in the realtime timeline within a few seconds.