Problem

Our sales team handled inbound leads across multiple geographies, but routing them to the correct regional sales representative was inconsistent and manual. Leads often entered the CRM without standardized location data, requiring manual sorting by the RevOps or SDR teams.

Solution

Instead of introducing third-party enrichment tools or building a complex routing engine, I leveraged existing HubSpot form capabilities along with HubSpot’s location detection endpoint.

The approach focused on:

  • Automatically capturing the visitor’s ISO country code
  • Passing the value into a hidden form field
  • Using the captured value for downstream lead routing and assignment workflows

This allowed us to create an automated and reliable routing mechanism without additional software costs or operational complexity.

Implementation

I implemented a JavaScript-based solution that executes when the HubSpot form loads.

Process Overview:

  1. The script listens for the HubSpot form readiness event.
  2. It calls HubSpot’s location detection endpoint to fetch the visitor’s ISO country code.
  3. The returned country code is automatically populated into a hidden form field.
  4. HubSpot workflows then use this hidden field to assign leads to the correct regional sales representative.

Key Code Used:

window.addEventListener(‘hs-form-event:on-ready’, function (event) {
const form = HubSpotFormsV4.getFormFromEvent(event);

fetch(“https://js-na2.hs-banner.com/v2/cf-location”)
.then(res => res.text())
.then(code => {
const iso = code.trim();
if (iso) form.setFieldValue(‘0-1/iso_country_code’, iso);
})
.catch(err => console.error(“ISO country lookup failed:”, err));
});

Results

The automation significantly improved lead management efficiency and sales response speed.

Key Outcomes:

  • Eliminated manual geographic lead sorting.
  • Improved speed of lead assignment to sales representatives.
  • Reduced dependency on external enrichment tools.

View other case studies