Skip to main content

How to use the Alia SDK

Use window.alia to open or close popups, set profile properties, and listen for signups and other events on your store.

Written by Rob D

The Alia SDK lets code on your store talk to Alia. Use it to open or close popups from your own buttons, add details to a subscriber's profile, or send Alia's signups and other events to another tool.

The SDK is part of Alia. If Alia is embedded on your store, there's nothing to install.

Send messages to Alia

Start every message with this line, then push your message:

window.alia = window.alia || [];
window.alia.push(message);

The first line makes sure your message isn't lost if your code runs before Alia loads. Alia reads any messages waiting when it starts.

Open a popup

window.alia = window.alia || [];
window.alia.push({
type: "open",
campaignID: 12345,
ignoreTargeting: true,
});

Replace 12345 with your campaign's ID. To find it, go to Campaigns and look for the gray number next to the campaign name. Select it to copy it.

ignoreTargeting decides whether the campaign's targeting still applies:

  • true: the popup opens even if the visitor doesn't match the targeting. The campaign still has to be live.

  • false: the popup opens only if the visitor matches the targeting when Alia handles your message.

  • Left out: the popup opens only if the visitor matched the targeting when the page loaded. This is the older behavior.

Set ignoreTargeting to true or false so the result is predictable.

Close a popup

window.alia = window.alia || [];
window.alia.push({ type: "close" });

This fully closes Alia popups on the page, including any floating buttons, the same as a Close popup action.

Set profile properties

window.alia = window.alia || [];
window.alia.push({
type: "setProperties",
properties: { loyalty_tier: "gold", landing_collection: "summer" },
});

Alia adds these to the visitor's profile and sends them to most integrations, including Klaviyo, Attentive, and Postscript, with the visitor's next signup. Keys must be text, and values are turned into text.

Report analytics consent

If your store uses its own consent banner, tell Alia what the visitor chose:

window.alia = window.alia || [];
window.alia.push({ type: "enableAnalyticsTracking" });
// or
window.alia.push({ type: "disableAnalyticsTracking" });

Reset for the next visitor

window.alia.push({ type: "reset" });

This clears what Alia knows about the visitor in this browser and reloads the page, so the next person counts as a new visitor. Use it for signups collected in person on one device. Add reload: false if your own code navigates the page afterwards.

Listen for events from Alia

Alia fires browser events whenever a visitor interacts with a popup. Each event name starts with alia:. For example, this code listens for signups:

document.addEventListener("alia:signup", (event) => {
console.log(event.detail.email);
});

Every event's detail includes type and popupID, and usually popupTitle, campaignID, and campaignTitle.

Event

When it fires

Extra fields in detail

alia:campaignMatched

A visitor matches a campaign's targeting on this page

None

alia:popupView

A visitor sees a popup

None

alia:popupClose

A visitor closes a popup

None

alia:signup

A visitor submits a form with their email or phone

email, phone (either can be missing)

alia:pollAnswered

A visitor answers a question

answers: a list of questionID, questionText, answerID, and answerText

alia:rewardClaimed

A visitor claims a reward

rewardID, rewardText (such as "15% off"), discountCode, shopifyDiscountCodeNodeID

answers usually has 1 item. It has more when a question allows more than one answer.

💡 Note: If a popup should only open from your code, remove all of its triggers, including Smart Trigger. Otherwise it also opens on its own.

To open a popup when someone clicks a button or link on your site, see How to trigger a popup on click or with JavaScript. To use visitor data inside a popup, see The $alia object in custom code.

Frequently asked questions

My open message does nothing. What should I check?

Check that the campaign is live and that you used the campaign's ID, not a popup's. If ignoreTargeting is false or left out, the visitor also has to match the campaign's targeting. Look for errors in your browser console.

Does Alia send webhooks?

No. Use the browser events above to send Alia activity to another tool as it happens.

Still have questions?

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

Did this answer your question?