You can open any live Alia popup with a short JavaScript snippet instead of waiting for the campaign's own triggers. Use it to open a popup from your own button, a banner, a link, or any other action on your store.
š” Note: Code is a custom solution. Before you write any, check whether a built-in trigger or targeting rule already does what you need. Built-in options keep working when your theme changes.
When to trigger a popup with JavaScript
Common reasons include:
A visitor selects a call-to-action button, like "Take the quiz" or "Get 10% off."
A visitor interacts with a banner or announcement bar.
A shopper adds a product to their cart.
A visitor reaches a specific section of a page.
Alia has no built-in "on click" trigger. To open a popup when someone clicks something on your site, you add a short script that listens for the click. The steps are below.
Before you start
Check that:
Your campaign is live. Only live campaigns can be opened with JavaScript.
Your popup has no triggers. If the popup should open only from your code, remove all of its triggers, including Smart Trigger. When none are left, its trigger settings show "No triggers configured. This popup will only show if triggered using our Javascript SDK."
You have your campaign ID. Go to Campaigns and find the gray number next to the campaign's name. Select it to copy it.
Open a popup with JavaScript
This snippet opens your popup as soon as it runs:
window.alia = window.alia || [];
window.alia.push({
type: "open",
campaignID: 12345,
ignoreTargeting: true
});
Replace 12345 with your campaign ID. The first line makes sure your message isn't lost if your code runs before Alia loads.
ignoreTargeting decides whether the campaign's targeting still applies:
true: the popup opens even if the visitor doesn't match the campaign's targeting. The campaign still has to be live.false: the popup opens only if it has already loaded for this visitor, because they matched the campaign's targeting on this page, and they still match when Alia handles your message.Left out: the older behavior. The popup opens if it has already loaded for this visitor, without checking targeting again.
Always set ignoreTargeting to true or false so the popup behaves predictably.
A few other things to know:
The popup uses the design you set up in the popup editor, so you don't need to style anything in code.
If you leave out
campaignID, every popup already loaded on the page opens.If the visitor has been through the popup before, it reopens on the last step they saw.
Open a popup when a visitor clicks an element
To open the popup from a button, banner, or link, add a script that listens for clicks on that element.
Find your element's CSS selector
A CSS selector tells the script which element to watch. In Google Chrome:
On your store, right-click the button and select Inspect. A panel opens showing the page's code, with the line for your button highlighted.
In the highlighted line, look for
id="..."orclass="...". You only need the value inside the quotation marks.Turn that value into a selector:
If the line has an id, add
#in front of it. For example,id="quiz-button"becomes#quiz-button.If there's no id, use a class and add
.in front of it. For example,class="btn quiz-cta"gives you.quiz-cta.
For example, a highlighted line might look like this:
<a href="/pages/quiz" id="quiz-button" class="btn quiz-cta">Take the quiz</a>
Here you'd use #quiz-button. An id is the best choice because it points to exactly one element.
š” Note: A class with spaces, like btn quiz-cta, is really 2 classes. Use just one, and pick the one most specific to your button. A general class like btn is often on every button on your site, so the popup would open from all of them.
If you can't find a usable id or class:
The highlighted line is text inside the button. If you right-clicked the button's label, Chrome may highlight a line starting with
<span. Look one line up for a line starting with<aor<button. That's usually the button itself.The button has no id and only general classes. Many theme buttons are like this. Ask whoever manages your theme to add an id to the button, or start a chat with us for help.
Add the script to your Shopify theme
Buttons you add in the Shopify theme editor usually can't run JavaScript on their own, so you add the script to your theme instead.
š” Tip: Before you edit theme code, duplicate your theme so you have a backup. In Themes, select ⯠ā Duplicate.
From your Shopify admin:
Go to Online Store ā Themes.
Next to your current theme, select ⯠ā Edit code.
In the Layout folder, open
theme.liquid.Paste the script below just before the closing
</head>tag.Replace
#open-offerwith your CSS selector and12345with your campaign ID.Select Save.
<script>
document.addEventListener("click", (event) => {
if (!event.target.closest("#open-offer")) return;
event.preventDefault();
window.alia = window.alia || [];
window.alia.push({ type: "open", campaignID: 12345, ignoreTargeting: true });
});
</script>
The script listens for clicks anywhere on the page and only acts when the click lands on your element. That keeps it working for elements your theme adds later, like a slide-out cart.
Other platforms: If your site builder lets a button run its own JavaScript, such as an onclick or custom code field, you can paste the snippet from Open a popup with JavaScript into that field instead.
Open a popup from a link
Add alia=1 to a page's URL, such as https://yourstore.com/?alia=1. Any popup that matches the visitor opens as soon as the page loads, without waiting for its triggers. Targeting still applies.
Test your popup
Open your store in a private browser window.
Select the button or link you set up.
Check that the popup opens.
š” Note: If ignoreTargeting is false, your targeting rules still apply while you test. Rules for returning visitors or specific devices can stop the popup from opening.
FAQ
I added the script, but my popup isn't opening. What should I check?
Work through these in order:
The campaign is live.
You used the campaign's ID, not a popup's ID.
The CSS selector matches your element exactly, including the
#or..You saved
theme.liquidin the theme that's currently published.If
ignoreTargetingisfalseor left out, the visitor matches the campaign's targeting.
You can also check your browser's console for errors. Alia labels its errors with [Alia.
Can I open the same popup from more than one button?
Yes. Give each button the same class, such as open-offer, and use .open-offer as the selector. The script works for every element that matches.
Why does my popup also open on its own?
The popup still has triggers. Remove all of them, including Smart Trigger.
My button is a link, and the page changes before the popup opens. How do I fix it?
Keep event.preventDefault() in the script, or remove the link's href. Otherwise the page navigates away before the popup can open.
Still have questions?
Start a chat from inside the Alia app, or use the chat in our Help Center.

