JavaScript SDK
The JavaScript SDK 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.
1
<script>
2
window._shipScout = window._shipScout || [];
3
_shipScout.push(function (response) {
4
5
/*
6
example response object
7
{
8
testId: 1,
9
testType: 'threshold',
10
variant: 'B',
11
threshold: true,
12
freeShippingThresholdCents: 5000,
13
shippingPriceCents: 1000,
14
lineItemProperty: 0467e6f7-8d66-4610-a939-da76dd9f7a68_1_B
15
}
16
*/
17
18
//apply any exchange rates to currency if necessary
19
var thresholdCents = (window.Shopify && Shopify.currency && Shopify.currency.rate) ? response.freeShippingThresholdCents * Shopify.currency.rate : response.freeShippingThresholdCents;
20
var flatrateCents = (window.Shopify && Shopify.currency && Shopify.currency.rate) ? response.shippingPriceCents * Shopify.currency.rate : response.shippingPriceCents;
21
22
23
//format currency
24
var currencyFormat = ShipScoutGetCurrency();
25
26
//get threshold amount with currency symbol
27
var thresholdAmount = ShipScoutFormatMoney(thresholdCents, currencyFormat);
28
29
//get flat rate amount with currency symbol
30
var flatrateAmount = ShipScoutFormatMoney(flatrateCents, currencyFormat);
31
32
//==== insert your code below to dynamically update elements ====//
33
34
//example updating an element on the page dynamically with the threshold amount
35
var el = document.getElementById("foo-bar");
36
37
if(response.freeShippingThresholdCents === 0) {
38
el.innerHTML = "FREE!";
39
} else {
40
el.innerHTML = thresholdAmount;
41
}
42
43
});
44
</script>
Copied!
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", "flat-rate" or "new-vs-returning".
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 SDK. The following 3 properties will be null however: testId, testType, and variant.
Testing the SDK without a live test
You can append ?shipscout_preview=yes to any URL on your website to test your SDK integration without a live test. Appending this URL will simulate these hard-coded values for the SDK:
1
testType: 'threshold',
2
threshold: true,
3
freeShippingThresholdCents: 0,
4
testId: 'preview',
5
variant: 'A',
6
shippingPriceCents: 500
Copied!
If you need to overwrite these hard-coded preview values to simulate a different setup or variant you can do that like this:
1
window._shipScout = window._shipScout || [];
2
_shipScout.push(function (response) {
3
4
//Temporarily overwrite the response for testing
5
response = {
6
...response,
7
freeShippingThresholdCents: 5000,
8
variant: 'B',
9
}
10
11
})
Copied!
Last modified 2mo ago
Copy link