Anonymous Chat (Guest Mode)
- Visitors can chat without accounts.
- Fastest, friction-free setup.
Create + Log In User On The Fly (Squarespace Members)
- Auto-create CometChat users for Squarespace members.
- Falls back to guests for non-members.
Backend-Created User (Auth Token Login)
- Maximum security; no authKey in the browser.
- Use your backend to issue auth tokens.
Steps to Add Custom Code in Squarespace (via Code Injection)
- Log in to Squarespace and open your website dashboard.
- In the left sidebar, click Website (top-left) and select the site.
- Scroll to Marketing Tools and click Custom Code.
- Click Code Injection.
- You’ll see Header and Footer. Paste your chosen integration snippet into Footer.
- Click Save.
- Refresh your site and open a page to confirm chat loads.
1. Anonymous Chat (Guest Mode)
Use this when:- You want visitors to chat without creating accounts.
- You don’t have a member area or user authentication.
- You want quick, friction-free chat access.
Paste this into Footer (Code Injection)
appID,region,authKey: Copy from Dashboard.user.name,user.avatar,user.link: Optional guest display info.width,height,isDocked: Widget dimensions (isDocked = true= floating icon;false= embedded).
2. Create + Log In User On The Fly (Squarespace Members)
Use this when:- You have Squarespace Member Areas enabled.
- You want members to automatically get CometChat accounts.
- You want to support both members and guest visitors.
Paste this into Footer (Code Injection)
- Detects Squarespace members via the
SiteUserInfocookie. - Creates CometChat users on-the-fly when members first visit; falls back to guest for others.
- Persists guest IDs in
localStorageto keep a consistent identity.
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.
- You need maximum security (no authKey exposed in the frontend).
- You have a custom backend or serverless functions.
- You want full control over user creation and authentication.
Paste this into Footer (Code Injection)
appID,region,authKey| Copy from Dashboard.authToken| Generated by your backend and passed to this page.width,height,isDocked| Adjust widget dimensions/placement.
Troubleshooting
- Widget not appearing? Verify App ID, Region & Auth Key (or auth token), and check browser console for CSP/ad-blocker errors.
- Login fails? For UID mode, ensure the
uidexists or is created on first visit; for auth token mode, make sure the token matches the logged-in user. - Styling issues? Add custom CSS in Design → Custom CSS to override defaults.
- Page-specific placement? Use a page-level Code Block instead of the global Footer if you only want it on one page.
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).