Skip to main content

AR Try-on Events

GlamAR SDK sends triggers all essential events for the user on every ui interaction, data change and api resolution. We will dive deep into these events and when and how to use them. First we will go over basic events.

Life Cycle Events

loading

Fired when the GlamAR module is initiated and the SDK proceeds with the loading process.

Don't call any other function before you recieve the loaded event as it may cause misbehaviour due to incomplete initialization

GlamAR.addEventListener("loading", () => { console.log("GlamAR: Is Loading..."); })

loaded

Fired when the GlamAR module initialization is completed

Use this event as a starting point to call any other fuction, as shown below

// Initilization Function
GlamAR.init("Your Contianer Id", "Your Access Key", { platform: "web" });

// Listen for loaded event
GlamAR.addEventListener("loaded", () => {
console.log("GlamAR: Loaded successfully");
// Continue with desired flow

// Example: apply a specific SKU
// GlamAR.applyBySku("valid-skuId");

// Example: apply a category by name
// GlamAR.applyByCategory("valid-subcategory");

// Example: start EyePD tracking
// GlamAR.eyePD("start");
});

opened

Fired when GlamAR module starts showing any type of viewer ,i.e, Live Try-on, Model Try-on or Model Viewer

// Opens the GlamAR SDK or activates the AR session
GlamAR.open();

// Listen for the 'opened' event
GlamAR.addEventListener("opened", () => {
console.log("GlamAR: Opened successfully");
});

closed

Fired when GlamAR module is told to stop working

// Closes the GlamAR SDK
GlamAR.close();

// Listen for the 'closed' event
GlamAR.addEventListener("closed", () => {
console.log("GlamAR: Closed successfully");
});

reset

Fired when GlamAR module removes all the applied effects are reset.

// Resets the GlamAR SDK applied effects
GlamAR.reset();

// Listen for the 'reset' event
GlamAR.addEventListener("reset", () => {
console.log("GlamAR: Reset successfully");
});

error

Fired anytime an error occurs. This event returns Error object with a description of the error that has been encountered. If your toasts are active you will see the same message on screen. If you want to use your own error handling UI just listen to this event and show errors using the Error we send.

GlamAR.addEventListener("error", (error) => {
console.log("GlamAR: Error encountered", error);
});

Camera Events

camera-opened

Fired when the camera is opened successfully.

camera-closed

Fired when the camera is closed successfully.

camera-access-issue

Fired when the camera fails. This can occur if the user refuses to grant permission or the app is unable to retrieve the video stream normally.

// Fired when the GlamAR camera is opened
GlamAR.addEventListener("camera-opened", () => {
console.log("GlamAR: Camera opened");
});

// Fired when the GlamAR camera is closed
GlamAR.addEventListener("camera-closed", () => {
console.log("GlamAR: Camera closed");
});

// Fired when camera permission is not granted
GlamAR.addEventListener("camera-access-issue", () => {
console.log("GlamAR: Camera permission not granted");
});

Try-on Events

sku-applied

Fired when a given SKU is applied successfully

sku-failed

Fired when a given SKU is not applied successfully. This can occur if there is some issue with SKU data or user's subscription has exprired. Check the Check the Pixelbin > GlamAR > Plans to make sure your plan is active and has enough credits.

// Apply a desired SKU by ID
GlamAR.applyBySku("valid-sku-id");

// Listen for the 'sku-applied' event
GlamAR.addEventListener("sku-applied", () => {
console.log("GlamAR: SKU was correctly applied");
});

// Listen for the 'sku-failed' event
GlamAR.addEventListener("sku-failed", () => {
console.log("GlamAR: SKU failed to apply. Go to GlamAR Console and check plan details and credits");
});

photo-loaded

Fired when SDK is prompted to take a screenshot of the current AR effect. This event handles both success or failed conditions. The payload of this event contains two variables as follows:

  • image in base64 format
  • status in string format with possible values of succes | failed

Below code example shows the complete cycle of function and event

// Prompts the GlamAR SDK to take a screenshot
GlamAR.snapshot();

// Listen for the photo-loaded event
GlamAR.addEventListener("photo-loaded", ({ image, status }) => {
console.log("GlamAR: Screenshot status:", status, "image data:", image);
});

UI Events

ui-interactions

Fired when a user interacts with any UI element. You can register these events to trigger specific actions or to track behavior on your side.
GlamAR provides its own analytics as well, but you can also log these for custom analytics.

