JavaScript API

For ease of use, Intelligems adds an object to the global window scope when the page loads. It primarily acts as a read interface for configurations and session-specific A/B tests.


In this article:


API Details

The root level object is called igData. It should load immediately following the loading of your Intelligems JavaScript library.

Overview

window.igData

User

window.igData.user

The following functions are available in igData.user:


user.igId

Example

console.log(igData.user.igId);

"ig_71e855a9313945b63eb35e0abd5b63361d48"
 Returns
igId: string

The user's Intelligems IgId id.


user.getExperiments()

Example

console.log(igData.user.getExperiments());

[
{
"id": "8bce9d31-cd20-4f4a-a070-a6970c7e9803",
"name": "Price Test",
"isPreview": true
}
]
 Returns
experiments: { 
id: string;
name: string;
isPreview: boolean
}[] | null;

List of experiments the user is in.


user.getTestGroup([experimentId])

Example

console.log(igData.user.getTestGroup("8bce9d31-cd20-4f4a-a070-a6970c7e9803"))

{
id: "8cead46f-a9d1-41dd-a864-86fc718ee133",
name: "Control Group",
percentage: 33,
isControl: true
}
 Parameters
experimentId: string

Returns

testGroup: {
id: string;
name: string;
percentage: number;
isControl: boolean;
freeShippingThreshold: number | undefined;
shippingRate: number | undefined;
} | null

The user's test group based on experiment ID


user.getTestGroupName([experimentId])

Example

igData.user.getTestGroupName("8bce9d31-cd20-4f4a-a070-a6970c7e9803")

"Control Group"
 Parameters
experimentId: string
 Returns
testGroupName: string

User's test group name based on experiment ID.


Price

window.igData.price

The following functions are available in igData.price:


price.getPriceByVariantId([variantId])

Example

console.log(igData.price.getPriceByVariantId(32305433935974));

"89.95"
 Parameters
variantId: string
 Returns
price: string | null

The price for this product based on the user's test group and the product variant id.
If the variant is not included in any experiment, it will return null.


price.getDiscountByVariantId([variantId])

Example

console.log(igData.price.getDiscountByVariantId(32305433935974));

"1005"
 Parameters
variantId: string
 Returns
discount: string | null 

The discount for this user based on their test group and the product variant id. This discount is in cents (or equivalent currency).


price.getAltProductHandle([handle])

Example

console.log(igData.price.getAltProductHandle("dutch-oven"));

"dutch-oven-1"
 Parameters
handle: string
 Returns
altHandle: string

Product handle of duplicated product based on the user's current test group.


price.getAltVariantId([variantId])

Example

console.log(igData.price.getAltVariantId("32305433935974"));

"51805463582052"
 Parameters
variantId: string
 Returns
variantId: string | null

Corresponding variant ID of duplicated product based on the passed variant ID and the user's current test group.

Campaigns

window.igData.campaigns

The following functions are available in igData.campaigns:

  • getAll()
  • getGWP({achieved})

campaigns.getAll()

Gets all eligible campaigns and returns a list of campaigns.

campaigns.getGWP(options)

Returns all the eligible Gift-with-Purchase "tiers"

Parameters
options (optional):

  • achieved: boolean (optional) - When true, this will only return eligible (achieved) gift with purchase tiers. When omitted or false, this will return all gwp tiers.

Return

The function returns a list of tiers:

[
{
autoAddGiftWithPurchase: boolean, //if Intelligems will automatically add the GWP to cart
 giftWithPurchaseProductId: string | null, // Shopify Product ID (i.e. "7191907565616")
 giftWithPurchaseVariantId: string | null, // Shopify Variant ID (i.e. "435713513473145")
isGiftWithPurchase: boolean,
isFreeShipping: boolean,
minimumUnits: integer, // minimum requirement to be eligible, in dollars or items
}
]

    Example:

    console.log(igData.campaigns.getGWP({achieved: true}))
    [
      {
        giftWithPurchaseProductId: "7191907565616",
        giftWithPurchaseVariantId: null,
        autoAddGiftWithPurchase: false
        id: "0c8f4018-4b42-45ae-9fc4-8f5a9969c32a",
        minimumUnits: 100,
        unitDiscount: 0,
        isFreeShipping: true,
        isGiftWithPurchase: true,
      }
    ]