How to Send Experiment and Variation Data to Salesforce Hidden Fields
Capture Convert experiment and variation data in Salesforce Web-to-Lead or Web-to-Case forms for attribution, segmentation, and reporting
| Author: | George F. Crewe |
IN THIS ARTICLE YOU WILL:
- Get an Overview
- Understand the Pre-requisite
- Setup Salesforce
- Integrate JavaScript
- Query Users by Variation
Overview
Passing experiment and variation data directly into Salesforce allows you to track how specific variations impact your downstream lead quality, sales velocity, and overall revenue.
You can achieve this by capturing the active variation details using the window.convert JavaScript object and injecting that string into a hidden field on your Salesforce Web-to-Lead (or Web-to-Case) form.
Here is the step-by-step guide to setting this up.
Prerequisite: Disable Data Anonymization
To access the actual names of your experiments and variations (instead of just their numeric IDs), you must disable Data Anonymization.
- Navigate to Project Settings > Configuration.
- Ensure Data Anonymization is turned off.
Part 1: Salesforce Setup
1. Create a Custom Field in Salesforce:
Set up the destination for your A/B test data.
- Log in to Salesforce and go to Setup.
- Navigate to Object Manager and select Lead (or the object your form submits to).
- Click Fields & Relationships and then New.
- Choose Text (or Text Area if you run multiple concurrent experiments and need more character space).
- Name it Convert Experiences and complete the setup. Make a note of the newly created API name.
2. Generate your Salesforce Form HTML:
Create the Web-to-Lead or Web-to-Case snippet.
- In Salesforce Setup, search for Web-to-Lead (or Web-to-Case).
- Click Create Web-to-Lead Form.
- Add your standard fields (Name, Email, etc.) and include your new Convert Experiences field.
- Click Generate and copy the provided HTML.
3. Convert the field into a Hidden Field:
Hide it from the user interface.
Paste the generated HTML into your website's code editor. Locate the input field for Convert Experiences. It will look something like this:
<input id="00N50000001abcD" maxlength="255" name="00N50000001abcD" size="20" type="text" />
Change type="text" to type="hidden".
⚠️ Important:
Copy the id value of this field, as you will need it for the JavaScript integration
Part 2: JavaScript Integration
Once the form is on your page, you need to read the active experiment data and push it into the hidden field right before the user submits the form. The window.convert.currentData.experiments object contains exactly what the visitor is currently bucketed into.
Add the following JavaScript snippet to your webpage. Place it below both your tracking code and your Salesforce form HTML.
<script>
document.addEventListener("DOMContentLoaded", function() {
// 1. REPLACE THIS with the actual HTML ID of your Salesforce hidden field
var salesforceHiddenFieldId = "00N50000001abcD";
// 2. Check if the tracking object is fully loaded and has current data
if (typeof window.convert !== 'undefined' && window.convert.currentData && window.convert.currentData.experiments) {
var activeExperiments = window.convert.currentData.experiments;
var experimentDataArray = [];
// Loop through the active experiences for this visitor
for (var expId in activeExperiments) {
if (activeExperiments.hasOwnProperty(expId)) {
// Fetch the human-readable experiment and variation names
var expName = activeExperiments[expId].experiment_name || "Unknown Experiment";
var varName = activeExperiments[expId].variation_name || "Unknown Variation";
// Format and add to our array
experimentDataArray.push(expName + " : " + varName);
}
}
// 3. Inject the combined string into the Salesforce hidden field
if (experimentDataArray.length > 0) {
var convertDataString = experimentDataArray.join(" | ");
var hiddenField = document.getElementById(salesforceHiddenFieldId);
if (hiddenField) {
hiddenField.value = convertDataString;
}
}
}
});
</script>
How this script works:
- Validation: It checks if the tracking variables have fired and data is present.
- Iteration: It loops through window.convert.currentData.experiments to fetch the human-readable experiment_name and variation_name.
- Concatenation: If the user is part of multiple experiments, it joins them together separated by a pipe (|). Example output: Checkout Flow Test : Variation B | Button Color Test : Blue Variant.
- Injection: It finds the Salesforce input field by its HTML ID and updates the value attribute when the page loads. When the visitor clicks submit, the data passes directly to your Lead record.
Note for Dynamic Forms: If your form is loaded dynamically via JavaScript (such as in a popup modal or a Single Page Application), the DOMContentLoaded event might fire before the form exists on the page. In those scenarios, bind this logic to your form's "on open" or "on render" event instead of the initial page load.
Part 3: Querying Users by Variation in Salesforce
Because the script injects the data as a formatted text string, you can easily locate users who saw a specific variation by using standard Salesforce Text Filters.
Here are the two most common ways to query this data:
Method A: Create a Custom List View
List views are best for quickly browsing Leads or Cases associated with an experiment directly from your primary tabs.
1. Create a New List View:
Navigate to the Leads tab (or your chosen object), click the Gear Icon in the top right, and select New. Name your list view (e.g., "Leads - Checkout Variation B").
2. Add a Filter:
In the Filters panel on the right, click Add Filter.
3. Define the Match Criteria:
Set the Field to Convert Experiences, the Operator to contains, and the Value to your target variation name (e.g., Variation B).
4. Save and Apply:
Click Done and then Save. The list will update to show only users bucketed into that specific variation.
Method B: Build a Salesforce Report
Reports are best if you want to calculate conversion rates, total pipeline value, or aggregate the data visually.
1. Start a New Report:
Navigate to the Reports tab and click New Report. Select your object type (e.g., Leads) and click Start Report.
2. Navigate to Filters:
Click the Filters tab on the left-hand menu.
3. Filter by the Custom Field:
Search for Convert Experiences in the Add Filter box. Change the operator to contains and enter the exact variation name (e.g., Variation B or Checkout Flow Test : Variation B).
4. Run the Report:
Click Apply, and then Save & Run to view the aggregated metrics for users in that specific test group.