Skip to main content
All CollectionsFunnelFlux features explainedMultivariate Tracking
Setting up Multivariate Testing (MVT) with PHP
Setting up Multivariate Testing (MVT) with PHP
Zeno avatar
Written by Zeno
Updated over 6 years ago

This page explains how to setup Multivariate Testing on your PHP pages.

If you want to know more about Multivariate Testing, then click here to read this first.


Prerequisites:

  1. Your page must be saved with the .php extension (to execute php code)

  2. It must be saved on the same server (hosting) as your FunnelFlux installation (but it can be another domain name). Thus you cannot use the PHP version with the managed version.*

  3. You must find the server path to your mvt.php file - it is located at your funnelflux root folder /tracking/mvt.php -- if you are using our Vultr install procedure then your path will be /usr/share/nginx/html/tracking/mvt.php

*For security reasons we can't enable remote calls to the PHP MVT processor from another server, and it would be slower than using JS anyway so is not worth it.


Implementing MVT

In your lander/offer page, you will add the following code above everything else:

<?php
include 'path/to/tracking/mvt.php';
Mvt::process();
?>

This mvt.php  file is on the same server as the tracker, as is your lander, so on the back-end it handles communicating all MVT variation information to the FunnelFlux tracker, for the current user session.

Remember, this doesn't have to be on the same domain/virtual host -- as long as its on the same server, you can modify the path/to/ to find this file. E.g. you might have 

include 'usr/share/nginx/trackerdomain.com/tracking/mvt.php';


Now, for adding variations...

Between the include and the Mvt::process(), you will then be able to create all your variations, such as:

<?php
include 'path/to/tracking/mvt.php';

Mvt::add('heading', 'Best Shoes Evaaarrr!');
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();
?>

Then, in your lander's HTML, anywhere you want to inject a variation, you can do it like this:

<?= Mvt::get('heading'); ?>

or

<?= Mvt::get('image'); ?>

etc...

'heading' and 'image' are just examples. You will use the keys that you have defined in your variations. The names for the keys are completely up to you.

By default, your visitors will ALWAYS see the same variations, no matter how many times they enter your funnel or refresh the page.

You can change this behavior by passing the following parameters to Mvt::process();

Mvt::process( [ 'randomness' => Mvt::RANDOMNESS_ALWAYS ] );

This will always show random variations. If your visitor refreshes the page, he will see new variations.

or

Mvt::process( [ 'randomness' => Mvt::RANDOMNESS_PER_ENTRANCE ] );

This will always show the same variations to your visitor when he refreshes the page. However, if he re-enters your funnel with your tracking link, new variations will be shown.

or

Mvt::process( [ 'randomness' => Mvt::RANDOMNESS_PER_UNIQUE_VISITOR ] ); 

This one is the default behavior. Your visitor will always see the same variations, no matter how many times they enter your funnel, or how many times they refresh the page.


Using PHP-based MVT with Javascript on-page tracking

Consider this situation: you use the PHP MVT script to generate variations in serve them in your page. However, users do not get to that page via a tracking link and instead are tracked by on-page Javascript.

In this situation, the mvt.php  will be included, generate and serve variations, but it will not be able to communicate what variations were served because the user session did not exist at the time -- the user was first tracked by the Javascript once the page loaded.

You could instead use Javascript to generate and output variations, but this may not be desired, since the PHP approach results in clean HTML output before the browser renders, giving no flickering of text or potential for Javascript issues.

Instead, what is required is for the Javascript to know what MVT variations were served by the PHP side and track these, logging them for the active user.

This can be accomplished by making a small adjustment to your PHP code

In your PHP code, alter the Mvt::process function to the following:

Mvt::process([
'randomness' => Mvt::RANDOMNESS_PER_UNIQUE_VISITOR,
'sendToJS' => true
]);

Here setting sendToJS  to true (it is false by default) will result in the PHP outputting some Javascript code, allowing the FunnelFlux on-page JS to then access the variations.

Note that this will overrule any variations the JS itself generates, the two should not be used in tandem to generate MVT variations.

If present, the JS code will automatically use the variation information that the PHP has generated and output on the page.


Important notes:

When using MVT for a domain different than your tracking domain (but hosted on the same server), since cookies cannot be transferred from one domain to another, you must pass two additional parameters to your lander's url:

  1. &flux_hid={hit-id}

  2. &flux_visitor={visitor-id}

This needs to be done only when the lander's domain is different than the tracker's domain.

Click here to learn how to set up MVT in Javascript on any page, any domain, and any hosting (even on your CDNs)

Did this answer your question?