You can run A/B tests server-side using PHP or any other backend language. When running experiments server-side, Matomo does not execute the experiment. It functions strictly as a measurement and reporting system. Unlike client-side (JavaScript) experiments, the PHP Experiments library does not synchronise configurations from Matomo UI.

⚠️
Changing traffic allocation, redirects, or schedules in the Matomo UI affects reporting only and does not change how the server-side experiment runs. If you adjust experiment settings in the UI, update the backend configuration.

For implementation details, read the developer guide on running experiments server-side.

Example of a server-side flow

  1. Create the experiment in Matomo (for reporting).
  2. Define experiment configuration in your backend:
    • Traffic allocation (for example, 50/50)
    • Variation identifiers
    • Redirect or rendering logic
    • Scheduling rules
  3. Use the PHP Experiments library to:
    • Assign a variation
    • Persist the assignment
    • Send the AbTesting::enter tracking call
  4. Render content or perform redirects based on the assigned variation:
$experiment = new Experiment('theExperimentName', $variations);
$activated = $experiment->getActivatedVariation();

if ($activated->getName() === 'A') {
    showOriginal();
} else {
    showVariant();
}

Server-side execution gives you full control over variation assignment and application logic. However, configuration and execution remain entirely within your backend. Matomo records the activated variation for reporting purposes only.

There is no supported method in the PHP Experiments library (or Matomo A/B Testing) to fetch experiment configuration from Matomo at runtime.

If you want Matomo to manage experiment configuration, targeting, traffic allocation, and execution automatically, use client-side mode instead.

Previous FAQ: Can I run an experiment only on a subset of my users?