Setting up Multivariate Testing (MVT) with PHP
This page explains how to set up multivariate testing on PHP pages. For what multivariate testing is, see What is multivariate testing.
Prerequisites
Section titled “Prerequisites”- The page must have a
.phpextension so the server runs the PHP. - The page must be hosted on the same server as FunnelFlux. It can use a different domain name.
- You need the server path to
mvt.php. It is in the FunnelFlux root attracking/mvt.php. On a server set up with the FunnelFlux Ubuntu installer, the full path is/usr/share/nginx/html/tracking/mvt.php.
The PHP MVT script can’t be called remotely from another server. If your page is hosted elsewhere, use JavaScript MVT instead.
Include the script
Section titled “Include the script”Add this above everything else on the lander or offer page:
<?phpinclude '/usr/share/nginx/html/tracking/mvt.php';Mvt::process();?>Change the path if your FunnelFlux files are somewhere else. Because the script runs on the same server, it can look up the current visitor’s session and record which variations they were shown.
Add variations
Section titled “Add variations”Define your variations between the include and Mvt::process():
<?phpinclude '/usr/share/nginx/html/tracking/mvt.php';
Mvt::add('heading', 'Best Shoes Ever!');Mvt::add('heading', '#1 Product');
Mvt::add('image', 'image01.jpg');Mvt::add('image', 'image02.jpg');Mvt::add('image', 'image03.jpg');
Mvt::add('cta', 'Buy NOW!');Mvt::add('cta', 'Get one NOW!');Mvt::add('cta', 'Purchase a Pair NOW!');
Mvt::add('background', '#ff0000');Mvt::add('background', '#008000');
Mvt::process();?>The keys (heading, image, cta, background) are examples; name them however you like.
Print a variation anywhere in the page HTML with Mvt::get():
<h1><?= Mvt::get('heading'); ?></h1><img src="<?= Mvt::get('image'); ?>" alt="">Choose how often variations change
Section titled “Choose how often variations change”Pass a randomness option to Mvt::process():
| Option | Behaviour |
|---|---|
Mvt::RANDOMNESS_PER_UNIQUE_VISITOR |
Default. The visitor sees the same variations on every entrance and every refresh. |
Mvt::RANDOMNESS_PER_ENTRANCE |
The variations stay the same on refresh, but a new set is picked each time the visitor enters through the tracking link. |
Mvt::RANDOMNESS_ALWAYS |
A new random set on every page load, including refreshes. |
For example:
Mvt::process( [ 'randomness' => Mvt::RANDOMNESS_PER_ENTRANCE ] );PHP MVT with on-page JavaScript tracking
Section titled “PHP MVT with on-page JavaScript tracking”Sometimes the visitor reaches the page without a tracking link, and the FunnelFlux on-page JavaScript creates the session after the page loads.
mvt.php still picks and serves variations, but it can’t record them, because the session doesn’t exist yet when PHP runs.
You could generate the variations in JavaScript instead. PHP is often the better fit, because the HTML is complete before the browser renders it: text doesn’t flicker and you don’t depend on JavaScript to print the variations.
To let the JavaScript record what PHP served, set sendToJS:
Mvt::process([ 'randomness' => Mvt::RANDOMNESS_PER_UNIQUE_VISITOR, 'sendToJS' => true]);sendToJS is off by default.
When it is on, PHP outputs a small script that the FunnelFlux on-page JavaScript reads, and the JavaScript logs those variations for the visitor.
Don’t also generate variations in JavaScript on the same page. If the PHP output is present, the JavaScript uses it and ignores variations it would have generated itself.
Different domain, same server
Section titled “Different domain, same server”Cookies are not shared across domains. If the lander uses a different domain from your tracking domain, add these two parameters to the lander URL in FunnelFlux:
&flux_hid={hit-id}&flux_visitor={visitor-id}Add them only when the lander domain differs from the tracking domain.

