A PostHog transformation can save an event’s IP to a person profile, but it cannot read the profile. It runs before PostHog resolves person properties, with access to the event and project globals. Transformations also cannot make external HTTP requests. If your logic needs an existing person property, use a realtime destination. (+)
A transformation can still copy the event’s $ip into $set and $set_once on the returned event. For events with person-profile processing enabled, PostHog applies those updates during ingestion, making the visitor’s IP available for later server-side conversions. (+)
Choose where the visitor’s IP comes from
A billing webhook, renewal or backend order sent without the visitor’s IP gets the sending server’s IP as $ip. PostHog keeps an event-supplied $ip; otherwise it uses the capture request’s IP. (+)
Ad platforms use the visitor’s IP as a matching signal. (+) Our overview of PostHog’s ad destinations explains the other matching fields and how the six platforms differ.
- Conversion sent while handling the visitor’s request: put the visitor’s IP on that event as
$ip. This is the simpler route when your backend still has the request context. - Conversion sent later, without a visitor request: save the IP on the person using the transformation below, then change the destination’s IP mapping to read it. This covers a delayed report of something the visitor did, such as a purchase a billing webhook confirms later.
An automatic renewal has no visitor behind it. Send it as a system-generated event where the platform has one, such as Meta’s system_generated action source, and leave the saved browser context out rather than presenting an old IP as current. (+)
Before you start: IP retention and consent
IP addresses can be personal data. New projects in PostHog Cloud EU default to discarding client IPs. (+)
In Settings → Project → Privacy, find IP data capture configuration. (+) The Discard client IP data toggle removes $ip from stored events, leaving destinations that read it from the event without a visitor IP. In cookieless server hash mode, the IP is removed before transformations run, so this method has nothing to copy. (+)
Transformations and person updates run before the IP is removed from the event, so this transformation can retain the IP on the person even when the project discards it from events. (+ / +) The copy also stays on the stored event: Discard client IP data removes only the event’s own $ip, and in our test on 24 November 2026 the IP in $set and $set_once remained. From 30 November 2026, PostHog keeps those for 60 days after it receives the event. (+) Do not store IPs on people in a project configured to discard them unless your lawful basis covers that retention.
1. Check that your events have $ip
Open a recent browser $pageview in PostHog and inspect its event properties. Confirm $lib is web and $ip is the visitor’s address. (+)
If $ip isn’t there, check the IP retention settings before changing your tracking or proxy. With Discard client IP data on, stored events show no $ip even though the transformation still receives it: test the transformation with your own event in Step 5, then check the person after an identified visit. If the address belongs to your server or proxy, fix how the visitor’s IP reaches PostHog. The transformation can’t invent the IP.
2. Create a custom transformation
3. Configure when the transformation runs
- In Filters, require Library (
$lib) to equalweb. - Also require IP address (
$ip) is set. - Under Match events, select
$pageviewor$identify. If you use a custom pageview event, select that instead of$pageview. (+)
The IP filter only excludes missing values. Backend events can carry the server’s IP; the $lib = web filter is what excludes those events. Without it, server events can overwrite the person’s saved visitor IP. Add a filter for the consent property recorded by your consent tool if consent is required.
With the default person_profiles: 'identified_only', anonymous pageviews cannot update person properties: PostHog strips their $set and $set_once, and no profile is created. Including $identify saves the IP when the visitor is identified; qualifying pageviews update it afterwards. The first saved IP is therefore from identification onwards, not necessarily the first anonymous visit. (+ / +)
4. Add the transformation code
Open Edit source code and paste this Hog. It copies the read-only event, modifies the copy and returns it. (+)
let ip := event.properties?.$ip
let returnEvent := event
returnEvent.properties := returnEvent.properties ?? {}
returnEvent.properties.$set := returnEvent.properties.$set ?? {}
returnEvent.properties.$set_once := returnEvent.properties.$set_once ?? {}
returnEvent.properties.$set.$ip := ip
returnEvent.properties.$set_once.$initial_ip := ip
// Keep the browser's user agent beside the IP, under its own name,
// so a later server event cannot overwrite it.
returnEvent.properties.$set.visitor_user_agent := event.properties?.$raw_user_agent
return returnEvent
$set.$ip keeps the latest qualifying IP, and $set.visitor_user_agent the browser’s user agent from the same event. $set_once.$initial_ip preserves the first seen IP. Both follow ingestion order: “first” means the first value PostHog processes, not the earliest event timestamp. (+)
5. Test and enable the transformation
- In the transformation’s test panel, load a browser event containing
$ip, or supply your own event JSON. (+) - Run the test and confirm that the returned
$set.$ipand$set_once.$initial_ipmatch the input IP. - Enable the transformation and click Create; for an existing transformation, click Save. (+)
For example, load an $identify event and replace its properties object with:
{
"$lib": "web",
"$ip": "203.0.113.9",
"$raw_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)"
}comes back from the test with these additions to its properties:
"$set": {
"$ip": "203.0.113.9",
"visitor_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)"
},
"$set_once": {
"$initial_ip": "203.0.113.9"
}Every enabled transformation in the project runs on events that pass its filters. There is no source or destination to attach. (+)
6. Verify an identified visit
- Visit your site, accept tracking if required, and complete the flow that calls
identify(). - Find the browser
$identifyevent in PostHog and open its linked person profile. - Confirm the person has
$ip,$initial_ipandvisitor_user_agent. A later qualifying pageview can update$ip;$initial_ipstays as the first captured IP because of$set_once.
PostHog keeps $set and $set_once on stored events; from 30 November 2026, for 60 days after it receives them. (+) To check the transformation, read its returned payload in the test panel and the saved values on the person profile.
7. Use the saved IP in your destination
Saving the IP does not change the destination’s mapping. Pinterest, Snapchat and TikTok default to event.properties.$ip; Reddit’s default hashes it under an ip key that Reddit does not define. Meta and Google Ads have no default IP field. None of the six reads person.properties.$ip automatically. (+)
When your non-web events have no visitor request behind them, use this IP mapping and check the resolved value in the destination’s test panel. A browser event falls back to the saved IP when Discard client IP data has removed its own:
{event.properties.$lib == 'web' ? (event.properties.$ip ?? person.properties.$ip) : person.properties.$ip}
Use the raw expression for User data → client_ip_address in Pinterest or Snapchat, or User properties → ip in TikTok. For Reddit’s User parameters, replace the default ip entry with ip_address and this expression; Reddit defines no ip user field. (+) For Meta, add client_ip_address to User data. (+) Our Meta destination guide covers the other matching fields. Google Ads has no IP input in this template.
If your backend already puts the visitor’s IP on a conversion event, keep reading it from the event in that mapping. The saved IP is from the last qualifying browser event, so it can be out of date by the time a delayed report arrives.
Send the browser’s user agent with that IP: Meta requires it for website events (+), and Pinterest and Snapchat use the IP for matching only together with the user agent. PostHog copies $raw_user_agent onto the person from processed events, so a server event can replace the browser’s value (+); the visitor_user_agent property the transformation saves comes only from browser events. Map the user agent the same way as the IP:
{event.properties.$lib == 'web' ? event.properties.$raw_user_agent : person.properties.visitor_user_agent}With Discard client IP data on and the destination still reading the IP from the event, Snapchat skips sending when both email and phone are absent, without logging the skip. Pinterest logs a skip unless it has email, a mobile ad ID, or both an IP address and a user agent. (+)
Use the same distinct_id for the browser and billing events, and make sure the browser’s IP write is processed first. A destination reads person properties as they are when it processes the conversion; identifying or setting the IP later does not add it to that earlier conversion. (+)
Test a browser event, a billing event and an event for a person with no saved IP. Inspect the resolved IP and user agent rather than substituting a server address when the saved value is missing. Turn off Make real HTTP requests while checking mappings so the test does not send a conversion. (+)
These six ad destination templates are experimental, without official customer support. (+) Verify delivery in the ad platform after checking the mappings, and retest any template changes.
RevenueCat and other billing events
If a RevenueCat event arrives without its own $ip property, PostHog uses the address of RevenueCat’s sending server. (+)
RevenueCat’s reserved $ip attribute is the device’s IP. It is a device identifier that cannot change once set, so it describes the original installation, not necessarily the current network. (+) Its PostHog integration includes customer attributes under subscriber_attributes. Inspect event.properties.subscriber_attributes.$ip on a real billing event before using that path in a mapping; confirm that the value is present and is an IP string. (+)
RevenueCat attaches its events to a PostHog person through the $posthogUserId attribute and falls back to its own app user ID without it. Make sure RevenueCat’s app user ID matches the distinct ID your site identifies, or set $posthogUserId to that ID, so its events reach the person holding the saved IP. (+)
Also check whether GeoIP enrichment updates the person’s location from these server events. If it does, set $geoip_disable: true on those events or exclude them from the GeoIP transformation. (+)
Frequently asked questions
Does PostHog automatically save $ip on the person?
Will this backfill existing person profiles?
No. Transformations only apply to new incoming events. An existing profile gets these properties when another qualifying event arrives; enabling the transformation does not backfill it. (+)
What if multiple users share the same IP?
They stay separate people. PostHog associates people through distinct IDs, not IP addresses, so keep a separate identity for each person and do not use their IP as the distinct ID. (+)
Does this work with reverse proxies or server-side rendering?
Yes, if the visitor’s IP reaches PostHog. Behind a reverse proxy, forward X-Forwarded-For so the original IP is preserved (+). For events captured during server-side rendering, put the visitor’s IP on the event as $ip yourself. An event that arrives without a real client IP cannot be fixed by the transformation.
Do I need consent before saving a visitor’s IP on the person?
It depends on your basis for processing. If you require consent, you must only set IP after the user accepts tracking. (+) Apply that consent decision to outgoing billing events too: opting out the browser SDK does not stop a separate server from sending events, so filter destinations using your recorded consent. (+)
Can I set other person properties the same way?
Yes. The same pattern applies to custom user traits already present on an event, subject to the same requirements for person profiles and consent. Just add extra $set / $set_once keys inside the transformation code. (+) Our person properties guide explains how $set and $set_once behave and when a visitor has a person profile.

