Skip to content

Commit e840861

Browse files
yosriadyclaude
andauthored
P-2069 unify mobile screen events as page type (#12)
* feat: unify mobile screen events as page type for Tinybird compatibility Screen events from the React Native SDK now send type="page" instead of type="screen", with screen name mapped to page_title, page_path, and page_url context fields. This allows Tinybird's process_sessions and process_sources materializations (which filter on type='page') to include mobile screen views. The channel="mobile" field distinguishes mobile from web traffic. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: let user-supplied context override default page fields in screen events User-provided context values for page_title, page_path, and page_url were being silently discarded because the defaults were spread after the user context. Reversed the spread order so user values take precedence, consistent with how generateContext() handles merging. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * refactor: remove redundant page_path from screen event context Tinybird derives page_path from page_url via path(), so setting it in the SDK is redundant and never read. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8b97141 commit e840861

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/lib/event/EventFactory.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,10 @@ class EventFactory implements IEventFactory {
372372
}
373373

374374
/**
375-
* Generate screen view event (mobile equivalent of page)
375+
* Generate screen view event as a page event for unified analytics.
376+
* Maps screen name to page-equivalent context fields (page_title, page_path, page_url)
377+
* so Tinybird materializations (process_sessions, process_sources) can process mobile
378+
* screen views alongside web page views. The channel="mobile" distinguishes the source.
376379
*/
377380
async generateScreenEvent(
378381
name: string,
@@ -382,12 +385,21 @@ class EventFactory implements IEventFactory {
382385
): Promise<IFormoEvent> {
383386
const props = { ...(properties ?? {}), name, ...(category && { category }) };
384387

388+
// Map screen name to page-equivalent context fields for Tinybird compatibility.
389+
// page_path is omitted — Tinybird derives it from page_url via path().
390+
// User-supplied context values take precedence (spread last).
391+
const screenContext: IFormoEventContext = {
392+
page_title: name,
393+
page_url: `app://${name}`,
394+
...(context ?? {}),
395+
};
396+
385397
const screenEvent: Partial<IFormoEvent> = {
386398
properties: props,
387-
type: "screen",
399+
type: "page",
388400
};
389401

390-
return this.getEnrichedEvent(screenEvent, context);
402+
return this.getEnrichedEvent(screenEvent, screenContext);
391403
}
392404

393405
async generateDetectWalletEvent(

0 commit comments

Comments
 (0)