Skip to main content

The $alia object in custom code

The $alia object gives code you write inside Alia the visitor's details, plus ways to move through or close the popup.

Written by Rob D

Where you can use $alia

The $alia object is available in code you write inside Alia:

  • Custom code targeting conditions.

  • The Custom code element in the popup editor.

  • The Custom code action on a button or form.

  • Expressions in text, button text, and form submission properties. See Using JavaScript code expressions in Alia.

Reference it like any other variable:

const skinType = $alia.user.profile.properties["Skin type"];
$alia.popup.step();

💡 Note: In custom code targeting conditions, only $alia.user works. $alia.popup and $alia.variables do nothing there, because no popup is open yet.

$alia.user

Details about the visitor.

Field

What it holds

createdAt

When Alia first saw the visitor, as an ISO date.

name

The visitor's name, if they entered it.

email, phone

The visitor's email and phone number. Only filled in right after they submit them in this session.

maskedPhone

The visitor's phone number with most digits hidden.

hasEmail, hasPhone

Whether Alia has an email or phone number for the visitor.

emailOptIn, smsOptIn

Whether the visitor opted in to email or SMS.

shopifyCustomerID

The visitor's Shopify customer ID. Only filled in for logged-in Shopify customers.

country, market, language

The country (2-letter code), Shopify market, and storefront language Shopify set for the visitor.

ipAddress, ipCountry, ipRegion, ipCity

The visitor's IP address and the location it points to.

browser, os, isMobile

The visitor's browser, operating system, and whether Alia counts them as on mobile.

isMerchantPreview

true when you're previewing your own popup.

profile.properties

The visitor's profile properties, including their answers to questions.

Getting a visitor's answer to a question

Use $alia.user.profile.properties. The key is the question's name, as set on the question element. The value is the visitor's answer. Multiple answers are joined into one string, separated by commas.

const skinType = $alia.user.profile.properties["Skin type"];

$alia.popup

Move through or close the popup.

$alia.popup.step(id)

Goes to the step with that ID. Leave out the ID to go to the next step.

To get a step's ID, right-click the step in the popup editor and select Copy step ID.

$alia.popup.closePopup()

Closes the popup.

$alia.variables

Variables are name and value pairs that last for the browser tab's session. A new tab starts with none. You can also set them with the Set variable(s) action.

$alia.variables.get(name)

Returns one variable's value.

$alia.variables.values

Holds all variables as an object.

$alia.variables.set(values)

Takes an object and updates only the variables in it. Other variables stay as they are.

$alia.variables.set({ shopping_for: "gift" });

💡 Tip: Ask Lia to add a Custom code element to your popup, for example: "Add a custom code element that shows the visitor's quiz answer."

FAQ

How do I get the page a visitor signed up on?

The page URL isn't on $alia. Use the browser's own values instead, which work directly in an expression:

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

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

To record it, set a custom property on your email or SMS submit button to {{ window.location.pathname }}. The same approach works for other browser values, such as document.referrer or navigator.language.

Can I use $alia from my store's own code?

No. $alia only exists inside code you write in Alia. From your store's code, use the JavaScript SDK. See How to use the Alia SDK.

Still have questions?

Start a chat from inside the Alia app, or use the chat in our Help Center.

Did this answer your question?