Skip to main content

The $alia object

Reference data & perform actions from custom code using the $alia object

Written by Joel Pednaud

The $alia object is a Javascript object that allows you to reference user data and perform actions relating to Alia's current state.

The $alia object is supported in the following places:

  • Custom code targeting conditions

  • Custom code elements

  • Custom code actions

  • Expressions (in text & button elements and form submission properties)

How to use the $alia object

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: {
properties: Record<string, string>; // contains survey answers, etc.
}
}

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.

Getting the page a user signed up on

The page URL or path is not part of the $alia object. There is no $alia.user.pageUrl or equivalent key.

You do not need custom code or an event listener to capture it. Expressions evaluate any Javascript, so standard browser globals work directly in a property value:

  • window.location.pathname returns the path, for example /collections/new-arrivals

  • window.location.toString() returns the full URL

Set this as the value of a custom property on your email or SMS submit button to record which page a visitor signed up from. See Making use of custom Javascript code in Alia for expression syntax.

The same approach applies to any other browser value that is not on the $alia object, such as document.referrer or navigator.language.

$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 and clicking "Copy step ID".

$alia.popup.closePopup()

Closes the popup.

$alia.variables

Variables are key-value pairs that are stored in session storage and can be set using the "Set variables" action in the editor. $alia.variables provides methods and properties to read and update variables.

$alia.variables.get(name: string)

Returns the value of the variable with the given name.

$alia.variables.values

Returns the current state of all variables as an object.

$alia.variables.set(values: Record<string, any>)

Takes an object and updates just the variables present in the object.

Did this answer your question?