DEV Community

Samee Ullah
Samee Ullah

Posted on

How I Automatically Capture the Country of Newsletter Leads in GoHighLevel (GHL)

How I Automatically Capture the Country of Newsletter Leads in GoHighLevelIf you're using GoHighLevel (GHL) to collect newsletter subscribers, your form probably only asks for an email address. Keeping forms short is great for conversions, but it also means you miss useful information like the visitor's country.

I recently needed a way to identify the country of newsletter subscribers without asking them to fill out another field. After testing a few approaches, I found a simple solution that automatically detects the visitor's country and saves it inside GoHighLevel using a hidden custom field.

In this article, I'll show you exactly how to set it up.

The Problem

Most newsletter forms look something like this:

  • Email Address

Or maybe:

  • First Name

  • Email Address

That's enough to collect subscribers, but it doesn't tell you where they are from.

Without the country, you cannot:

  • Send country specific email campaigns.

  • Build location based automations.

  • Segment your audience by country.

  • Understand where your subscribers are coming from.

If you have subscribers from different countries, this data can be very valuable.

The Solution

Instead of asking visitors to select their country manually, we can detect it automatically using their public IP address.

The process is simple:

  1. Create a hidden custom field in GoHighLevel.

  2. Add that field to your newsletter form.

  3. Detect the visitor's country using JavaScript.

  4. Save the country into the hidden field before the form is submitted.

The subscriber only enters their email address, while GoHighLevel stores the country in the background.


Step 1: Create a Custom Field in GoHighLevel

Go to:

Settings → Custom Fields

Create a new custom field.

Field Name

Country Tracker
Enter fullscreen mode Exit fullscreen mode

Field Type

Single Line Text
Enter fullscreen mode Exit fullscreen mode

Save the custom field.

This field will hold the detected country for every newsletter subscriber.


Step 2: Add the Custom Field to Your Newsletter Form

Open your GoHighLevel newsletter form.

Add the newly created Country Tracker field.

Since visitors should never see it, set the field to Hidden.

Your subscribers will never interact with this field, but the value will still be submitted with the form.


Step 3: Find the Hidden Input ID

Now we need the HTML ID of that hidden field.

Open the page containing your form.

Right click and choose Inspect.

Inside the Elements tab, search for one of these:

country_tracker
Enter fullscreen mode Exit fullscreen mode

or

Country Tracker
Enter fullscreen mode Exit fullscreen mode

Eventually you'll find something similar to this:

<input
    id="tkSh7iX8ZeTa1BDUJtjK"
    data-q="country_tracker"
    type="text">
Enter fullscreen mode Exit fullscreen mode

Copy the value from the id attribute.

In this example, the ID is:

tkSh7iX8ZeTa1BDUJtjK
Enter fullscreen mode Exit fullscreen mode

You will replace the ID inside the JavaScript with your own if it is different.


Step 4: Add the JavaScript

Place this script on the page where your GoHighLevel form is embedded.

fetch("https://ipwho.is/")
  .then(response => response.json())
  .then(data => {

    const countryField = document.getElementById("tkSh7iX8ZeTa1BDUJtjK");

    if (countryField) {
      countryField.value = data.country;

      countryField.dispatchEvent(new Event("input", { bubbles: true }));
      countryField.dispatchEvent(new Event("change", { bubbles: true }));

      console.log("Country saved:", data.country);
    }

  })
  .catch(console.error);
Enter fullscreen mode Exit fullscreen mode

Once the page loads, the visitor's country is detected automatically.

When the form is submitted, the hidden field is submitted with it.


Example

A visitor from Australia subscribes to your newsletter.

They only enter:

john@example.com
Enter fullscreen mode Exit fullscreen mode

Behind the scenes, the script automatically stores:

Country Tracker: Australia
Enter fullscreen mode Exit fullscreen mode

Inside GoHighLevel, the contact now contains both the email address and the detected country.

No additional fields were shown to the visitor.


Why This Is Useful

Personalize Email Campaigns

Create different email sequences based on where subscribers live.

For example:

  • United States

  • Canada

  • Australia

  • United Kingdom

Each audience can receive content that is more relevant to them.

Build Better Workflows

The Country Tracker field can be used inside GoHighLevel automations.

Examples include:

  • Apply country specific tags.

  • Send localized newsletters.

  • Route contacts to different teams.

  • Trigger different workflows.

Better Audience Analytics

You can quickly identify which countries generate the most subscribers.

This makes it easier to measure campaign performance and discover new opportunities.

Keep Your Forms Simple

Newsletter forms should stay short.

Instead of asking visitors to choose their country manually, everything happens automatically in the background.

That means fewer fields and a better user experience.


Final Thoughts

If you've been looking for how to get the country of the lead in GHL or how to get lead country via form, this approach is simple to implement and works well for newsletter forms that only collect an email address.

By creating a hidden Country Tracker custom field, adding it to your GoHighLevel form, finding the input ID, and using a small JavaScript snippet, you can automatically save every subscriber's country.

Once the country is stored, you can build smarter automations, create personalized email campaigns, and better understand your audience without asking visitors for any extra information.

If you have another approach for capturing lead location in GoHighLevel, I'd love to hear about it in the comments.

Top comments (0)