Skip to content

feat: set Polymarket referrer inside dapp browser#7388

Open
i1skn wants to merge 1 commit intodevelopfrom
04-24-feat_set_polymarket_referrer_inside_dapp_browser
Open

feat: set Polymarket referrer inside dapp browser#7388
i1skn wants to merge 1 commit intodevelopfrom
04-24-feat_set_polymarket_referrer_inside_dapp_browser

Conversation

@i1skn
Copy link
Copy Markdown
Contributor

@i1skn i1skn commented Apr 24, 2026

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:

  1. Alternate app/new-tab entry path
    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.
  2. Direct browser navigation path
    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.
  3. Cross-site navigation path (e.g. starting on Google)
    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

Copy link
Copy Markdown
Contributor Author

i1skn commented Apr 24, 2026

@linear
Copy link
Copy Markdown

linear Bot commented Apr 24, 2026

@i1skn i1skn marked this pull request as ready for review April 24, 2026 15:50
@github-actions
Copy link
Copy Markdown

Launch in simulator or device for ddae102

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 24, 2026

🧪 Flashlight Performance Report (AWS Device Farm)

🔀 Commit: ed23c91

📎 View Artifacts

Metric Current Δ vs Baseline
Time to Interactive (TTI) 5659 ms
Average FPS 56.62
Average RAM 399.3 MB

const { updateTabUrlWorklet } = useBrowserWorkletsContext();

const currentMessengerRef = useRef<MessengerWithUrl | null>(null);
const dappReferralsAppliedRef = useRef(new Set<string>());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread src/components/DappBrowser/hooks/useWebViewHandlers.ts Outdated
}
}

runOnUI(updateTabUrlWorklet)({ tabId, url: urlToSet });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed with goToPage above or can/should we skip it when that branch executes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIU this two different thing: goToPage actually changes the URL and updateTabUrlWorklet is responsible for visual handling in a URL bar.

Comment thread src/components/DappBrowser/hooks/useWebViewHandlers.ts Outdated
@olerass
Copy link
Copy Markdown
Contributor

olerass commented Apr 27, 2026

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):

features/polymarket/
├── constants.ts                  # add POLYMARKET_REFERRAL_PARAM, POLYMARKET_REFERRAL_CODE, POLYMARKET_HOSTNAMES
├── utils/
   └── polymarketReferralUrl.ts   # getPolymarketReferralUrl(url): string | null

The browser then becomes:

import { getPolymarketReferralUrl } from '@/features/polymarket/utils/polymarketReferralUrl';

const referralUrl = getPolymarketReferralUrl(navState.url);
if (referralUrl && !dappReferralsAppliedRef.current.has('polymarket')) {
  dappReferralsAppliedRef.current.add('polymarket');
  if (referralUrl !== navState.url) {
    useBrowserStore.getState().goToPage(referralUrl, tabId);
  }
}

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.

@i1skn i1skn force-pushed the 04-24-feat_set_polymarket_referrer_inside_dapp_browser branch from ce6d985 to 992c7c9 Compare April 28, 2026 11:39
@github-actions
Copy link
Copy Markdown

Launch in simulator or device for 1afd55c

@i1skn i1skn force-pushed the 04-24-feat_set_polymarket_referrer_inside_dapp_browser branch from 992c7c9 to df83dac Compare April 28, 2026 12:28
@blacksmith-sh

This comment has been minimized.

@i1skn i1skn force-pushed the 04-24-feat_set_polymarket_referrer_inside_dapp_browser branch from df83dac to c61d6a5 Compare April 28, 2026 15:52
@github-actions
Copy link
Copy Markdown

Launch in simulator or device for 1170948

@i1skn i1skn force-pushed the 04-24-feat_set_polymarket_referrer_inside_dapp_browser branch from c61d6a5 to 8077192 Compare April 29, 2026 11:49
@i1skn i1skn requested a review from olerass April 29, 2026 11:50
@github-actions
Copy link
Copy Markdown

Launch in simulator or device for ed23c91

Copy link
Copy Markdown
Contributor

@olerass olerass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new more generic solution 👍 A few Qs:

  1. 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?

  2. Should we add analytics to the rewrite path?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants