Geolocation Enrichment using Transformations

Fetch geolocation information from IP address using RudderStack’s geolocation service.
Available Plans
  • growth
  • enterprise

info
The most reliable way to enrich events with geolocation information is using RudderStack’s Geolocation Enrichment at Source feature.

This guide explains how to enrich events with users’ geolocation information using transformations.

Overview

You can add a geolocation service function (geolocation) in your transformation takes the IP address present in the event (request_ip) as an argument. RudderStack supports both JavaScript and Python transformations for this feature.

The transformation returns the following geolocation data once it runs successfully:

  • City
  • Country
  • Region
  • Location
  • Postal code
  • Timezone

See Runtime Functions in Transformations for more information on using the geolocation function.

License

This product includes GeoLite2 data created by MaxMind, available from https://www.maxmind.com.

For more information, see Maxmind license agreement.

info
RudderStack does not call the MaxMind API to get the geolocation data. Instead, the MaxMind database is embedded in RudderStack’s service and is served via RudderStack’s own API.

Usage

announcement
If you’re hosting RudderStack on-premise, contact RudderStack Support to use this feature.

To use the geolocation service, add a new transformation as shown:

In the above transformation, the geolocation service function geolocation takes the IP address present in the event (request_ip) as an argument. Once it runs successfully, it returns the following geolocation data:

  • City
  • Country
  • Region
  • Location
  • Postal code
  • Timezone
warning

Note that:

  • The geolocation data provided by RudderStack powered by Maxmind is not 100% accurate and varies by country. See the Maxmind website (link: https://www.maxmind.com/en/geoip2-city-accuracy-comparison) to get the accuracy information by country.

  • RudderStack returns a 400 Bad Request error if you pass a malformed IP address.

  • If you currently use a geolocation enrichment template, switching to this transformation will result in some schema changes:

    • RudderStack creates new columns for the IP addresses in your warehouse.
    • It stores the country code instead of country name.
Geolocation information

FAQ

How is this feature different from the geolocation enrichment transformation template?

RudderStack’s geolocation service feature lets you enrich events with users’ geolocation information for a given IP address by leveraging the licensed GeoLite2 data created by MaxMind.

On the other hand, the geolocation enrichment template enriches events with geolocation data using an IP-to-geolocation API endpoint that you need to provide.


Questions? We're here to help.

Join the RudderStack Slack community or email us for support