UI elements have two behaviors:

  • clicked
  • toggleOn | toggleOff

topNavigationPanel

Image

This is the top navigation panel. It has four buttons, each with an interaction event:

  • Clicked on Back button
  • Clicked on Global Cart button
  • Clicked on Share button
  • Clicked on Close button
UI ElementAction
backclicked
globalCartclicked
shareclicked
closeclicked
GlamAR.addEventListener("ui-interactions", ({ screenType, buttonType, value }) => {
console.log("GlamAR: UI event:", screenType, "interacted with:", buttonType, "value:", value);
if (screenType === "topNavigationPanel") {
if (buttonType === "back") { /* Back button clicked */ }
if (buttonType === "globalCart") { /* Global Cart button clicked */ }
if (buttonType === "share") { /* Share button clicked */ }
if (buttonType === "close") { /* Close button clicked */ }
}
});

vtoHeroScreen

Image

This is the first screen displayed when the SDK initializes correctly and the UI is not overridden.

  • Clicked on Live Camera button
  • Clicked on Choose a Model button
UI ElementAction
LiveCameraclicked
ChooseAModelclicked
GlamAR.addEventListener("ui-interactions", ({ screenType, buttonType }) => {
console.log("GlamAR: UI event:", screenType, "interacted with:", buttonType);
if (screenType === "vtoHeroScreen") {
if (buttonType === "LiveCamera") { /* Live Camera button clicked */ }
if (buttonType === "ChooseAModel") { /* Choose a Model button clicked */ }
}
});

skuSelectionPanel

Image

Displayed when any category is applied correctly. If there are multiple SKUs, this panel allows selecting one.

  • Clicked on Add to Cart button
  • Clicked on Add to Wishlist button (the heart icon)
UI ElementAction
addToCartclicked
addToWishlistclicked
GlamAR.addEventListener("ui-interactions", ({ screenType, buttonType }) => {
console.log("GlamAR: UI event:", screenType, "interacted with:", buttonType);
if (screenType === "skuSelectionPanel") {
if (buttonType === "addToCart") { /* Add to Cart clicked */ }
if (buttonType === "addToWishlist") { /* Add to Wishlist clicked */ }
}
});

modelScreen

Image

Shown when any SKU is applied correctly and the user chooses Choose a Model. Users can select a model or upload their own.

  • Clicked on Upload button
  • Clicked on Confirm button
UI ElementAction
uploadclicked
confirmclicked
GlamAR.addEventListener("ui-interactions", ({ screenType, buttonType, value }) => {
console.log("GlamAR: UI event:", screenType, "interacted with:", buttonType, "value:", value);
if (screenType === "modelScreen") {
if (buttonType === "upload") { /* Upload button clicked */ }
if (buttonType === "confirm") { /* Confirm button clicked */ }
if (buttonType === "selectModel") { /* Model index selected: value */ }
}
});

eyePdToast

Image

EyePD toast showing the default PD value.

  • Clicked on Measure Now button
UI ElementAction
measureNowclicked
GlamAR.addEventListener("ui-interactions", ({ screenType, buttonType }) => {
console.log("GlamAR: UI event:", screenType, "interacted with:", buttonType);
if (screenType === "eyePdToast") {
if (buttonType === "measureNow") { /* Measure Now button clicked */ }
}
});

eyePdInstructionScreen

Image

UI ElementAction
startNowclicked
GlamAR.addEventListener("ui-interactions", ({ screenType, buttonType }) => {
console.log("GlamAR: UI event:", screenType, "interacted with:", buttonType);
if (screenType === "eyePdInstructionScreen") {
if (buttonType === "startNow") { /* Start Now button clicked */ }
}
});

eyePdResultPopup

Image

UI ElementAction
proceedclicked
retakeclicked
GlamAR.addEventListener("ui-interactions", ({ screenType, buttonType }) => {
console.log("GlamAR: UI event:", screenType, "interacted with:", buttonType);
if (screenType === "eyePdResultPopup") {
if (buttonType === "proceed") { /* Proceed button clicked */ }
if (buttonType === "retake") { /* Retake button clicked */ }
}
});

modelViewerScreen

Image

This is the 3D Model Viewer screen. From left to right, each element emits a ui-interactions event on interaction.

