Skip to content

feat(sdk): add useParentAmplitudeIdentity option for cross-domain Amplitude identity #COMW-165#84

Open
dannydtk wants to merge 1 commit into
masterfrom
daniel/cross-domain-amplitude-identity
Open

feat(sdk): add useParentAmplitudeIdentity option for cross-domain Amplitude identity #COMW-165#84
dannydtk wants to merge 1 commit into
masterfrom
daniel/cross-domain-amplitude-identity

Conversation

@dannydtk
Copy link
Copy Markdown
Contributor

@dannydtk dannydtk commented Apr 30, 2026

Why

When a user visits x.com → rampnetwork.com (marketing) → app.rampnetwork.com (widget), Amplitude assigns the marketing site and the widget iframe separate device IDs because they run on different origins. The URL that originally brought a user to Ramp (document.referrer, captured on the marketing site as initial_referrer) is never visible from widget events — they appear as a completely different user.

Sharing the Amplitude device_id via the client URL param (which the widget already consumes via loadExternalAnalyticsIds) fixes the identity split. This PR adds the opt-in mechanism to the SDK. The paired monorepo PR (RampNetwork/ramp-instant#27381) makes the signing side safe by excluding client / profile from signed bytes.

What changed

src/types.ts

Added optional useParentAmplitudeIdentity?: boolean to IHostConfigBase with JSDoc explaining the behaviour.

src/init-helpers.ts

  • New exported helper readParentAmplitudeIdentity(): reads window.amplitude.getDeviceId() / getSessionId() and returns { client, profile }. Silently returns {} if window.amplitude is missing or throws.
  • initWidgetIframeUrl: when useParentAmplitudeIdentity is true, calls the helper and appends client / profile to the iframe URL. Never overwrites pre-existing values (partner-set values take precedence).
  • The useParentAmplitudeIdentity flag itself is not forwarded into the URL.

test/ramp-instant-sdk.test.ts

8 new tests covering:

  • readParentAmplitudeIdentity with present global, missing global, partial global, and throwing global.
  • initWidgetIframeUrl with flag off (no injection), flag on (params appended), flag on but pre-existing client/profile (no override).
  • That useParentAmplitudeIdentity itself does not leak into the URL.

Risk / migration

None for existing integrations. The flag defaults off — no behaviour change unless the host page opts in. The helper silently no-ops when window.amplitude is absent.

Test plan

  • npx jest --env=jsdom — 10/10 pass (including 8 new tests).
  • npx tsc --noEmit clean.
  • Manual smoke after both PRs merge: from rampnetwork.com, confirm in Amplitude that the widget's device_id matches the marketing site's device_id for the same browser session and that initial_referrer is the original external URL (e.g. x.com/...) rather than rampnetwork.com.

Related

Made with Cursor

…litude identity #COMW-165

New opt-in flag forwards the host page's Amplitude device/session IDs to
the widget iframe as `client` / `profile` URL params. Pairs with
RampNetwork/ramp-instant#<PR-NUMBER>, which excludes those params from the
signed payload so this is safe to enable on top of partner-signed URLs.

Made-with: Cursor
@dannydtk dannydtk requested a review from a team as a code owner April 30, 2026 06:07
@github-actions
Copy link
Copy Markdown

Messages
📖

Jira issue(s) related to this PR:

Generated by 🚫 dangerJS against e8a1606

@sonarqubecloud
Copy link
Copy Markdown

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.

1 participant