Skip to content

Refactor analytics enrichment and fix screen tracking initialization - #2127

Merged
MusabShakeel576 merged 1 commit into
qafrom
claude/lucid-cori-c1MEf
Jun 9, 2026
Merged

Refactor analytics enrichment and fix screen tracking initialization#2127
MusabShakeel576 merged 1 commit into
qafrom
claude/lucid-cori-c1MEf

Conversation

@MusabShakeel576

Copy link
Copy Markdown
Contributor

Summary

This PR refactors the analytics event enrichment logic to reduce duplication and fixes a timing issue where screen views were tracked before analytics initialization completed, potentially causing events to be sent to incorrect endpoints.

Key Changes

  • Extract shared enrichment logic: Created enrichEventParams() helper function that centralizes attribution, device context, and platform data enrichment. This function is now used by both track() and trackAmplitudeScreen() to ensure consistent event properties across all event types.

  • Fix screen tracking initialization: Added analyticsReady state that gates screen view tracking until initAnalytics() completes. This prevents early screen views from being queued before the Amplitude SDK is properly configured with proxy/serverUrl settings on web.

  • Flatten route params in screen events: Modified trackAmplitudeScreen() to flatten route params into top-level properties (matching track() behavior), making utm_source, utm_campaign, and other attribution data directly queryable in Amplitude instead of nested in a params object.

  • Reorganize layout component: Moved onLayout callback from SafeAreaProvider to GestureHandlerRootView and added flex: 1 style to ensure proper layout handling.

Implementation Details

  • The enrichEventParams() function consolidates all enrichment logic that was previously duplicated in the track() function, improving maintainability.
  • Screen tracking now waits for analytics initialization, ensuring the landing screen is captured with full attribution context.
  • The analyticsReady dependency in the screen tracking effect ensures the effect re-fires once initialization completes, capturing the initial route with proper context.

https://claude.ai/code/session_01KR9AG8hkYVigCMsQmDKGS2

Web never sent any Amplitude events because initAnalytics is gated behind
splashScreenHidden, which is only flipped by onLayoutRootView. That
onLayout was attached to SafeAreaProvider, which does not forward an
arbitrary onLayout prop to its underlying view on web (it only wires its
own inset measurement), so the callback never ran and analytics was
never initialized. Native works because the native SafeAreaProvider does
forward onLayout. Move onLayout to GestureHandlerRootView, which passes
it through to a react-native-web View (fires via ResizeObserver) on web
and lays out normally on native.

Also gate trackScreen behind a new analyticsReady flag set once
initAnalytics resolves, so the first (landing) Page Viewed fires after
init instead of being queued before the Amplitude proxy serverUrl is
configured and flushed to the wrong endpoint.

Enrich the Amplitude Page Viewed event the same way track() does:
extract a shared enrichEventParams() helper and use it for screen
tracking so UTM/attribution fields land as top-level, queryable
properties (utm_source, utm_campaign, ...) and route params are
flattened instead of nested under a `params` object. Kept screen
tracking on the Amplitude-only path to avoid double-counting in
Firebase/GTM.

https://claude.ai/code/session_01KR9AG8hkYVigCMsQmDKGS2
@vercel

vercel Bot commented Jun 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
solid-app Ignored Ignored Jun 9, 2026 6:32am
solid-app-staging Ignored Ignored Jun 9, 2026 6:32am

Request Review

@MusabShakeel576
MusabShakeel576 merged commit 8c1f3f4 into qa Jun 9, 2026
4 of 5 checks passed
@MusabShakeel576
MusabShakeel576 deleted the claude/lucid-cori-c1MEf branch June 9, 2026 06:55
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