UI ElementActionDescription
showDimensionsclickedShow dimensions panel
ARclickedBack to selected try-on
viewInYourSpaceclickedOn compatible mobile devices launches AR view. On desktop shows a QR code to scan
fullScreenclickedToggle full-screen view
qrCloseclickedClose the QR code popup
GlamAR.addEventListener("ui-interactions", ({ screenType, buttonType }) => {
console.log("GlamAR: UI event:", screenType, "interacted with:", buttonType);
if (screenType === "modelViewerScreen") {
if (buttonType === "showDimensions") { /* Show dimensions button clicked */ }
if (buttonType === "AR") { /* Back to selected try-on button clicked */ }
if (buttonType === "viewInYourSpace") { /* View in your space button clicked */ }
if (buttonType === "fullScreen") { /* Full screen button clicked */ }
if (buttonType === "qrClose") { /* QR close button clicked */ }
}
});

comparePanel

Image

Comparison UI emits events for the following interactions:

  • Clicked on Set Default button
  • Clicked on Close (X) button
UI ElementAction
closeclicked
defaultclicked
GlamAR.addEventListener("ui-interactions", ({ screenType, buttonType }) => {
console.log("GlamAR: UI event:", screenType, "interacted with:", buttonType);
if (screenType === "comparePanel") {
if (buttonType === "close") { /* Close button clicked */ }
if (buttonType === "default") { /* Set Default button clicked */ }
}
});

settingsPanel

Image

The settings panel differs for each category. The image above is for the eyewear category. Other buttons and UI elements are shown for different categories. Buttons include:

  • Clicked on Close (X) button
  • Clicked on Measure button
  • Clicked on Redo Measurement button
  • Clicked on Position button
  • Clicked on Intensity button
  • Clicked on Finger button
GlamAR.addEventListener("ui-interactions", ({ screenType, buttonType }) => {
console.log("GlamAR: UI event:", screenType, "interacted with:", buttonType);
if (screenType === "settingsPanel") {
if (buttonType === "close") { /* Close button clicked */ }
if (buttonType === "pdMeasurement") { /* Measure button clicked */ }
if (buttonType === "redoMeasurement") { /* Redo Measurement button clicked */ }
if (buttonType === "positionAdjustment") { /* Position button clicked */ }
if (buttonType === "intensity") { /* Intensity button clicked */ }
if (buttonType === "fingerSelection") { /* Finger button clicked */ }
}
});

somethingWentWrongScreen

Image

This is the main error screen that appears if the ML model or SKU fails to load.

  • Clicked on Choose different method button
GlamAR.addEventListener("ui-interactions", ({ screenType, buttonType }) => {
console.log("GlamAR: UI event:", screenType, "interacted with:", buttonType);
if (screenType === "somethingWentWrongScreen") {
if (buttonType === "chooseDifferentMethod") { /* Choose different method button clicked */ }
}
});

cameraFailed and cameraAccessDenied

Image

These are camera-related error screens that appear if the camera fails to load properly or access is denied.

  • Clicked on Choose different method button
GlamAR.addEventListener("ui-interactions", ({ screenType, buttonType }) => {
console.log("GlamAR: UI event:", screenType, "interacted with:", buttonType);
if (screenType === "cameraFailed" || screenType === "cameraAccessDenied") {
if (buttonType === "chooseDifferentMethod") { /* Choose different method button clicked */ }
}
});

restartPopUp

Image

Restart popup used in EyePD flow and Skin Analysis flow.

  • Clicked on No button
  • Clicked on Yes, restart button
GlamAR.addEventListener("ui-interactions", ({ screenType, buttonType }) => {
console.log("GlamAR: UI event:", screenType, "interacted with:", buttonType);
if (screenType === "restartPopUp") {
if (buttonType === "no") { /* No button clicked */ }
if (buttonType === "yes") { /* Yes, restart button clicked */ }
}
});

quitPopUp

Image

Quit confirmation popup used in EyePD and Skin Analysis flows.

  • Clicked on No button
  • Clicked on Yes, quit button
GlamAR.addEventListener("ui-interactions", ({ screenType, buttonType }) => {
console.log("GlamAR: UI event:", screenType, "interacted with:", buttonType);
if (screenType === "quitPopUp") {
if (buttonType === "no") { /* No button clicked */ }
if (buttonType === "yes") { /* Yes, quit button clicked */ }
}
});

toast

Image

