Anonymous Chat (Guest Mode)
- Visitors can chat without accounts.
- Fastest, friction-free setup.
Create + Log In User On The Fly
- Auto-create CometChat users with your existing IDs (email, user ID, etc.).
- No backend needed; CometChat creates users on first visit.
Backend-Created User (Auth Token Login)
- Use your backend to issue auth tokens.
- Keep your Auth Key off the page.
Where to place the snippet in Wix
Add it as site-level custom code, not as an Embed HTML element.- In your Wix dashboard, go to Settings → Custom Code and click + Add Custom Code.
- Paste the snippet from your chosen option below.
- Set Add Code to Pages to All pages, and Place Code in to Body – end.
- Give it a name, click Apply, then Publish your site.
- Open the published site — custom code does not run in the editor preview — and confirm the widget appears.
1. Anonymous Chat (Guest Mode)
Use this when: you want visitors to chat without signing in.Paste this into Custom Code
Update these values
2. Create + Log In User On The Fly
Use this when: you already have user IDs (email, username, member ID) and want to log people in with that ID automatically. CometChat creates the user the first time it sees the ID.Paste this into Custom Code
Update these values
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 into Custom Code
Update these values
Troubleshooting
- Widget not appearing? Custom code only runs on the published site, never in the editor preview — publish, then reload. Check the browser console for the
chat-embed@2.x.xscript and for errors from it. - Calls fail with a permission error? The snippet is almost certainly in an Embed HTML element rather than Custom Code. See the warning above.
- Login/auth errors? For UID mode, ensure the
uidis unique and you’re using an App Auth Key (not REST API key). For auth token mode, make sure the token matches the logged-in user. - Still showing guests only? Make sure you’re actually providing
uidorauthTokenin the snippet (and that your page logic passes the right IDs). - Page preview vs published: Test on a published page if preview blocks scripts.
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.login() does nothing while someone is signed in. It returns the current user and ignores
the uid you pass, because the SDK keeps its session across reloads. To change users, sign the
previous one out first: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.
init() takes appRegion; CometChatAuth.start() takes region. They are the same value under
different names, and each call rejects the other’s spelling.Change the widget language
The widget starts in the locale you set with thelanguage launch option, and falls back to en-US when you do not set one. You can switch locale at any time after load — run the helper and swap in the language code you need.
Need another locale? Use the same pattern with its code (for example
CometChatApp.localize("ko") for Korean).