Skip to main content

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:
You can customize the container ID, but make sure it matches the element you pass to the widget constructor.
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
Use direct integration when you already have address data from a previous form, user profile, or application state.

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:
For complete field specifications, see the Address Data Format section in the overview.

Address Validation

The widget validates addresses using these rules:
  • street1: Primary address (street number and name)
  • zip: 5 or 9-digit ZIP code format (12345 or 12345-6789)
  • 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
  • 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

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
Expected behavior: The widget should initialize within 2-3 seconds of calling hum.initialize().
Common address issues:
  • Ensure the required fields (street1 and zip) are provided
  • Include city and state when 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
Expected behavior: Valid addresses should return service options within 5-10 seconds.
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
Expected behavior: The widget should load service options in under 10 seconds for most addresses.
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
Expected behavior: The widget should integrate seamlessly without affecting other page functionality.
If issues persist, check the browser console for detailed error messages and contact support with the specific error details.

Best Practices

Always implement proper error handling for API calls:
Use loading states to improve user experience:
  • Load the widget script asynchronously
  • Include latitude/longitude coordinates for faster results
  • Cache widget instances when using multiple widgets
  • Monitor console logs during development
  • 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