How to run server-side A/B tests with Matomo
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.
For implementation details, read the developer guide on running experiments server-side.
Example of a server-side flow
- Create the experiment in Matomo (for reporting).
- Define experiment configuration in your backend:
- Traffic allocation (for example, 50/50)
- Variation identifiers
- Redirect or rendering logic
- Scheduling rules
- Use the PHP Experiments library to:
- Assign a variation
- Persist the assignment
- Send the
AbTesting::entertracking call
- 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.