AI traffic
Install on any other PHP site
The PHP core, for any PHP site without a dedicated package.
The core is what the WordPress, Laravel and OpenCart packages are built on. Use it directly on any other PHP site (Symfony, CodeIgniter, your own code).
Requirements: PHP 8.1 or newer, ext-json. It uses ext-curl when installed. No other dependencies.
Install
-
Create a key in Survelium โ Brand settings โ Integrations โ Create key. It is shown once.
-
Until the package is on Packagist, add the repository to
composer.json:"repositories": [{ "type": "vcs", "url": "https://github.com/survelium/agent-analytics-php" }] -
Install it:
composer require survelium/agent-analytics-php:^0.1@dev -
Start it once, as early as possible in every request (in your front controller or through
auto_prepend_file):use Survelium\AgentAnalytics\AgentAnalytics; use Survelium\AgentAnalytics\Config; AgentAnalytics::start(new Config(apiKey: 'svk_...'));
That is all. At the end of the request the page view is recorded (GET/HEAD, not XHR or prefetch), and every 50
items or 60 seconds the buffer is sent. Under PHP-FPM or LiteSpeed the response goes out to the visitor first.
Before you leave it running, check
- Behind Cloudflare or a load balancer, set
ipHeader, or crawlers cannot be verified. - A page cache in front of PHP hides the crawlers reading cached pages. Exclude AI crawler user agents from it (the list).
- The storage folder is writable by the web server user. If it is not, nothing is recorded (and nothing breaks).
Options
new Config(
apiKey: 'svk_...',
trackReferrals: true, // false = AI crawlers only
denyPaths: ['/admin'], // paths neither reported nor counted
ipHeader: 'HTTP_CF_CONNECTING_IP', // only behind a proxy that always sets it
storagePath: '/var/www/storage/survelium', // default: the system temp folder
);
When something goes wrong
- Survelium unreachable: data stays buffered, retries back off from 30 seconds to an hour.
- Key revoked: pauses an hour. Plan without AI traffic: pauses six hours. Data is kept.
- Storage folder not writable: does nothing. The integration never breaks your site.