Skip to main content

Using JavaScript code expressions in Alia

Show live values in popup text, buttons, and form properties with expressions written in double curly braces.

Written by Rob D

Expressions let your popup show live values, such as the visitor's country, a discount code, or a countdown. You write an expression in double curly braces, and Alia replaces it with its result when the popup shows.

You can use expressions in:

  • Text elements

  • Button text

  • Properties a form sends when it's submitted

Write an expression

An expression is any short piece of JavaScript inside double curly braces:

Shipping to {{ $alia.user.country }} today

This shows the same thing:

{{ "Shipping to " + $alia.user.country + " today" }}

Keep expressions simple. Statements and complex syntax, such as JSON, may not work.

Insert an expression without typing code

  1. Select the text or button in the popup editor.

  2. In the right sidebar, select the Insert an expression icon next to the text field.

  3. Choose Visual to pick a value from a list, or </> Code to write your own.

  4. Select Save.

Expressions show as pills in the editor. To change one, select the pill. Edit expressions in the right sidebar, not by double-clicking the text on the canvas.

💡 Note: The editor only shows expressions that are a plain name, such as {{ discount_code }}. Longer expressions appear blank in the editor. Select Preview to see what they show on your store.

Values you can use

Variables

Variable

What it shows

question_text

The text of the question the element sits inside

answer_text

The text of the answer the element sits inside

discount_code

The visitor's discount code

discount_expiration

When the visitor's discount code expires

phone

The visitor's phone number, masked so only the last four digits show. Empty until they enter it

sms_consent

SMS consent text for a form where the visitor enters their phone number and selects a button

sms_consent_es

SMS consent text in Spanish. The HELP and STOP keywords stay in English

sms_consent_fr

SMS consent text in French. The HELP and STOP keywords stay in English

email_consent

Email consent text

card_offer

The offer revealed in a Pick a card game

The consent texts link to the terms of service and privacy policy you set in Settings. Use question_text and answer_text instead of typing the question or answer twice, so the text always matches what's sent to your integrations.

The $alia object

$alia holds details about the visitor, such as their country, Shopify market, and quiz answers. For example, {{ $alia.user.market }} shows the visitor's Shopify market. See The $alia object in custom code.

Rewards

reward() shows a reward's discount code or its text, such as "15% off":

{{ reward({ id: 12345, property: "text" }) }}

Replace 12345 with your reward's ID from the Rewards page. Use "code" to show the code instead.

  • If the visitor already claimed this reward, it shows the one they claimed.

  • If not, calling it claims the reward. For a unique code reward, that creates a new code.

To build this without code, choose Reward in the Insert expression window.

Countdowns

countdown() shows a ticking timer. For most countdowns, the Countdown element is easier. See How to insert a countdown timer.

To count down

Use

A fixed time

secs, mins, hours, or days, such as {{ countdown({ mins: 10 }) }}

To a date

date, such as {{ countdown({ date: "2026-12-31" }) }}

To the end of a period

endOf: "minute", "hour", "day", "week", "month", or "year"

Add format: "letters" (1d 2h 30m) or format: "colons" (01:02:30) to change how it looks, and units to choose which units show.

link() builds a link to a page on your store. Give it a reward ID to apply that reward's code at checkout. To build a link without code, choose Link in the Insert expression window.

Frequently asked questions

Why does my expression show as blank in the editor?

The editor only runs expressions that are a plain name. Select Preview to see the result on your store.

How do I record the page someone signed up on?

Add a property to the form with the value {{ window.location.pathname }}. Use {{ window.location.toString() }} for the full URL.

Why does only part of my expression work on my store?

If your store's security settings block JavaScript, only expressions that are a plain name, such as {{ discount_code }} or {{ $alia.user.market }}, still work.

Still have questions?

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

Did this answer your question?