JavaScript Widget Integration
The Hum widget can be embedded directly into your website with just a few lines of JavaScript and HTML. This integration method is ideal for web applications, landing pages, and any environment where you have control over the HTML and JavaScript.This guide covers the JavaScript/HTML embed integration. For mobile app WebView integration, see WebView Integration.
To test with a Sandbox key, load the Sandbox widget bundle instead of the Production bundle shown below. See Environments and API Keys.
Quick Start
Get up and running with the Hum widget in three simple steps:1
Add the Widget Container
Add a container div where you want the widget to render:
2
Include the Widget Script
Load the Hum widget script in your HTML page:
The script loads asynchronously and is hosted on a CDN for optimal performance.
3
Initialize the Widget
Initialize the widget with your API key:
Verify the widget loads by checking your browser’s developer console for any error messages.
Configuration
The Hum widget accepts an optional configuration object as the third parameter. For a complete list of available options, see the Widget Overview.Basic Configuration Example
Advanced Configuration Example
Here’s an example with all available options:Integration Examples
Example 1: Form-Based Integration
Integrate the widget with an HTML form for address input:A
campaign_id field inside widget address data is ignored. Set campaign attribution with the widget’s campaignId configuration option.index.html
Test your integration by entering a valid US address and verifying that service options load correctly.
Example 2: Direct Address Loading
Load address data directly when you already have the information:direct-integration.html
Example 3: React Integration
Integrate the Hum widget into a React application:HumWidget.jsx
Example 4: Vue.js Integration
Integrate the widget into a Vue.js application:HumWidget.vue
Address Data Format
The widget expects address data in a specific JSON format:Address Validation
The widget validates addresses using these rules:Required Field Validation
Required Field Validation
- street1: Primary address (street number and name)
- zip: 5 or 9-digit ZIP code format (12345 or 12345-6789)
Optional Field Validation
Optional Field Validation
- street2: Unit/apartment information (no specific format required)
- city: City name (recommended for improved address match quality)
- state: 2-letter US state code (recommended for improved address match quality)
- latitude/longitude: Must be provided together and within US territorial bounds
Additional Validation Rules
Additional Validation Rules
- Address must be geocodable by our system
- Address must be serviceable by at least one provider
- Coordinates must be within the bounds of the US and its territories
Troubleshooting
Widget Not Loading
Widget Not Loading
Check these common issues:
- Verify the container div exists on the page
- Ensure the widget script loads before your initialization code
- Check that your API key is valid and properly formatted
- Look for JavaScript errors in the browser console
hum.initialize().Address Validation Errors
Address Validation Errors
Common address issues:
- Ensure the required fields (
street1andzip) are provided - Include
cityandstatewhen available to improve address match quality - Verify the state is a valid 2-letter US state code
- Check that the ZIP code is in the correct format (12345 or 12345-6789)
- Make sure the address is a real, serviceable US address
Performance Issues
Performance Issues
Optimization tips:
- Include latitude and longitude coordinates when available
- Use the summary layout for faster loading when full e-commerce isn’t needed
- Ensure the widget script is loaded asynchronously
- Check network connectivity and CDN availability
Integration Problems
Integration Problems
Common integration issues:
- Verify the widget instance is stored globally if accessed by other scripts
- Check for conflicts with other JavaScript libraries
- Ensure proper error handling for failed API calls
- Verify the container element is visible and properly sized
Best Practices
Error Handling
Error Handling
Always implement proper error handling for API calls:
Loading States
Loading States
Use loading states to improve user experience:
Performance Optimization
Performance Optimization
- Load the widget script asynchronously
- Include latitude/longitude coordinates for faster results
- Cache widget instances when using multiple widgets
- Monitor console logs during development
User Experience
User Experience
- Test with various address formats and edge cases
- Provide clear error messages
- Use appropriate layouts for your use case
- Include campaign IDs for better tracking
Next Steps
Widget Hooks
Learn how to listen for and handle events from the widget
Configuration Options
Explore all available configuration parameters
WebView Integration
Integrate the widget into mobile applications
Get Support
Contact our team for integration assistance
