Shopify
Anonymous visitors
- In Shopify admin: Online Store → Themes → … → Edit code.
- Open
layout/theme.liquidand paste the snippet just before</body>:
<script src="https://api.mysarthi.tech/widget/v1.js" data-site-key="ws_acme_7f3a9c" async></script>
- Save. Add your store's address (
https://yourstore.com, and yourhttps://….myshopify.comaddress if you use it) under Allowed websites in the console.
Themes that support app embeds or a "custom code" section work too: anywhere that ends up in the page body is fine.
Logged-in customers
Shopify lets Liquid tell you whether a customer is logged in, but a token must be signed by a server with your SDK secret, and theme code can't keep a secret. You need one small endpoint of your own (a Shopify app proxy, a serverless function, or any server you run) that checks the Shopify customer and returns a token:
<script src="https://api.mysarthi.tech/widget/v1.js" async></script>
<script>
{% if customer %}
window.Sarthi = { q: [['init', {
siteKey: 'ws_acme_7f3a9c',
// Your own endpoint (for example an app proxy at /apps/saarthi/token) that verifies the
// customer and signs the token with your SDK secret. See "Signing the token on your server".
getEndUserToken: () => fetch('/apps/saarthi/token', { credentials: 'same-origin' })
.then((r) => r.json()).then((d) => d.token),
}]] };
{% else %}
window.Sarthi = { q: [['init', { siteKey: 'ws_acme_7f3a9c' }]] };
{% endif %}
</script>
In the token, use the Shopify customer id as user_id, and attrs for anything your routing rules need (for example the customer's tags). The exact claims are in Signing the token on your server.
Without a token, logged-in customers still get the chat: they just chat as anonymous visitors (the form, if you have one, instead of being recognised). Per-customer answers from your database need the token.