Widget Installation
Add Hal to your website in minutes
Installing the Widget
The Hal widget is a lightweight JavaScript file that creates a chat interface on your website.
Basic Installation
Add this code just before the closing </body> tag:
<script src="https://api.chatwithhal.com/widget.js" data-app-id="your-app-id"></script>
Replace your-app-id with your actual App ID from the Settings page.
Advanced Configuration
For more control, use the HalSettings object:
<script>
window.HalSettings = {
appId: 'your-app-id',
// Optional: Identify the visitor
visitorId: 'user-123', // Your system's user ID
name: 'John Doe', // Display name
email: 'john@example.com', // Email address
// Optional: Custom attributes
metadata: {
plan: 'pro',
signupDate: '2024-01-15'
}
};
</script>
<script src="https://api.chatwithhal.com/widget.js"></script>
Configuration Options
| Option | Type | Description |
|---|---|---|
appId |
string | Required. Your Hal App ID |
visitorId |
string | Unique identifier for the visitor. If not provided, Hal generates one and stores it in localStorage. |
name |
string | Visitor's display name |
email |
string | Visitor's email address |
metadata |
object | Custom key-value pairs for context |
Data Attributes
You can also configure the widget using data attributes on the script tag:
| Attribute | Type | Description |
|---|---|---|
data-app-id |
string | Required. Your Hal App ID |
data-server-url |
string | Custom server URL (for self-hosted or local development) |
data-open |
"true" | Open the widget automatically when the page loads |
data-open-delay |
number | Delay in milliseconds before auto-opening (requires data-open="true") |
data-locale |
string | Override the browser's locale (e.g., "en", "de", "fr") |
Auto-open Widget
You can automatically open the chat widget when the page loads. This is useful for:
- Proactive support on key pages (pricing, checkout)
- Onboarding flows where you want to prompt engagement
- Landing pages with a support focus
Open immediately:
<script src="https://api.chatwithhal.com/widget.js" data-app-id="your-app-id" data-open="true"></script>
Open after a delay (e.g., 3 seconds):
<script src="https://api.chatwithhal.com/widget.js" data-app-id="your-app-id" data-open="true" data-open-delay="3000"></script>
Visitor Identification
Hal can track visitors in two ways:
- Anonymous visitors: Hal generates a random ID and stores it in localStorage. Returning visitors will see their previous conversations.
- Identified visitors: Pass your own
visitorId(e.g., their user ID in your system) to link conversations to specific users.
Hal.identify() to update their information without reloading the page.
Dynamic Identification
Update visitor info after the widget loads:
// After user logs in
Hal.identify({
visitorId: user.id,
name: user.name,
email: user.email,
metadata: {
plan: user.subscription.plan
}
});
Single Page Apps (SPA)
The widget works automatically with React, Vue, Angular, and other SPAs. It loads once and persists across route changes.
To re-identify a user after login/logout:
// After login
Hal.identify({ visitorId: user.id, name: user.name });
// After logout
Hal.reset(); // Clears visitor data and creates new anonymous session
Testing Locally
When developing locally, set the server URL:
<script src="http://localhost:8001/widget.js" data-app-id="your-app-id" data-server-url="http://localhost:8001"></script>