Skip to content

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.

  1. The page must have a .php extension so the server runs the PHP.
  2. The page must be hosted on the same server as FunnelFlux. It can use a different domain name.
  3. You need the server path to mvt.php. It is in the FunnelFlux root at tracking/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.

Add this above everything else on the lander or offer page:

<?php
include '/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.

Define your variations between the include and Mvt::process():

<?php
include '/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="">

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 ] );

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.

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.