Dynamic variables
Pass dynamic variables from your website
Your website tells the avatar who it's talking to when a call starts: a name, a plan, an order number. These details are called dynamic variables.
Which way to use
| Your situation | Do this |
|---|---|
| You use the floating widget and your page knows the visitor when it loads | Add them to the widget snippet |
| The visitor signs in after the page loads (web apps) | Pass them from JavaScript |
| Your store runs on Shopify | Paste the Shopify snippet |
| You use the inline iframe, or a direct link (emails, QR codes) | Add them to the address |
- •Details are fixed when the visitor starts a call. Changes apply to their next call.
- •A detail your Dynamic Instructions don't use never reaches the avatar, but it's still available to webhooks.
- •The details are kept with the conversation, for your business only.
With the floating widget
In the widget snippet
Add the details to your embed snippet as JSON, in data-vars:
<script src="https://talk.selviaai.com/embed.js"
data-embed-key="emb_…"
data-vars='{"name":"John","plan":"Gold","orders":12}'
async></script>From JavaScript
For web apps where the visitor signs in after the page has loaded:
<script>
// Safe to call before or after the widget has loaded.
window.SelviaAI = window.SelviaAI || { q: [], identify: function (v) { this.q.push(v); } };
// After sign-in (adds to anything passed before):
SelviaAI.identify({ name: "John", plan: "Gold", order_id: "A-1042" });
// On sign-out:
SelviaAI.reset();
</script>On Shopify
No developer needed. In your theme's code (Online Store → Themes → Edit code → theme.liquid), paste this right after the Selvia AI widget snippet, before </body>:
<script>
window.SelviaAI = window.SelviaAI || { q: [], identify: function (v) { this.q.push(v); } };
SelviaAI.identify({
name: {{ customer.first_name | json }},
orders: {{ customer.orders_count | json }}
});
</script>Signed-in customers are greeted by name, and orders tells the avatar how many times they've ordered. For visitors who aren't signed in, the details are simply missing, and your instructions' “otherwise” text applies.
Inline iframe and direct links
Add the details after # in the address, as URL-encoded JSON. The part after # is never sent to any server, so the details stay out of server logs.
const details = { name: "John", plan: "Gold" };
const address = "https://talk.selviaai.com/embed/emb_…#vars=" +
encodeURIComponent(JSON.stringify(details));
// use it as the iframe's src, or as a link: <a href="…">Talk to us</a>To change them later (after a sign-in, say), update the part after # on the iframe; the next call uses the new details.
Limits
| Limit | |
|---|---|
| Names | Up to 30. Letters, digits and _, starting with a letter, up to 40 characters. Upper and lower case are the same. |
| Values | Text, a number, or true/false. Up to 200 characters each; longer text is cut. |
| Total | Up to 4 KB for all details together. |
| Cleaning | Line breaks and braces are removed from text. Lists, objects and null are ignored. |
| Reserved names | visitor, true, false, and, or, not, avatar_name, business_name |
Anything over a limit is dropped or cut, and the call still starts. Nothing a visitor passes can stop your avatar from working.