JavaScript API

The JavaScript API lets you get information about the test or settings that a current user is active in.

Include the following JavaScript wherever you'd like (we recommend somewhere before the closing </head> tag). It will execute as soon as ShipScout has loaded and will inform you on which test the current user is in.

<script>
window._shipScout = window._shipScout || [];
_shipScout.push(function (response) {
/*
example response object
{
testId: 1,
testType: 'threshold',
variant: 'B',
threshold: true,
freeShippingThresholdCents: 5000,
shippingPriceCents: 1000
}
*/
//apply any exchange rates to currency if necessary
var thresholdCents = (window.Shopify && Shopify.currency && Shopify.currency.rate) ? response.freeShippingThresholdCents * Shopify.currency.rate : response.freeShippingThresholdCents;
//format currency
var currencyFormat = ShipScoutGetCurrency();
//get amount
var amount = ShipScoutFormatMoney(thresholdCents, currencyFormat);
//==== insert your code below to dynamically update elements ====//
//example updating an element on the page dynamically with the threshold amount
var el = document.getElementById("foo-bar");
if(response.freeShippingThresholdCents === 0) {
el.innerHTML = "FREE!";
} else {
el.innerHTML = amount;
}
});
</script>

Here's a description of the properties and values to expect in the response object.

Property

Value Type

Example

Description

testId

integer | null

1

The test number.

variant

string | null

A

The variant this user is in.

freeShippingThresholdCents

integer

5000

*Only present if threshold is true

The amount, in cents, required to get free shipping.

shippingPriceCents

integer

1000

The price, in cents, of shipping.

threshold

boolean

true

If there's a free shipping threshold for this user.

testType

string | null

threshold

The value can either be "threshold" or "flat-rate".

If there's no test live but you do have a Default Shipping Rate set in ShipScout the rate settings will still be returned by the JS API. The following 3 properties will be null however: testId, testType, and variant.