Anonymous Chat (Guest Mode)
- Visitors can chat without accounts.
- Fastest, friction-free setup.
Create + Log In User On The Fly (Shopify Customers)
- Auto-create CometChat users from Shopify customers.
- Falls back to guests when no one is logged in.
Backend-Created User (Auth Token Login)
- Use your backend to issue auth tokens.
- Keep your Auth Key off the storefront.
Where to paste the snippet in Shopify
- In Shopify Admin, go to Online Store → Themes → … → Edit code.
- Open layout/theme.liquid (or a section where you want the widget).
- Scroll near
</body>and paste the snippet from the option you choose. - Save and refresh your storefront to confirm chat loads.
- For page-specific placement, paste the snippet into a section or template instead of the global layout.
1. Anonymous Chat (Guest Mode)
Use this when: you want anyone to chat without signing in.Paste this near </body> in layout/theme.liquid
appID,region,authKey: Copy from the CometChat Dashboard (use an App Auth Key, not REST API key).user.name,user.avatar,user.link: Optional guest display info.width,height,isDocked: Size/placement (isDocked = trueshows a docked bubble).variantID,chatType,defaultChatID,dockedAlignment: Optional widget targeting/placement controls.
2. Create + Log In User On The Fly (Shopify Customers)
Use this when: you have Shopify customer accounts and want logged-in shoppers to automatically become CometChat users. Falls back to a persistent guest ID for visitors.Turn on Shopify customer accounts so{{ customer.id }}and{{ customer.first_name }}populate.
Paste this near </body> in layout/theme.liquid
appID,region,authKey: Copy from Dashboard (App Auth Key).uid: Leave as-is; it pulls Shopify customer ID or a stored guest ID.user.name,user.avatar,user.link: Optional profile info shown in chat.width,height,isDocked,variantID,chatType,defaultChatID,dockedAlignment: Optional UI/placement controls.
- Uses Shopify
customer.id+customer.first_namewhen a shopper is logged in. - Stores a stable guest ID in
localStoragefor visitors so their chat history persists across pages. - CometChat auto-creates the UID the first time it sees it.
3. Backend-Created User (Auth Token Login)
Use this when: people sign in through your backend and you generate their CometChat auth token server-side. This keeps your Auth Key off the page. Server-side flow (auth token login):- Authenticate the user in your app.
- If it’s their first time, call Create User (https://www.cometchat.com/docs/rest-api/users/create) — you can also request an auth token in that call.
- For returning users, call Create Auth Token (https://www.cometchat.com/docs/rest-api/auth-tokens/create) to issue a fresh token.
- Send the token to the browser and place it in the widget config below.
- The same token works for the CometChat Widget, UI Kit, or SDK.
Paste this near </body> in layout/theme.liquid
appID,region: Copy from Dashboard.authToken: Generate server-side after the user logs in (using CometChat Auth Token API) and output it into this snippet (e.g., from a Shopify app proxy or metafield).- UI options:
width,height,isDocked,variantID,chatType,defaultChatID,dockedAlignment.
Optional: Make credentials editable in Theme settings
Add this block toconfig/settings_schema.json (just before the final ]). Then replace hardcoded values in the snippets with {{ settings.cometchat_app_id }} etc.
Optional: Add as an Online Store 2.0 section/app block
- Online Store → Themes → Edit code.
- Under Sections, create
cometchat-widget.liquidand paste one of the snippets above. - Save, then add it in Customize theme under App embeds or as a section on any template:
Advanced JavaScript Controls
The embed works out of the box. Use the helpers below only if you need to open a specific chat, listen for widget events, or change settings on the fly.Before you follow advanced setup steps
- Keep the standard widget snippet (from the Integration guide) on your page.
- Add another
<script type="module">right after it or inside your site builder’s “custom code” area. - Wrap your code in
window.addEventListener("DOMContentLoaded", () => { ... })so it runs after the widget loads. - Replace placeholder text such as
UID,GUID, andLANGUAGE_CODEwith your real values.
CometChatApp. Every example below shows a tiny recipe you can paste inside the script mentioned above.
Open a chat or start a call
Use these helpers when you want the widget to jump straight to a person/group or begin a call. Drop the snippet inside your custom script and replaceUID/GUID with real IDs from your CometChat app.
Listen for widget events
Run your own code when something happens inside the widget—new message, docked bubble opened, or someone switching chats. Keep the event names as shown; just change what happens inside each arrow function.Create/Update users on the fly
- This will only work with authKey
Create/Update groups on the fly
If you want to create groups directly from your page, use this snippet. Replace the placeholders and run the snippet after the widget loads.Log users in or out with code
Use an auth token if you have a backend, or fall back to a plain UID for quick tests. Run these helpers after the widget loads.Control where data is stored
Pick whether the widget should remember login info in the browser tab only (SESSION) or across visits (LOCAL). Update the placeholders, then drop this script right after the default widget embed.
Change the widget language
The widget auto-detects the browser language, but you can force it to any supported locale. Run the helper once after the widget loads and swap in the language code you need.| Language | Code |
|---|---|
| English (United States) | en-US |
| English (United Kingdom) | en-GB |
| Dutch | nl |
| French | fr |
| German | de |
| Hindi | hi |
| Italian | it |
| Japanese | ja |
| Korean | ko |
| Portuguese | pt |
| Russian | ru |
| Spanish | es |
| Turkish | tr |
| Chinese (Simplified) | zh |
| Chinese (Traditional) | zh-TW |
| Malay | ms |
| Swedish | sv |
| Lithuanian | lt |
| Hungarian | hu |
CometChatApp.localize("ko") for Korean).
Troubleshooting
- Widget not appearing? Confirm the embed script loads (
chat-embed@1.x.x), the mount div exists, and no ad blockers or CSP rules are blocking it. - Shopify customer info not showing? Ensure customer accounts are enabled and you’re previewing as a logged-in shopper (not just the Theme Editor).
- Login/auth errors? For UID mode, verify the Auth Key is an App Auth Key and UIDs are unique; for auth token mode, ensure the token matches the logged-in user.
- Docked vs embedded view wrong? Adjust
isDocked,width,height, and optional alignment settings. - Still stuck? Inspect
CometChatApp.CometChatAuthcalls in the browser console for errors.