Guide: Real-Time Experiment Attribution for E-commerce Orders
Capture experiment and variation IDs on the thank you page and attach them directly to order metadata for SKU-level A/B test analysis.
| Author: | George F. Crewe |
This guide details how to capture Convert.com experiment data at the exact moment an order is generated and append it directly to the order object as metadata. This enables product-level reporting by linking specific SKUs to the A/B tests the customer was exposed to.
The Logic: Zero-Persistence Attribution
Instead of storing data in cookies or local storage, this method executes on the Order Confirmation/Thank You page. It reads the active experiment data from the browser's memory and pushes it immediately into your order attributes.
Step 1: Preparation of the E-commerce System
Before deploying the code, you must ensure your e-commerce platform (e.g., WooCommerce, Shopify, or a Custom SQL backend) is ready to receive and store these two specific data points for every order:
| Database Field | Format | Purpose |
| experiments | String / Array | Stores a list of all Experiment IDs (e.g., 100234, 100235) |
| variations | String / Array | Stores the specific Variations seen (e.g., 123, 456) |
Note: Check your database schema or plugin settings to ensure these custom "order meta" fields are whitelisted and can be saved during the checkout process.
Step 2: Capture and Append Data (Frontend)
Run the following script on the page where the order is finalized. It merges current and historical session data and appends it to your order object.
_conv_q = _conv_q || [];
_conv_q.push([function() {
// 1. Gather all active and historical experiment data
const currentExps = convert.currentData.experiences || {};
const historicalExps = convert.historicalData.experiences || {};
// Merge data, prioritizing current session data
const allExps = { ...historicalExps, ...currentExps };
const experimentIds = [];
const variationIds = [];
for (const expId in allExps) {
experimentIds.push(expId);
variationIds.push(allExps[expId].variation.id);
}
// 2. Append directly to your Order Object
// REPLACE 'window.myOrderObject' with your actual site's order variable
if (window.myOrderObject) {
window.myOrderObject.attributes = window.myOrderObject.attributes || {};
window.myOrderObject.attributes.experiments = experimentIds.join(', ');
window.myOrderObject.attributes.variations = variationIds.join(', ');
console.log("Convert.com data appended to order attributes.");
} else {
console.error("Order object not found. Ensure script runs after the order is initialized.");
}
}]);
Step 3: Reporting and SKU Analysis
Because these IDs are now saved as part of the order record in your database, you can run custom SQL queries or export CSVs to see exactly which experiments drove the sale of specific products.
Example Report Structure
Order ID: #5501
Product SKU: BLUE-WIDGET-01
Experiments: 12345, 67890
Variations: Original, Variant-B
Optional: Server-to-Server Tracking (REST API)
To keep Convert.com's internal dashboard in sync with your backend, you can have your server trigger a "Goal Hit" via the REST API using the data captured above.
Endpoint: https://data.convert.com/track/{PROJECT_ID}/{VISITOR_ID}
Payload Example
{
"events": [{
"type": "hitGoal",
"data": {
"expId": "captured_exp_id",
"varId": "captured_var_id",
"goalId": "your_revenue_goal_id"
}
}]
}
This structure also aligns well with related Convert support patterns around storing experiment data as Shopify order attributes and using purchase confirmation logic for downstream validation/reporting.