Default toast shown for errors encountered.

  • Clicked on Close (X) button
GlamAR.addEventListener("ui-interactions", ({ screenType, buttonType }) => {
console.log("GlamAR: UI event:", screenType, "interacted with:", buttonType);
if (screenType === "toast") {
if (buttonType === "close") { /* Close button clicked */ }
}
});

add-to-cart

Fired when user clicks on add to cart button of any particular SKU. This event returns two variables inside its payload,

  • skuId in string format
  • productName in string format

This can be used to identify which product was selected to add to cart. On your end, you can add it to the cart or do anything required, and then if you want SDK's UI to reflect this confirmation that required action was completed, you will have to call

// Listen for the 'add-to-cart' event
GlamAR.addEventListener('add-to-cart', ({ skuId, productName }) => {
console.log("GlamAR: Add to cart:", productName, "id:", skuId);

// Perform your add-to-cart operation in your system
// ...

// Notify the SDK that the item was successfully added
GlamAR.addedToCart(skuId);
// Note: skuId must match the one received from the event
});

add-to-wishlist

Fired when user clicks on the heart icon of any particular SKU. This event returns two variables inside its payload,

  • skuId in string format
  • productName in string format

This can be used to identify which product was selected to add to wishlist. On your end, you need can add it to the wislist or do anything required, and then if you want SDK's UI to reflect this confirmation that required action was completed, you will have to call

// Listen for the 'add-to-wishlist' event
GlamAR.addEventListener('add-to-wishlist', ({ skuId, productName }) => {
console.log("GlamAR: Add to wishlist:", productName, "id:", skuId);

// Perform your add-to-wishlist operation in your system
// ...

// Notify the SDK that the item was successfully added
GlamAR.addedToWishlist(skuId);
// Note: skuId must match the one received from the event
});

add-to-cart-global

Fired when user clicks on the cart icon in the top navigation bar. This is can be used to open your own cart section, to show all the items in cart.

// Listen for the 'add-to-cart-global' event
GlamAR.addEventListener('add-to-cart-global', () => {
console.log("GlamAR: Open Global Cart clicked");

// Open your own global Cart section in your app
// ...

// If desired, close the SDK after opening the cart
// GlamAR.close();
});

Advanced Events

subscription-invalid

Fired when the subscription is found to be invalid or expired. Check the Pixelbin > GlamAR > Plans to make sure your plan is active and has enough credits.

// Listen for the 'subscription-invalid' event
GlamAR.addEventListener('subscription-invalid', () => {
console.log("GlamAR: Subscription has expired or credits consumed. Check plan status in console");
});

upload-started

Fired when the upload mode dialogue is shown. This is during Ar-tryon when user goes to Model try-on and wants to add his own image. When he starts the process we trigger this event

upload-cancelled

Fired when the upload mode dialogue is canceled.

GlamAR.addEventListener('upload-started', () => {
console.log("GlamAR: User started uploading their own model image to use");
});

GlamAR.addEventListener('upload-cancelled', () => {
console.log("GlamAR: User cancelled uploading model image");
});

overriden-ui-action

Fired when any UI that is prompted to be shown but has been deactivated from GlamAR console. User inside custom code can toggle ui as per his need. So when inside SDK that perticular UI is supposed to activate, instead of activating it, it will send this event with two variables

  • type in string | with possible values of popup|screen as values
  • name in string | with possible value of name of any overriden ui available

Note: Restart popup is dependent on the category choosen, it shows up for EyePD flow and Skin Analysis flow. So if you override this popup it will not show up for both cases

Image

// If 'heroScreen' has been overridden, this triggers once the SDK loads successfully after 'init'
GlamAR.addEventListener('overriden-ui-action', ({ type, name }) => {
console.log("GlamAR: type", type, "name", name);
if (type === "screen" && name === "heroScreen") {
// Show your own hero screen
// Show your own UI for Live TryOn or Model TryOn
// Call GlamAR.open() and GlamAR.open("imgTryOn") respectively
}
});

// If 'quit' has been overridden, this triggers when the popup opens after 'X' icon is clicked
GlamAR.addEventListener('overriden-ui-action', ({ type, name }) => {
console.log("GlamAR: type", type, "name", name);
if (type === "popup" && name === "quit") {
// Show your own quit popup
// 'No' just closes the popup
// 'Yes' call GlamAR.close()
}
});