Skip to main content

Shopify

Anonymous visitors​

  1. In Shopify admin: Online Store → Themes → … → Edit code.
  2. Open layout/theme.liquid and paste the snippet just before </body>:
layout/theme.liquid
<script src="https://api.mysarthi.tech/widget/v1.js" data-site-key="ws_acme_7f3a9c" async></script>
  1. Save. Add your store's address (https://yourstore.com, and your https://….myshopify.com address 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:

layout/theme.liquid
<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.

note

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.