Behavioral Events

alby Context leverages event data from your website to tailor your agent’s interactions to each individual customer. For accurate context, you must implement required behavioral events directly in your codebase.

This guide details the events and expected payload structures to support a developer-friendly integration process to enable alby Context.

Before you begin

When implementing these events to enable alby Context, consider the following:

  • You need to implement the following JavaScript events to enable Context functionality. These events help alby understand customer behaviors and provide relevant responses.
  • These events do not fire automatically. You must call each event on your website when these actions occur. The alby snippet should be loaded on each page that one of the events will be fired.
  • alby Context is automatically enabled once the events are successfully sending to alby. If you need assistance, reach out to [email protected] for best practices and troubleshooting.
  • The alby Website Integration will log warnings in your browser console if required fields are missing or formatted incorrectly. Check the console for errors during integration or testing.
  • Avoid firing duplicate events for the same user action.
  • Never send sensitive or personal data in event payloads.

Required behavioral events

Event TypeDescriptionRequired FieldsOptional Fields
'AddedToCart'User adds a product to cartvariantId,cost,quantityproductId,cartId
'Purchase'User completes a purchaseorderId,total,items-
'RemovedFromCart'User removes a product from cartvariantId,cost,quantityproductId,cartId
'Search'User submits a searchquery,results-
'ViewedCart'User views their cartcost,itemscartId
'ViewedCollection'User views a product collectiontitle,itemscollectionId
'ViewedProduct'User views a product pageproductIdvariantId
'ViewedVariant'User views a product variantvariantId-

Payload structure examples

AddedToCart

// Minimal required fields
window.albyEvent = window.albyEvent || [];
window.albyEvent.push('AddedToCart', {
    variantId: '678xyz',                           // required
    cost: { amount: 29.99, currencyCode: 'USD' },  // required
    quantity: 2                                    // required
});

// With optional fields
window.albyEvent.push('AddedToCart', {
    variantId: '678xyz',                           // required
    cost: { amount: 29.99, currencyCode: 'USD' },  // required
    quantity: 2,                                   // required
    productId: 'abc123',                           // optional
    cartId: 'cart_456'                             // optional
});

AddedToCart event fields

FieldTypeRequiredDescription
variantIdstringYesThe unique identifier of the product variant/SKU added to the cart
costobjectYesPrice info; must contain amount (number)
quantityintegerYesNumber of this variant added to cart. Must be greater than 0.
productIdstringNoID of the parent/base product
cartIdstringNoID for the current cart/session

cost object

FieldTypeRequiredDescription
amountnumberYesThe numerical price of the item. Must be greater than or equal to 0.
currencyCodestringNoDefaults to ISO currency code USD

Purchase

window.albyEvent = window.albyEvent || [];
window.albyEvent.push('Purchase', {
    orderId: 'order_789',                          // required
    total: { amount: 59.98, currencyCode: 'USD' }, // required
    items: [                                       // required
        {
            productId: 'abc123',
            variantId: '678xyz',
            quantity: 2,
            cost: { amount: 29.99, currencyCode: 'USD' }
        }
    ]
});

Purchase event fields

FieldTypeRequiredDescription
orderIdstringYesThe unique identifier of the order made in the purchase event
costobjectYesPrice info; must contain amount (number)
itemsarray of objectsYesList of purchased items, each with productId, variantId, quantity, and cost

items array fields

FieldTypeRequiredDescription
productIdstringYesID of the parent/base product
variantIdstringYesUnique variant/SKU identifier
quantityintegerYesNumber of units of this variant purchased. Must be greater than 0.
costobjectYesPrice info; must contain amount (number)

cost object

FieldTypeRequiredDescription
amountnumberYesThe numerical price of the item. Must be greater than or equal to 0.
currencyCodestringYesDefaults to ISO currency code USD

RemovedFromCart

// Minimal required fields
window.albyEvent = window.albyEvent || [];
window.albyEvent.push('RemovedFromCart', {
    variantId: '678xyz',                           // required
    cost: { amount: 29.99, currencyCode: 'USD' },  // required
    quantity: 1                                    // required
});

// With optional fields
window.albyEvent = window.albyEvent || [];
window.albyEvent.push('RemovedFromCart', {
    variantId: '678xyz',                           // required
    cost: { amount: 29.99, currencyCode: 'USD' },  // required
    quantity: 1,                                   // required
    productId: 'abc123',                           // optional
    cartId: 'cart_456'                             // optional
});

RemovedFromCart event fields

