window.ABConvert. For what the API is for and how to use it, read JavaScript API first.
Globals
Do not define your own
window.ABConvert: ABConvert replaces it when it runs. The ABConvert object reaches your window.ABConvertQueue callback as its argument.
Methods
A method marked with a test type exists only while your store has a test of that type running or in preview.
onReady
Runscallback when ABConvert is ready, or at once if it already is. The same as pushing onto window.ABConvertQueue; use it from code that already holds the object.
(ABConvert) => void
required
Receives the
ABConvert object.getAssignments
Returns oneAssignment per test the visitor is in. Tests that excluded the visitor are absent.
getAssignment
Returns the visitor’sAssignment for one test, or null.
string
required
The test ID shown in the ABConvert admin, as a string:
'49603'.getPriceByVariantId
Returns the visitor’sPrice for one product variant, or null when no test price applies. See the null rules.
string
required
The product variant ID as a numeric string:
'47522361606401'.PriceOptions
getPriceByProductId
Returns onePrice for a product, or null, under the same rules as getPriceByVariantId.
string
required
The product ID as a numeric string:
'6654464491584'.PriceOptions
formatPrice
Returnsamount formatted in currency for the visitor’s locale, such as '$62.70'. For a currency code the browser does not know, returns the code and the amount with two decimals, as in 'NOPE 49.50'.
number
required
string
ISO 4217 code. Defaults to the page currency, then to
'USD'.getShippingRates
Returns theShippingRates the visitor’s test group offers, cheapest first within each zone and currency. Returns null when the visitor is in no shipping test, and [] when the test group has no rates.
ShippingOptions
getFreeShippingThreshold
Returns the lowest order subtotal at which the visitor’s test group gets a free rate in a zone, as aFreeShippingThreshold, or null when the visitor is in no shipping test or no single threshold exists. See the null rules.
ShippingOptions
getOffers
Returns oneOffer per offer test the visitor is in. A test group with no offer contributes none.
track
Records a custom JS event for this visitor. At most once per page load; an unknown slug, or a page outside the event’s page scope, records nothing.string
required
The event’s slug from the custom event library:
'product_builder_completed'.{ value?: unknown }
value is stored with the event.getVisitorId
Returns the ID ABConvert records this visitor’s assignments under, creating it if needed. Use it to match your own logs with ABConvert data. When the browser blockslocalStorage, every call returns a new ID, so read it once and reuse it. To segment other tools by test group, send testGroup.index, not the visitor ID.
getCountry
Returns the visitor’s country as an ISO 3166-1 alpha-2 code such as'US', or '' while it is still unknown. It is the country ABConvert detected, not the market the page rendered for, so it can differ from Price.country. Preview with a chosen country returns that country.
forceTestGroup
Puts you in a test group from the next page load. For seeing a test group yourself; see Force a test group.string
required
The test ID. Throws a
TypeError when empty.number
required
The test group’s position, counting from 0. Throws unless it is an integer of 0 or more. A position past the last test group shows Control.
clearForcedTestGroup
UndoesforceTestGroup for one test, from the next page load.
string
required
The test ID. Throws a
TypeError when empty.Events
ABConvert fires two events onwindow. abconvert:assignment-ready fires before ABConvert changes the page; abconvert:ready fires after.
Rules for
abconvert:ready:
- It fires once and does not replay. Prefer
window.ABConvertQueue, which runs your callback whether you push before or after the event. - It does not fire again on client-side navigation. A theme that swaps page content without a full load gets one event, on the first load.
abconvert:assignment-ready:
- It fires before your queue callback runs. Add the listener at the top level of your script, not inside a
window.ABConvertQueuecallback, or it never runs. To read assignments after the fact, callgetAssignments()instead. - It does not fire for a forced or preview assignment. A visit forced with
forceTestGroup, a link, or Preview appears ingetAssignments()but sends no event. - It fires once per test. A combined test’s changes register as one assignment and send one event.
Objects
Assignment
string
The test ID shown in the ABConvert admin, as a string.
string
string
One of
price, shipping, theme, template, url_redirect, checkout, offer, visual_editor, combined, personalization.'active' | 'preview'
The test lifecycle states a visitor can see.
TestGroup
The visitor’s test group.
string
How the visitor got the test group:
TestGroup
number
The test group’s position in the test, counting from 0. Use it as the identifier.
string
A display label. Can change at any time.
boolean
true for Control. false for every test group of a personalization.number
The test group’s share of traffic, an integer from 0 to 100.
Price
string
TestGroup
number
number | null
null when the test group sets no compare-at price.string
ISO 4217. The currency this price is stated in.
string
ISO 3166-1 alpha-2. The country this price is for. Empty when unknown.
string
string
ShippingRate
string
TestGroup
string
The shipping zone name, as in the Shopify admin.
string
The rate name shown at checkout.
number
0 for a free rate.string
The currency you set the rate in, which can differ from the page currency.
object | null
null for a rate with no condition.FreeShippingThreshold
string
TestGroup
string
number
0 for a free rate with no condition.string
The currency you set the rate in, which can differ from the page currency.
Offer
string
TestGroup
string
Discount[]
The offer’s discounts. The
Discount shapes are in the TypeScript block below.TypeScript
Copy this into a.d.ts file for autocompletion and type checking. Methods marked ? exist only while your store has that test type.