feat(sdk): add useParentAmplitudeIdentity option for cross-domain Amplitude identity #COMW-165#84
Open
dannydtk wants to merge 1 commit into
Open
feat(sdk): add useParentAmplitudeIdentity option for cross-domain Amplitude identity #COMW-165#84dannydtk wants to merge 1 commit into
dannydtk wants to merge 1 commit into
Conversation
…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
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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 asinitial_referrer) is never visible from widget events — they appear as a completely different user.Sharing the Amplitude
device_idvia theclientURL param (which the widget already consumes vialoadExternalAnalyticsIds) 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 excludingclient/profilefrom signed bytes.What changed
src/types.tsAdded optional
useParentAmplitudeIdentity?: booleantoIHostConfigBasewith JSDoc explaining the behaviour.src/init-helpers.tsreadParentAmplitudeIdentity(): readswindow.amplitude.getDeviceId()/getSessionId()and returns{ client, profile }. Silently returns{}ifwindow.amplitudeis missing or throws.initWidgetIframeUrl: whenuseParentAmplitudeIdentityis true, calls the helper and appendsclient/profileto the iframe URL. Never overwrites pre-existing values (partner-set values take precedence).useParentAmplitudeIdentityflag itself is not forwarded into the URL.test/ramp-instant-sdk.test.ts8 new tests covering:
readParentAmplitudeIdentitywith present global, missing global, partial global, and throwing global.initWidgetIframeUrlwith flag off (no injection), flag on (params appended), flag on but pre-existingclient/profile(no override).useParentAmplitudeIdentityitself 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.amplitudeis absent.Test plan
npx jest --env=jsdom— 10/10 pass (including 8 new tests).npx tsc --noEmitclean.rampnetwork.com, confirm in Amplitude that the widget'sdevice_idmatches the marketing site'sdevice_idfor the same browser session and thatinitial_referreris the original external URL (e.g.x.com/...) rather thanrampnetwork.com.Related
Made with Cursor