FieldTypeRequiredDescription
variantIdstringYesUnique identifier of the product variant/SKU removed from the cart
costobjectYesThe price info; contains amount (number)
quantityintegerYesNumber of units of this variant removed from cart. Must be greater than 0.
productIdstringNoID of the parent/base product
cartIdstringNoIdentifier for the current cart/session

cost object

FieldTypeRequiredDescription
amountnumberYesThe numerical price of the item. Must be greater than or equal to 0.
currencyCodestringYesDefaults to ISO currency code USD

Search

window.albyEvent = window.albyEvent || [];
window.albyEvent.push('Search', {
    query: 'running shoes',                        // required
    results: [                                     // required
        { productId: 'shoe1', variantId: 'var1' },
        { productId: 'shoe2', variantId: 'var2' }
    ]
});

Search event fields

FieldTypeRequiredDescription
querystringYesThe text string the user searched for
resultsarray of objectsYesArray of search result items (see fields below)

results array fields

FieldTypeRequiredDescription
productIdstringYesProduct identifier for the result item
variantIdstringYesVariant/SKU identifier for the result item

ViewedCart

// Required fields only
window.albyEvent = window.albyEvent || [];
window.albyEvent.push('ViewedCart', {
    cost: { amount: 89.97, currencyCode: 'USD' },  // required
    items: [                                       // required
        {
            productId: 'abc123',
            variantId: '678xyz',
            cost: { amount: 29.99, currencyCode: 'USD' },
            quantity: 2
        },
        {
            productId: 'def456',
            variantId: '789abc',
            cost: { amount: 29.99, currencyCode: 'USD' },
            quantity: 1
        }
    ]
});

// With optional cartId
window.albyEvent = window.albyEvent || [];
window.albyEvent.push('ViewedCart', {
    cost: { amount: 89.97, currencyCode: 'USD' },  // required
    items: [                                       // required
        {
            productId: 'abc123',
            variantId: '678xyz',
            cost: { amount: 29.99, currencyCode: 'USD' },
            quantity: 2
        }
    ],
    cartId: 'cart_456'                             // optional
});

ViewedCart event fields

FieldTypeRequiredDescription
costobjectYesTotal price of all items in the cart; object with amount (number)
itemsarray of objectsYesArray of cart item objects, each representing an item in the cart
cartIdstringNoIdentifier for the cart/session (optional)

items array fields

FieldTypeRequiredDescription
productIdstringYesID of the parent/base product
variantIdstringYesUnique identifier for the product variant/SKU
costobjectYesPrice info of the item; object with amount
quantityintegerYesNumber of units of this item in the cart

cost object

FieldTypeRequiredDescription
amountnumberYesThe numerical price of the item. Must be greater than or equal to 0.
currencyCodestringYesDefaults to ISO currency code USD

ViewedCollection

// Minimal required fields
window.albyEvent = window.albyEvent || [];
window.albyEvent.push('ViewedCollection', {
    title: 'Summer 2025 Collection',               // required
    items: [                                       // required
        { productId: 'summer1', variantId: 'var1' },
        { productId: 'summer2', variantId: 'var2' },
        { productId: 'summer3', variantId: 'var3' }
    ]
});

// With optional collectionId
window.albyEvent = window.albyEvent || [];
window.albyEvent.push('ViewedCollection', {
    title: 'Summer 2025 Collection',               // required
    items: [                                       // required
        { productId: 'summer1', variantId: 'var1' },
        { productId: 'summer2', variantId: 'var2' },
        { productId: 'summer3', variantId: 'var3' }
    ],
    collectionId: 'summer-collection'              // optional
});

ViewedCollection event fields

FieldTypeRequiredDescription
titlestringYesName of the collection viewed
itemsarray of objectsYesArray of item objects in the collection (see structure below)
collectionIdstringNoIdentifier for this collection (optional)

items array fields

FieldTypeRequiredDescription
productIdstringYesProduct identifier in the collection
variantIdstringYesVariant/SKU identifier for the item

ViewedProduct

window.albyEvent = window.albyEvent || [];
window.albyEvent.push('ViewedProduct', {
    productId: 'abc123',        // required
    variantId: '678xyz'         // optional
});

ViewedProduct event fields

FieldTypeRequiredDescription
productIdstringYesUnique identifier for the viewed product
variantIdstringNoIdentifier for the viewed variant/SKU

ViewedVariant

window.albyEvent = window.albyEvent || [];
window.albyEvent.push('ViewedVariant', {
    variantId: '678xyz'                 // required
});

ViewedVariant event fields

FieldTypeRequiredDescription
variantIdstringYesUnique identifier for the viewed product variant/SKU