❤️
AppsFlyer knows where your users came from. PostHog knows what they did next. Here is how to get them talking.
AppsFlyer and PostHog are often found in the same stack, but they rarely talk to each other. That is a missed opportunity. One tells you where your users came from, the other tells you what they did after they arrived.
In this article we first look at what each platform does well. Then we focus on PostHog and show how to get more out of it by connecting it to AppsFlyer: pulling AppsFlyer data into the PostHog data warehouse, sending PostHog events back to AppsFlyer, and enriching PostHog with attribution data at the source.
At a glance
-
1Data warehouse Native AppsFlyer to PostHogManaged AppsFlyer source for aggregate reports, raw installs and in-app events, and ad revenue.
-
2Destinations Custom PostHog to AppsFlyerPostHog has no native AppsFlyer destination, so build it yourself with a webhook or custom Hog function.
-
3SDK enrichment Native AppsFlyer to PostHogHand the AppsFlyer SDK’s conversion data and AppsFlyer ID to the PostHog SDK in the app.
What each platform is good at (and where it falls short)
AppsFlyer attributes installs and in-app events to the campaign, network and creative that caused them.
Where it shines
- Attribution across ad networks: Installs and re-engagements are matched to media sources, including privacy-preserving iOS measurement (SKAdNetwork).
- Fraud protection: Protect360 filters out invalid installs and events before they pollute your numbers.
- Deep linking: OneLink routes users from ads, email, web or QR codes to the right place in your app, keeping the attribution context.
- Partner postbacks: Conversions are sent back to ad networks so their algorithms can optimize.
Where it falls short
- Limited product analytics: AppsFlyer is built to answer marketing attribution questions. Funnels over many product events, session replay, feature flags and experimentation are outside its scope.
- Data access is gated: Raw, user-level exports depend on your package (Data Locker is a premium feature), while PostHog’s SQL editor queries every event and person you have sent.
- Short memory for raw data: The Pull API serves raw data for roughly the last 90 days, and Data Locker keeps its files for 14 days. Long-term, user-level history needs a warehouse of your own.
PostHog combines product and web analytics, session replay, feature flags, experiments and a data warehouse in one place. Want to know more? Read about our PostHog services.
Where it shines
- Event-level analytics: Funnels, retention, paths and cohorts on every event you send, including person-level data.
- Everything in one tool: Replay, flags and experiments run on the same data as your insights. Native SDKs exist for iOS, Android, React Native and Flutter.
- Composable data: You can query PostHog data and imported external tables together with SQL, and stream events out with destinations.
Where it falls short
- No install attribution: PostHog does not match installs and re-engagements to media sources, and it has no SKAdNetwork support for iOS. On web it reads UTM parameters, but in a native app it has no idea which ad brought the user in unless you tell it.
- No attributed deep links: Without something like OneLink, links from ads, email or QR codes (including deferred deep links after an install) do not carry the campaign context into your app.
- No ad network postbacks: PostHog cannot report conversions back to ad networks, so their algorithms cannot optimize on what users do in your app.
❤️ The synergy in short ❤️
AppsFlyer is the source of truth for acquisition (who brought the user, and how much it cost). PostHog is the source of truth for behavior (what the user did, and why they dropped off). Connect them and you can finally answer questions like: which campaign brings users who actually subscribe?
Pull AppsFlyer data into the PostHog data warehouse
PostHog has a managed AppsFlyer source for its data warehouse. That means AppsFlyer data lands next to your PostHog events and persons, where you can query it with SQL, build insights and put it on dashboards.
What you need
- An AppsFlyer account with an active Pull API subscription
- Your AppsFlyer API token (V2)
- The App ID (for example
id123456789for iOS orcom.example.appfor Android)
In PostHog, you can link AppsFlyer by creating a new source in the PostHog data warehouse. Enter the App ID and API token, select your tables, set the sync method and frequency, and click Import.
Which tables are available
The AppsFlyer source covers a total of 17 tables:
- Aggregate reports:
daily_report,geo_reportandpartners_report - Installs and in-app events:
installs,installs_organic,installs_retargeting,in_app_events,in_app_events_organic,in_app_events_retargetinganduninstall_events - Protect360 fraud:
blocked_installs,blocked_in_app_eventsandpost_attribution_installs - Ad revenue:
ad_revenue,ad_revenue_organicandad_revenue_retargeting - LTV:
master_report
Aggregates are great for campaign-level reporting. The raw install and event tables let you work at user level. Note that there are no SKAdNetwork tables: SKAN data is aggregated by design, so iOS installs that AppsFlyer only knows through SKAN never show up at user level.
What to watch out for
- Daily report excludes cost: AppsFlyer’s
daily_reporthas no cost columns. Total cost lives in thepartners_report, so a join is necessary to retrieve costs from connected ad managers. - One app per source: If you have multiple apps (or iOS and Android separately), create a source for each.
- Trailing two days: AppsFlyer attributions show up within minutes, but a day’s numbers are not final until about 48 hours after the UTC day. Each incremental sync therefore re-fetches the last two days and merges duplicates. Don’t panic when yesterday’s numbers change.
- History: The first sync can go back around 1,000 days, the maximum window of AppsFlyer’s aggregate Pull API. AppsFlyer’s raw data reports only cover roughly the last 90 days, so the sooner you start syncing the raw tables, the more user-level history you keep.
- Cost: Warehouse rows count towards your PostHog usage. See the pricing page for current allowances.
Use case A: blended campaign reporting
Join AppsFlyer spend and installs with PostHog conversions at campaign level, to get a cost per conversion.
Illustrative example. Table and column names depend on your source prefix and sync settings.
SELECT
af.campaign,
af.installs,
af.cost,
ph.signups,
round(af.cost / ph.signups, 2) AS cost_per_signup
FROM (
SELECT campaign, sum(installs) AS installs, sum(total_cost) AS cost
FROM appsflyer_partners_report
WHERE date >= today() - 30
GROUP BY campaign
) AS af
LEFT JOIN (
SELECT properties.af_campaign AS campaign, count(DISTINCT person_id) AS signups
FROM events
WHERE event = 'signed_up' AND timestamp >= now() - INTERVAL 30 DAY
GROUP BY campaign
) AS ph ON af.campaign = ph.campaign
ORDER BY af.cost DESCThe af_campaign property is something you need to set yourself (see section 3). Without a common key, the join falls apart.
Use case B: user-level joins
With the raw install and in-app event tables you can join on a shared user key. AppsFlyer rows carry the AppsFlyer ID and, if you set it in the app, your own Customer User ID. In PostHog you can add a join from the persons or events table to the AppsFlyer table, so the AppsFlyer fields become available in filters, breakdowns and SQL. This enables questions such as:
- Retention by media source or campaign
- Revenue per user by acquisition channel
- Which creatives bring users that reach your activation event
There is one catch: a person join is only resolved when a query runs, so feature flags, experiments and surveys cannot see it. If you want to target on acquisition data, either copy the columns onto person properties with PostHog’s warehouse properties (in beta, matched on distinct ID, and every updated person counts as an event) or send the data from the app (section 3).
Hedgehog tip
Use the same user identifier in AppsFlyer (
customer_user_id) and in PostHog (identify), and store the AppsFlyer ID as a PostHog person property. Fixing identity later is painful and rarely complete.
Other warehouse routes
If the managed source does not fit your setup (for example, you need hourly raw data or reports the Pull API does not offer), Data Locker, AppsFlyer’s premium raw data export, gives you two more routes:
- Data Locker to your own bucket: Let Data Locker write to your own Amazon S3 or Google Cloud Storage bucket and link that bucket as a PostHog S3 or GCS source. PostHog reads CSV, Parquet, JSON Lines and Delta Lake files (gzipped too) and copies them in on a schedule.
- Data Locker to BigQuery: Data Locker can also write straight into a BigQuery dataset, which you then link as a PostHog BigQuery source.
Data Locker writes hourly folders (t=topic/dt=date/h=0 to h=23), about one to three hours after the data reaches AppsFlyer. Late data goes into an extra h=late folder, and a _SUCCESS flag marks a folder as complete. If you use the AppsFlyer-owned bucket instead of your own, files only stay available for 14 days.
Forward the conversions AppsFlyer can’t see
Sometimes the conversion that matters does not happen where the AppsFlyer SDK can see it. Think of a subscription renewal processed on your backend, a purchase completed on web after an app-to-web journey, or an offline lead that gets qualified later. PostHog often does know about these events. With a PostHog destination you can forward them to AppsFlyer in real time, so they can be attributed and passed on to your ad networks.
PostHog has no native AppsFlyer destination, so you build this yourself on AppsFlyer’s server-to-server (S2S) events API, using the generic webhook destination or a customized Hog destination.
The basics of the AppsFlyer call
POST https://api3.appsflyer.com/inappevent/{app_id}, whereapp_idis the iOS app ID with itsidprefix or the Android package name- Your app’s S2S key goes in the
authenticationheader - Required body fields are
appsflyer_id,eventNameandeventValue eventValueis preferably a JSON object, for example{"af_revenue": "9.99"}. A stringified JSON is also accepted, and an event without a value sends""- Send
ostoo: AppsFlyer says it is needed for correct processing eventTimemust be UTC in the formatyyyy-mm-dd hh:mm:ss.sss, not ISO 8601. Without it, AppsFlyer uses the arrival time- Useful extras:
customer_user_id,eventCurrency,ip,bundleIdentifierandatt(iOS, 0 to 3), plusadvertising_id(needed for postbacks to self-reporting networks) andidfv(needed for Meta’s Aggregated Event Measurement) where you have consent - One event per request, with a payload of at most 1 KB
On errors you get a 400 for authentication failures, a missing appsflyer_id or JSON that does not parse, a 401 when the key is not this app’s S2S key, and a 403 for a Zero package, which does not accept attribution events.
A customized Hog destination
The plain webhook destination works for simple cases, since its JSON body supports templates such as {event.properties.revenue}. A customized destination earns its keep once you need logic: skipping people without an AppsFlyer ID, reformatting the timestamp, or picking the iOS or Android app per event. A rough sketch (test it with PostHog’s built-in test panel before turning it on):
// No AppsFlyer ID, no event: skip instead of sending a request AppsFlyer will reject
if (empty(inputs.appsflyer_id)) {
print('No appsflyer_id, skipping', event.event)
return
}
let res := fetch(f'https://api3.appsflyer.com/inappevent/{inputs.app_id}', {
'method': 'POST',
'headers': {
'authentication': inputs.s2s_key,
'Content-Type': 'application/json'
},
'body': {
'appsflyer_id': inputs.appsflyer_id,
'customer_user_id': inputs.customer_user_id,
'eventName': inputs.event_name,
'eventValue': inputs.event_value,
// AppsFlyer wants 'yyyy-mm-dd hh:mm:ss.sss' in UTC
'eventTime': formatDateTime(toDateTime(event.timestamp), '%Y-%m-%d %H:%i:%S.%f', 'UTC'),
'eventCurrency': inputs.currency,
'os': inputs.os
}
});
if (res.status >= 400) {
throw Error(f'AppsFlyer rejected the event: {res.status} {res.body}')
}Map each input to event or person properties with templates such as {person.properties.appsflyer_id}, mark the S2S key input as secret, and use filters so only the events that matter are forwarded.
Pitfalls that cost people days
- No
appsflyer_id, no event. AppsFlyer requires it. You must capture it in the app (from the AppsFlyer SDK) and store it in PostHog first. This is why section 3 matters. - Double counting. Each conversion should reach AppsFlyer through exactly one path, either the SDK or S2S. Otherwise the same purchase is counted twice and your ad networks optimize on inflated numbers.
- Late events get a new date. AppsFlyer only keeps your
eventTimeif the event arrives on the same UTC day, or the next day before 02:00 UTC. Anything later is stamped with its arrival time, so forward events in real time rather than in a nightly batch. - Failed deliveries. PostHog retries non-2xx responses up to three times, depending on the error code. Destinations that keep failing or respond slowly can be quarantined and eventually disabled. But 4xx responses do not count as poor performance, so a destination with a wrong key or broken JSON keeps failing politely forever. Keep an eye on the logs tab.
- Consent. The S2S API accepts a
sharing_filter("all"or a list of partner IDs) to block sharing with ad partners, andconsent_data, either as a TCF object or asgdpr_applies,ad_user_data_enabledandad_personalization_enabled. If you work privacy-first, only forward events for users who have consented and send the consent state along.
A
200 OKdoes not mean the event was recordedAppsFlyer only does minimal validation. For example, an iOS
app_idwithout theidprefix returns200, but nothing is recorded. Always verify in AppsFlyer.
What about audiences?
If you need to send audiences (not events) to AppsFlyer, remember that cohorts used in PostHog’s realtime destinations must consist exclusively of person-property filters, see the cohort documentation. Cohorts with behavioral filters cause destination errors, and dynamic cohorts are only recalculated once every 24 hours anyway. For heavier jobs, use PostHog batch exports to your warehouse and a reverse ETL tool.
Enrich PostHog with attribution data at the source
The warehouse gives you a rear-view mirror with a delay. If you want attribution available inside PostHog in real time, hand it over from the AppsFlyer SDK when the app learns about it.
What to send to PostHog
The AppsFlyer SDK delivers the conversion data in the onConversionDataSuccess callback. It always contains af_status (Organic or Non-organic), is_first_launch, media_source, campaign and campaign_id. Ad set and ad fields depend on the network: most use af_adset and af_ad, while Meta uses adset and adgroup. Send this to PostHog:
- Capture an attribution event (for example
install_attributed) whenis_first_launchis true, withaf_status,media_source, the campaign (stored asaf_campaign, to match use case A) and the other fields you care about. - Set person properties with the AppsFlyer ID (from
getAppsFlyerUID) and the attribution fields, so every later event and person can be filtered on them. - Identify the user with the same ID you send to AppsFlyer as the Customer User ID, once they log in.
Hedgehog tip
Call AppsFlyer’s
setCustomerUserIdbeforestart(). Otherwise the install itself is not tied to your user ID, only the events after it. On Android SDK 7, the Customer User ID only lives for the current session, so set it again on every cold start.
A few more traps: in React Native, is_first_launch arrives as the string "true" on Android but as a boolean on iOS. And use $set_once for first-touch attribution properties, so a reinstall or a later campaign does not overwrite where the user originally came from.
What this unlocks, directly in PostHog
- Funnels and retention by campaign or media source, without waiting for the next warehouse sync or writing a SQL join
- Session replays filtered on acquisition source, to see how users from campaign X actually behave
- Feature flags and experiments targeted on channel, for example a different onboarding for paid social users
- The
appsflyer_idneeded for section 2, so your destination has what AppsFlyer requires
Check what you are allowed to copy
AppsFlyer warns that partners such as Meta, X, Snap and Pinterest restrict sharing their data with third-party platforms. Before you store campaign-level details from those networks in PostHog, check their terms and drop what is restricted.
Note
Copying attribution into PostHog gives you speed and convenience, not a second source of truth. AppsFlyer stays the system of record for attribution and spend. Expect small differences, especially for iOS where deterministic attribution depends on consent.
Which one should you start with?
🦔 Our pick
In practice, we recommend starting with 3, because it fixes identity, and identity is what makes 1 and 2 work. Then add 1 for reporting, and 2 for the events AppsFlyer is missing.
About Marketing Engineers
Marketing Engineers helps organizations get more out of their marketing technology and measurement investments. We are one of PostHog's recommended external partners, and we build the data pipelines that connect PostHog to platforms like AppsFlyer, from tracking plan to warehouse to destinations. Want PostHog and AppsFlyer to start talking? Reach out via the form below.