This guide explains how to retrieve user group assignment and test prices for Shopify function (cart transform) price tests using ABConvert, so you can implement price display logic in custom themes or apps.
Step 1: determine user’s test group
ABConvert stores the user’s test group assignment in localStorage.
How to Access It:
const testGroups = JSON.parse(localStorage.getItem("abconvert-experiment-to-group-index"));
Example:
// Output:
{ "68f8a6e48ba7cd3fb1348314":1 }
In this example, the user is in Group Index 1 for the experiment with ID 68f8a6e48ba7cd3fb1348314.
Group index reference
Group index reference
Group Index | Description |
0 | Original group |
1 | Variant 1 |
2 | Variant 2 |
3 | Variant 3 |
4 | Variant 4 |
Note: When testing in “preview” mode, the group index can appear in string format:
{ "68f8a6e48ba7cd3fb1348314": "0" }
{ "68f8a6e48ba7cd3fb1348314": "1" }
2. Access test prices
Price test data is available via a global JavaScript object:
window.abconvertPriceCartTransformTestDict
⚠️ This object is only available when there’s an active test running.
Example Structure:
window.abconvertPriceCartTransformTestDict = {
"7420248031297": {
experimentId: "68f8a6e48ba7cd3fb1348314",
variantToGroupIndexToPrice: {
"41685506818113": {
"0": { price: "699.95", compareAtPrice: null },
"1": { price: "799.95" }
},
...
},
... }
}Each key in the object represents a product ID (7420248031297), and under it, you’ll find pricing per variant ID (41685506818113) and group index.
3. How to use this for customization
Here’s how to dynamically display the correct price in your theme or app:
Example:
const testGroups = JSON.parse(localStorage.getItem("abconvert-experiment-to-group-index"));
const experimentId = "68f8a6e48ba7cd3fb1348314"; // Replace with your actual experimentId
const userGroupIndex = testGroups?.[experimentId]; // e.g. 0 or 1
const productId = "7420248031297"; // Replace with actual product ID
const variantId = "41685506818113"; // Replace with actual variant ID
const priceData = window.abconvertPriceCartTransformTestDict?.[productId]?.variantToGroupIndexToPrice?.[variantId]?.[userGroupIndex];
if (priceData) {
const price = priceData.price;
const compareAt = priceData.compareAtPrice;
// Update DOM with price
document.querySelector(".product-price").textContent = `$${price}`;
if (compareAt) {
document.querySelector(".compare-price").textContent = `$${compareAt}`;
}
}
4. Handling market-based prices (country-specific)
If your price test includes market-specific pricing, such as different prices for DE, FR, IT, etc., you’ll find those under the countryMap key for each variant and group.
We use Shopify’s official country codes: CountryCode - Storefront API
Example: variantToGroupIndexToPrice with countryMap
{
"41685506818113": {
"0": { // Group 0 – Original
"price": "699.95",
"compareAtPrice": null,
"countryMap": {
"DE": {
"price": "20.95",
"compareAtPrice": 0
},
"FR": {
"price": "20.95",
"compareAtPrice": 0
}
// ... more countries
}
},
"1": { // Group 1 – Variant
"price": "799.95",
"countryMap": {
"DE": {
"price": "30.95"
// compareAtPrice can be optional
},
"FR": {
"price": "30.95"
}
// ... more countries
}
}
}
}
