Dynamic content based on locale or IP Address

  • Is it possible to have dynamic content based on where the user is coming from? (Locale, known user IP address, etc.)
  • ex: A page may say something about a specific country if their IP address is from that country while something different if their IP address is in the US

I know in Builder you have the ability to localize fields, whole entry, and data model. But is there anyway for say using a user’s IP address to show dynamic content. So if the user visits a page it will show dynamic content without using localized urls?

Hi Tracy​,

You can show dynamic content in Builder.io based on the user’s IP address (e.g., for geolocation or locale targeting) without requiring localized URLs. However, remember that this feature is part of the Enterprise plan.

Builder allows you to pass custom user Attributes when fetching content, and these attributes can be used in targeting rules for content entries. For example, you can pass the user’s country code, region, city, etc., obtained from their IP address.

Step-by-Step Example:

  1. Detect User’s Geolocation (e.g., server-side or with a geolocation API)

You can use a service like IPinfo, ipapi, or any other to detect the user’s location server-side.

// Example: server-side (Next.js API route or middleware)
const geo = await fetch('https://ipapi.co/json').then(res => res.json());
const country = geo.country_name; // e.g., 'USA'

2. Pass userAttributes to Builder

When calling builder.get() or fetchOneEntry(), pass userAttributes including country, locale, or any other relevant data:

builder
  .get('announcement-bar', {
    userAttributes: {
      urlPath: '/home',
      country: geo.country_name, // Example: 'USA'
      ip: geo.ip,
    },
  })
  .toPromise()
  .then(content => {
    // Render content with <BuilderComponent content={content} />
  });

3. Set Up Targeting in Builder UI

Inside the Builder UI:

  • Open your content entry (e.g., section, page).
  • Click the Targeting icon (looks like a target).
  • Set a condition like:
Where country equals "USA"

You can add multiple versions of the same content, each targeting different countries or regions.

Thank you,