Working-tree content. Subject to change and not yet released. Commit: e3d4530507.
Feature — Cross Promotion
This app is the destination of cross promotion. A player taps a promo in another Amanotes app (the source app) and arrives here through an AppsFlyer OneLink. The app then:
- reads the link's
xp_uid(the source app's click id) and keeps the first one for good, as the user propertyxp_uid; - brings the promoted song or genre up on the Song List, once the player is past the first run,
and sends
crosspromo_deeplink_open; - sends
map_user_idat every session start, which joins the AppsFlyer id to this install's Firebase ids, so BigQuery can match a player across apps.
Both events are Firebase only. Params and timing: analytics-events.md § Cross Promotion. iOS only. The rules follow MagicPad's implementation of the same Amanotes spec, except where noted below.
Flow
1. Intake
- Listeners. The AppsFlyer service registers the deep-link listener before
init()(the 7.x startup rule: a result that lands before a listener is attached is lost) and the conversion-data listener right after it. If iOS rejects the early deep-link registration, it is made again, once, afterinit()resolved (register-before-init.ts).start()runs on session ready, once that retry has settled, and resolves both. Results that arrive before anyone subscribes wait in a replay channel (up to 10) and go to the first subscriber (replay-channel.ts). A failed registration, failed conversion data or a throwing subscriber is a non-fatal (reportNonFatal, areaattribution). - Subscribe. Boot calls
startCrossPromoDeepLinks()after the splash intro, before AppsFlyer's init (start-app-bootstrap.ts). - Payload. iOS can nest the click's params under
click_event; they are lifted to the top level, and a top-level value wins (appsflyer-deep-link.pure.ts). - Parse (
cross-promo-link.pure.ts):deep_link_sub1..4→xp_uid,placement,song_genre,experiment_group.- Fallback: the same
deep_link_sub*keys in the click URL's query (link,af_dp,original_link,referrer,click_http_referrer). af_sub1..4are never read, at the top level or in a click URL: a paid UA campaign fills them too, and its install must not count as a cross-promo open.- Values are decoded (
Hip-Hop%2FRap→Hip-Hop/Rap,+→ space). Blanks and OneLink template placeholders (xp_uid,deep_link_sub1,{…}, …) count as missing. - No real
xp_uid= not cross promotion: ignored. An organic install sends nothing.
match_type. AppsFlyer'sprobabilisticstaysprobabilistic; any other found link isdeterministic; a link recovered from conversion data isnot_found.open_type. AppsFlyer's deferred flag →deferred, elsedirect. Conversion data is alwaysdeferred.- Conversion-data fallback (AppsFlyer's deep link did not resolve). Only on the install's
first launch, and not once a deep link with a real
xp_uidhas resolved. It is held at once, asnot_found, in the persisted store, so a player who kills the app seconds after the install keeps it. A deep link that resolves later for the same click replaces it (see One open per click below); the open waits for routing until the first run is over anyway. At most once per process (cross-promo-deep-link-flow.ts).
2. Record and store
recordCrossPromoOpenkeeps the install's firstxp_uid, sets the user propertyxp_uidto that kept value, then hands the open over. The property comes first, so every row from the event on carries it. A later link never moves it.useCrossPromoStore(MMKV keycross-promo):xpUid: the firstxp_uidever received; null for an install that never had one.pendingOpen: the open waiting for routing. It survives relaunches.lastOpenXpUid: the click of the last open taken.
- One open per click (
pending-open.pure.ts):- the same
xp_uidagain is dropped; - except: a waiting
not_foundopen is replaced by AppsFlyer's own match of the same click; - another click while an open still waits is dropped: the first keeps its place.
- the same
3. Gate
CrossPromoRouteHost is
mounted in the root layout and renders nothing. It routes when
(shouldRouteCrossPromoOpen):
- an open is waiting;
- the onboarding and the tutorial are done;
- the tutorial has no song left to open (
selectHasPendingPlay): the song claimed on the reward picker or picked on the exit opens over the Song List the moment the app reaches it, so an open routed then would be spent behind it and its focus dropped as the player left for the song; - nothing covers the screen (
isScreenCovered): a paywall, a popup, a full-screen ad, the cover of a song being launched; - this launch's App Open step is over (
useAppOpenLaunchStorephasedone): it starts once the Song List stands uncovered and may wait 5 s for the ad to load, so the song shows after the ad instead of under it. A launch that shows no App Open (the first launch, FTUE, too few finished songs, premium / No Ads) marks it done at once; - the screen is on the tab shell:
/songs,/profile,/mission,/leaguesor/shop.
Anywhere else (gameplay, Learn, a result, the keyboard) the open keeps waiting, so a song is
never cut short. A deferred open from a fresh install waits out the whole first run and the song
it ends on, across a relaunch. The routing then waits for the catalog to have songs (runOnceCatalogLoaded), so
route_result is never a lookup in an empty catalog.
4. Route
resolveCrossPromoRoute
matches song_genre against what the Song List offers now
(readSongListOffer: release gates applied,
the player's filters ignored).
- Split at the last
-:Fur_Elise-Classical→ songFur_Elise, genreClassical.-Phonkis genre only. A value without a dash is tried as a song, then as a genre. The whole value is tried after its parts, so a dash inside a name or a genre still matches. - Song →
matched_song. By catalog id, then by name. Both sides compare by a key: accents dropped, lower case, letters and digits only (Fur_Elise=fur-elise=Für Elise). The Song List brings the song into view and marks it once nothing covers it, however long that takes; the mark's 2.5 s count only while nothing covers the list, so an ad or a popup landing on it (an App Open on a return from the background) does not use them up. Leaving the tab shell first (a song, Learn, the keyboard, a result) drops the ask and ends a mark still showing (songs.md § Focus a song from outside). - Genre →
matched_genre. The catalog's genre of that name first (Folk,Hip Hop), else the source app's genre token through its group. The list is filtered to it (showCategory: search and difficulty cleared, so the genre never lands on an empty list; nofilter_click). - Nothing matched, or no
song_genre→fallback_default: the Song List as it is. - A failure on the way →
fallback_error: the Song List as it is. - From another tab the Song List is brought up (
router.dismissTo("/songs")). On the Song List only the song or the genre changes. - Lock rules are unchanged. Nothing opens, plays or unlocks.
- The open is taken from the store first, then
crosspromo_deeplink_openis sent: one open, one event.
Source genre tokens (MagicPad's sheet) → this app's genre:
A / compound also stands for each of its parts. folk finds the catalog's own Folk first.
Differs from MagicPad: a name-genre value is split at its last - (MagicPad does not
split). The conversion-data fallback is held at once (MagicPad waits 5 s for the deep link
first). MagicPad's gift song for a new install is not in
this app.
map_user_id
MapUserIdFlow, started at boot right after
AppsFlyer's init (map-user-id-runtime.ts):
- Session start: the cold start, or a return to the foreground after 30 min or more in the
background (Firebase's session timeout,
SESSION_TIMEOUT_MS). It reads the ids fresh and sends, even when nothing changed. - Within a session: a return to the foreground (any length) and the ATT answer read the ids again. It sends only when the row changed since the last one sent in this session.
- No AppsFlyer id: nothing is sent. The next check that finds one sends.
inactive(Control Center, a system alert) is not a trip to the background.- Checks run one after another, so two that land together send a change once.
- The ATT answer comes from
requestAttForAds(boot) or the tutorial'srequestAttGuarded(a new player's first answer) →notifyAttAnswered. - Rules (pure, tested):
map-user-id.pure.ts.
Differs from MagicPad: MagicPad waits up to 15 s for the AppsFlyer id and then sends anyway.
Here the spec makes appsflyer_id required, and the row goes out at every session start.
Device ids
src/core/device-ids is a port with an iOS
adapter, a fake and a registry. Every read is fresh, and a read that fails, or has not settled
within DEVICE_ID_READ_TIMEOUT_MS (5 s), is null (never thrown), so one stuck SDK never holds
up map_user_id:
ama_device_id = ios_ + the IDFV, dashes removed, lower case (MagicPad's rule). Boot reads the
IDFV once (warmUp), so ad_impression / ad_impression_ama carry ama_device_id from the
first paid ad (getCachedAmaDeviceId).
Deep-link URLs and the router
app/+native-intent.ts keeps an AppsFlyer link away from Expo
Router's "Unmatched Route". An AppsFlyer link
(isAppsFlyerLinkUrl) is a
*.onelink.me URL, or one whose query carries deep_link_value or deep_link_sub*, on any host
or the app's own scheme. pid or af_* alone do not make one, so other links with those params
still reach their route.
- Cold start (the link launched the app): the router lands on the Song List
(
/(app)/(tabs)/songs). - App already running: the router does not navigate (
redirectSystemPathreturnsnull), so a song in play is never popped. The open waits in the store, andCrossPromoRouteHostroutes it once the player is on a tab.
AppsFlyer's callback reads the link either way. The DevTool link (analytics-bridge) keeps its
own landing. The app's OneLink domain (iosinapp-event.onelink.me) is a *.onelink.me host, so a
Universal Link open lands the same way. A branded domain (not *.onelink.me) without those params
is not recognised.
Universal Links (direct opens)
A OneLink tapped while the app is installed opens the app directly when three things hold:
- The entitlement.
applinks:iosinapp-event.onelink.me(config/associated-domains.ts, wired intoios.associatedDomainsinapp.config.ts). The AppDelegate hands the link to AppsFlyer (plugins/withAppsFlyerAttributionFallback.ts+ the AppsFlyer Expo plugin), and the router lands as above. - Signing. The App ID has the Associated Domains capability, and every profile that signs
the build carries it. CI signs with
match(read-only): its profiles must be regenerated (or the new one imported) before a TestFlight build with this entitlement, or signing fails. - The domain's file. AppsFlyer lists the app (
<Team ID>.<bundle id>, paths/Ko5W/*) inhttps://iosinapp-event.onelink.me/.well-known/apple-app-site-associationonce template Ko5W has the Team ID. iOS reads it when the app is installed or updated (through Apple's CDN, which can lag), so a device that installed the app before the file listed it needs a reinstall.
Until all three hold, a tapped OneLink opens the browser or the App Store instead. Deferred opens (an install from the link) need none of them.
Files
Tests sit in each folder's __tests__/. The analytics contract is in
packages/analytics/tests/cross-promotion-schema.test.ts.
Not done yet
- Universal Links on a device. Not checked yet: it needs the domain's file to list the app and a build signed with a profile that has the capability (see Universal Links).
- Deferred payload on a real device. The deep-link and conversion-data payloads of a real install from a OneLink have not been checked on a device yet. The parser follows AppsFlyer's documented shapes and MagicPad's parser.
user_subscriptiontoken_1/token_2are not in the app. App Store Server Notification ids reach the server, never the client.pricestays text, withprice_valueandcurrencybeside it.