Skip to main content

Using the $alia object in custom code

Define complex logic and reference any user data from custom code using the $alia object

Bill Wohlers avatar
Written by Bill Wohlers
Updated over 2 months ago

For complex tasks that are impossible with our UI, Alia supports writing custom code in various parts of the app, including in various parts of the popup and in targeting settings.

When writing custom code in Alia, you can use the $alia object to reference Alia user data, call methods related to the popup, and more.

Note that the $alia object is not yet supported in targeting settings (this is coming soon).

The $alia object

The $alia object allows you to access data and actions from within custom code. You can reference the $alia object like any other variable. For example:

const property = $alia.user.profile.properties["my-property"];
$alia.actions.nextStep();

All the properties that exist on the $alia object are documented below.

$alia.user

Contains info about the user. The shape of this object is:

{
createdAt: string; // ISO format, when the user first visited
shopifyCustomerID: string;
ipAddress: string;
country: string; // ISO 3166-1 alpha-2
market: string; // Shopify market
language: string; // Shopify locale (IETF language tag)
name: string;
phone: string; // only available immediately after signing up
email: string; // only available immediately after signing up
profile: {
history: string[][]; // array of sessions, where each session is an array of URLs
properties: Record<string, string>; // properties set on user
}
}

Getting a user's answer to a question

You can get a user's answer to a specific question by using the $alia.user.profile.properties object. The key will be the question name (as set in the Question element), and the value will be their answer. If there are multiple answers, they will be joined to a single string using a comma delimiter.

$alia.popup.step(id?: string)

Goes to the step with the given ID. If no ID is provided, goes to the next step.

The step ID can be found by right-clicking on a step in the popup editor.

$alia.popup.closePopup()

Closes the popup.

Did this answer your question?