feat: set Polymarket referrer inside dapp browser#7388
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
🧪 Flashlight Performance Report (AWS Device Farm) 🔀 Commit: ed23c91
|
| const { updateTabUrlWorklet } = useBrowserWorkletsContext(); | ||
|
|
||
| const currentMessengerRef = useRef<MessengerWithUrl | null>(null); | ||
| const dappReferralsAppliedRef = useRef(new Set<string>()); |
There was a problem hiding this comment.
Why is this needed? We don't want to include the referral param on all navs to polymarket? Even if not, this only works for one session right?
There was a problem hiding this comment.
Doing it every request does not make much sense, as this is only usable when user registering for the first time. Doing it once prior to this should be enough. It does work for a single session, yeah, but still did not feel like always overriding URLs if that does not bring much value.
There was a problem hiding this comment.
I've moved this logic inside handleShouldStartLoadWithRequest (to avoid going back bug) so right now we need this even more as we do not want to cancel all the requests to polymarket and replace them with ones with ?r=.... Wdyt?
| } | ||
| } | ||
|
|
||
| runOnUI(updateTabUrlWorklet)({ tabId, url: urlToSet }); |
There was a problem hiding this comment.
Is this still needed with goToPage above or can/should we skip it when that branch executes?
There was a problem hiding this comment.
AFAIU this two different thing: goToPage actually changes the URL and updateTabUrlWorklet is responsible for visual handling in a URL bar.
|
Also, the referral logic should live in the Polymarket feature alongside the existing constants (I guess, even though I prefer constants close to their usage, so prob could also inline in the file in this feature): The browser then becomes: Browser still owns the dedup mechanism if we want it (it's a browser concern: "don't redirect twice within a session"). Polymarket owns the URL transform. |
ce6d985 to
992c7c9
Compare
992c7c9 to
df83dac
Compare
This comment has been minimized.
This comment has been minimized.
df83dac to
c61d6a5
Compare
c61d6a5 to
8077192
Compare
olerass
left a comment
There was a problem hiding this comment.
I like the new more generic solution 👍 A few Qs:
-
Do we need to strip the referral code from shared urls? In dapp browser -> Three dots -> Share (IIRC), is our built in functionality to share the current page directly to friends or SoMe. With the change here it shares the referral'ed url which might be unexpected?
-
Should we add analytics to the rewrite path?

Partially fixes https://linear.app/rainbow/issue/APP-3658/add-polymarket-referral-code-to-mobile-app-mobile-dapp-browser-and-bx
Why?
We want to add Polymarket attribution in the mobile dapp browser. The goal here is to make referral attribution reliable whenever the user lands on Polymarket, while avoiding repeated redirects or interference with embedded resource loads.
Description
We now enforce a single referral-injection strategy across the three real entry cases that matter:
When Polymarket is opened via route-driven tab creation (for example from another app surface/deep-link-like entry), the referral is applied before the first load so attribution is present immediately.
When navigation goes through the browser’s normal URL routing flow, the same referral rule is applied consistently so manual/pasted/redirected navigations do not bypass attribution.
When a user reaches Polymarket from another site, we intercept only top-frame navigations, rewrite once with referral, and stop the original navigation so the referrer is not missed on first arrival.
This keeps iframe/subresource traffic untouched and avoids referral re-application loops.
What to test