Bento JavaScript SDK Guide
This guide covers integrating Bento's JavaScript SDK for client-side analytics, user tracking, and engagement features.
Client-Side Only: This SDK is designed for browser environments. For server-side tracking, use our Node.js SDK.
Additional Resources
Installation
Add the Bento tracking script to your website:
You can find your Site UUID in your Bento Account Settings.
Replace YOUR_SITE_UUID
with your actual Site UUID from Bento.
Basic Setup
Once the script loads, Bento is automatically available via the global window.bento
object:
The SDK automatically:
- Generates unique visitor and visit IDs
- Tracks the initial page view
- Handles visitor session management
Verify the integration is working:
Check your browser's developer console for Bento confirmation messages.
Page View Tracking
Page views are automatically tracked when the script loads. For single-page applications, track navigation manually:
Manual Page View Tracking
SPA Navigation Tracking
User Identification
Connect user actions across sessions by identifying users with their email:
Basic Identification
Dynamic Identification
Event Tracking
Track custom events to understand user behavior and trigger workflows:
Basic Event Tracking
Events with Data
Common Event Examples
User Tagging
Add tags to segment users and trigger targeted campaigns:
Single Tag
Multiple Tags
Custom Fields
Store additional user data for personalization and segmentation:
Basic Fields
Progressive Profiling
Survey Integration
Bento includes built-in survey functionality for collecting user feedback:
Survey Forms
Add survey forms to your HTML:
Available Survey Types
Type | Description | Use Case |
---|---|---|
popup | Modal overlay survey | Exit intent, feedback |
toaster | Small notification survey | Quick polls, ratings |
takeover | Full-screen survey | Detailed questionnaires |
inline | Embedded in page content | Content-specific forms |
Core Methods
Method | Description | Example |
---|---|---|
bento.view() | Track page view | bento.view() |
bento.identify(email) | Identify user by email | bento.identify('[email protected]') |
bento.track(event, data) | Track custom event | bento.track('signup', { plan: 'pro' }) |
bento.tag(tag) | Add tag to user | bento.tag('premium_user') |
bento.updateFields(fields) | Update user fields | bento.updateFields({ name: 'John' }) |
Utility Methods
Method | Description | Example |
---|---|---|
bento.getEmail() | Get current user email | const email = bento.getEmail() |
bento.getName() | Get current user name | const name = bento.getName() |
Survey Methods
Method | Description | Example |
---|---|---|
bento.showSurveyForm(element, id, type) | Show survey form | bento.showSurveyForm(el, 'survey-1', 'popup') |
bento.spamCheck(email) | Validate email | bento.spamCheck('[email protected]') |
Chat Methods (if enabled)
Method | Description | Example |
---|---|---|
bento.showChat() | Enable chat | bento.showChat() |
bento.hideChat() | Hide chat | bento.hideChat() |
bento.openChat() | Open chat | bento.openChat() |
Performance
Load Optimization
Event Debouncing
Prevent excessive event tracking:
Data Quality
Email Validation
Error Handling
Privacy
Conditional Tracking
Common Issues
Issue | Solution |
---|---|
Script not loading | Verify Site UUID is correct and script URL is accessible |
Events not tracking | Check browser console for errors, ensure window.bento exists |
Double tracking | Remove duplicate script tags, check for multiple installations |
CORS errors | Ensure your domain is whitelisted in Bento settings |
Debug Mode
Enable debug logging: