- Help Center
- General
-
General
-
Getting Started
-
Configuration
- Targeting
- Split URL
- Product Testing
- Full Stack
- Experiment Management
- CSP Configuration
- Experiment Execution
- Reports
- Exit Popups
- GTM Integration
- Troubleshooting
- Performance Optimization
- Event-Triggered Changes
- Holdout Groups
- Split URL Pages
- URL Parameters
- DataLayer
- Menu Configurations
- Traffic Exclusion
- Experiment Scheduling
- Dynamic Element Changes
- Price Targeting
- Experience Scheduling
- Privacy
- Hash Changes
- Async Tracking
- Selective Installation
- CSS Selectors
- Vue.js Integration
- Page Content
- Multipage Split URL
- Organic Traffic
- Visual Editor
- Server-Side Testing
- Traffic Bucketing
- GDPR Warnings
- Statistical Confidence
- Browser Privacy
- Query Parameters
- Embedded Videos
- Tracking Code Execution
- Simultaneous Experiments
- Tags
- Deployments
- Disable Testing
- Locations
- Programmatic Bucketting
- Query Parameter Handling
- Convert Library
- Variation Previews
- Experiment Editing
- Opt-Out Script
- Data Reset
- Body Hiding
- Visit-Specific Variations
- Variation Styling
- Preview Issues
- Variation Editing
- Full-Site Testing
- Blinking Variations
- Cross-Domain Cookies
- Regex Support
- Conversion Tracking
- SPA Testing
- Project Setup
- Cross-Domain Tracking
- Geo-Targeting
- Analytics Tools
- Campaign Tags
- Previewing
- IDs
- Query String Targeting
- Bounce Rate Goals
- Bot Filtering
- Query String Variables
- Custom Audiences
- Redirects
- Baseline
- Tracking Code Location
- Secure Cookies
- AngularJS
- Cloudflare
- Code Installation
-
Shopify
-
Track Goals
- Form Tracking
- Cookie Management
- iFrame Click Tracking
- Performance Optimization
- Revenue Tracking
- Interaction Goals
- Form Submissions
- Advanced Goals
- Lazy Loading
- Multi-Conversions
- URL Parameters
- Bounce Rate Goals
- DataLayer Integration
- Scroll Depth
- Social Interactions
- Page Views
- Marketo Forms
- Feature Analysis
- AJAX Forms
- Revenue Tracking via GTM
- Order Outliers
- Cumulative Revenue
- Goal Templates
- Adding Revenue Goals
- JS-Based Goals
- Goal Basics
- Google Analytics Goals
- Social Sharing
- Dynamic Goals
- Typeform Integration
-
Target Visitors
- Geolocation
- Interaction Goals
- Goal-Based Targeting
- Weather Targeting
- Cookie-Based Targeting
- Page Visits
- Audience Management
- Audience Segmentation
- Experiment Targeting
- Advanced Audience Creation
- Audience Templates
- Audience Creation
- Data Layer Integration
- Manual Activation
- JavaScript Conditions
- Device Targeting
- Language Targeting
- IP-Based Exclusion
- Visitor Management
- Page Tagging
- Cookies
-
Troubleshooting
- Google Warnings
- Visual Editor
- HTTPS Content
- Logs
- Support Options
- Bootstrap
- Cookie Blocking
- Change History
- Mobile Debugging
- AdWords
- Bot Exclusion
- Domain Issues
- Cloudflare Issues
- Monitoring
- Cloaking Penalties
- Goal Editor Issues
- Variations
- Snippet Performance
- Changes Not Saved
- Blocked Visual Editor
- Goal Testing
- Visual Editor Browsing
- Experiment Issues
- Installation Verification
- Data Leak Prevention
- Usage Limits
- Experiment Previews
- GA4 Revenue
- Chrome Debugger Logs
- SPA Errors
- Checkout JSON Error
-
Analyze Results
-
Integrations
- Google Analytics
- Cookie Consent Platforms
- Microsoft Clarity
- Plausible
- Marketo
- HubSpot
- Tealium
- Smartlook
- Klaviyo
- Salesforce CRM
- FullStory
- Snowplow Analytics
- Webflow
- GA4 Roles
- Amplitude
- Segment
- React
- BigCommerce
- WooCommerce
- Active Campaign
- Google Tag Manager
- Mixpanel
- Zapier
- Inspectlet
- Crazy Egg
- LanderApp
- Unbounce
- Instapage
- Drupal
- PrestaShop
- Magento
- Roistat
- Piano Analytics
- Heap Analytics
- Kissmetrics
- Mouseflow
- Adobe Analytics
- Clicky
-
Account Management
-
Developers
-
What's New
-
Common Questions
Server Side Testing with PHP
THIS ARTICLE WILL HELP YOU:
Overview
This is a sample of PHP code with the purpose to enable AB testing server side. With this code, you should be able to AB test changes on a very rudimentary way, on the server side, before the page has been served to the browser. As we are planning to release a PHP and Python SDKs in the near future.
There is a Convert Server Side PHP example available to you.
Sample Code
This code will require that you create a normal Convert AB experiment, and do a small change on it, to be able to save it.
As a suggestion, go into the Visual Editor and under your Variation Menu > Custom Javascript enter the following:
// This is the variation.
With that change, you should be able to save it, and use that experiment to collect data, and analyze it using its report.
Make sure you enter a condition that wont be able to be triggered in the test. You could just use a JS Condition with the value false to never trigger it another way.
To start you will have to find out the Project Number and Experiment id. You need this to include it in the code.
This is way more efficient than getting them via an API, as this would delay the processing of the code. However, if this is what you need, we have an API available for you to use.
This code has been fully verified to be deployed with relative few effort.
<?php
// Set the project id and experiment id
Define('PROJECTNUMBERID','10014852_10015867');
$experimentid = '100122624';
$sel_variation = 0;
$unknownvseisitor = false;
$currentTime = time();
$defaultCookieData = "vi:1*sc:0*cs:$currentTime*fs:$currentTime*pv:0";
// echo 'Cookie Exists:'.(isset($_COOKIE['_conv_v'])).'<br/>';
if (!isset($_COOKIE['_conv_v']))
{
echo 'Convert Cookie named _conv_v is not set!';
$unknownvisitor = true;
// Get the variations from the Convert server
$projectdataURL = 'https://cdn-3.convertexperiments.com/JSON/'.PROJECTNUMBERID.'.json';
$output = file_get_contents($projectdataURL,0,null,null);
//echo $output;
// if request went well, extract the variations from the returned data and select the variation randomly
if ($output) {
$projectdata = json_decode($output,true);
$experiments = $projectdata['experiments'];
$ourexperiment = $experiments[$experimentid];
$variations = $ourexperiment['vars_sort'];
// Use array_rand to select the variation randomly
if (sizeof($variations) > 0) {
$sel_var_key = array_rand($variations, 1);
$sel_variation = $variations[$sel_var_key];
// echo "Variation Key Selected:'$sel_var_key\n";
// echo "Variation Selected:'$variations[$sel_var_key]\n";
}
}
$cookieData = $defaultCookieData;
}
else
{
// echo 'Convert Cookie is set! Lets read if we have <br />';
// Check if user is bucketed in experiment
$convertcookie = (string)$_COOKIE['_conv_v'];
// echo 'Convertcookie:'.$convertcookie.'<br/>';
// Extracts the experiment from the cookie
$sub = substr($convertcookie, strpos($convertcookie,'100122624.{v.')+strlen('100122624.{v.'),strlen($convertcookie));
$extractedvariation = substr($sub,0,strpos($sub,'-g.{'));
// echo 'Extracted Variation:'.$extractedvariation;
if ($extractedvariation){
$sel_variation = $extractedvariation;
}
$cookieData = $_COOKIE[$convertCookieName];
}
// Set the Convert Cookie to overcome the ITP cookie browser limits
setrawcookie("_conv_v",$cookieData, $currentTime + 15768000, "/", "touristcoin.com");
// Set the Selected Variation on the cookie
$sptestcookiecontent = $experimentid.':'.$sel_variation;
setrawcookie('_conv_sptest',$sptestcookiecontent, $currentTime + 300, "/", "touristcoin.com");
//Insert the Convert tracking code in case you have not done so.
echo '<!-- begin Convert Experiences code--><script type="text/javascript" src="//cdn-3.convertexperiments.com/js/'.PROJECTNUMBERID.'.js"></script><!-- end Convert Experiences code -->';
// Execute changes depending on the variation
echo 'Variation:'.$sel_variation.'<br>';
if ($sel_variation == '1001176189'){
// Insert code for corresponding variation
echo 'First Variation Selected<br>';
}
elseif ($sel_variation == "1001176190"){
// Insert code for corresponding variation
echo 'Second Variation Selected<br>';
}
?>
If you have any questions, let us know through the support channels available to you.