Skip to content

fix(analytics): page view events capturing unnecessary data#2134

Merged
dev-rb merged 9 commits intomainfrom
rahul/fix-analytics-pageview-event
Mar 24, 2026
Merged

fix(analytics): page view events capturing unnecessary data#2134
dev-rb merged 9 commits intomainfrom
rahul/fix-analytics-pageview-event

Conversation

@dev-rb
Copy link
Copy Markdown
Contributor

@dev-rb dev-rb commented Mar 23, 2026

This PR changes the way page view events are captured.

Currently, the page view event is auto captured by the analytics providers but this causes each event to capture the DOM document title which contains data like document, channel, email, etc. names/titles. Besides this data being largely irrelevant because there can be an infinite amount of dynamic pages due to user generated content, this data can also be sensitive and should not be captured.

In this PR, the automatic page view event tracking is replaced with manual page view tracking for component and blocks

@dev-rb dev-rb requested a review from a team as a code owner March 23, 2026 21:08
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 23, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 61c11960-6623-4ab5-8f1c-c458458f3e6a

📥 Commits

Reviewing files that changed from the base of the PR and between 42a4140 and 9a4c9ec.

📒 Files selected for processing (4)
  • js/app/packages/app/component/EmailAuth.tsx
  • js/app/packages/app/component/auth/Login.tsx
  • js/app/packages/app/lib/analytics/app-events.ts
  • js/app/packages/app/lib/analytics/providers.ts

Walkthrough

Added an exported analytics.pageView(pageTitle, opts?) API and PageViewOptions type; exposed on the AnalyticsInterface and singleton. Google Analytics and Meta Pixel inits were changed to disable automatic PageView emission (GA: send_page_view: false; Meta: fbq.disablePushState = true and adjusted noscript query). Introduced usePageViewTracking and wired pageView calls into authenticated split-layout routes, compose block factories, BlockLoader (non-nested/non-preview), Login, EmailSignUp, and InteractiveOnboarding. Removed page_view from AppEvents/AppEventNames.

Poem

🐰 I hop through routes and press my paw,
On mount I whisper the page I saw,
A tiny ping, a gentle cheer,
Each view recorded, crystal clear,
I bounce, I note, I softly say —
"Page viewed!" then hop away.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: replacing automatic page view event tracking with manual tracking to avoid capturing unnecessary data from the DOM document title.
Description check ✅ Passed The description clearly explains the problem (auto-captured page views include sensitive DOM document titles) and the solution (manual page view tracking for components and blocks), directly aligning with the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rahul/fix-analytics-pageview-event

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@js/app/packages/app/lib/analytics/analytics.ts`:
- Around line 133-151: The single try/catch around all analytics dispatches can
drop subsequent providers if one throws; update the block so each provider call
is protected individually (wrap gtag(...) in its own try/catch, wrap fbq(...) in
its own try/catch, and wrap posthog.instance.capture(...) in its own try/catch)
and log errors with provider-specific context (e.g.,
console.error('[Analytics][gtag] ...', err)) so one provider failing doesn't
prevent the others from running.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 45d55e09-963b-4e1b-acdb-507ddbe213a6

📥 Commits

Reviewing files that changed from the base of the PR and between a7aa488 and e320ca1.

📒 Files selected for processing (4)
  • js/app/packages/app/component/split-layout/componentRegistry.tsx
  • js/app/packages/app/lib/analytics/analytics.ts
  • js/app/packages/app/lib/analytics/providers.ts
  • js/app/packages/core/internal/BlockLoader.tsx

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
js/app/packages/app/lib/analytics/analytics.ts (1)

142-160: ⚠️ Potential issue | 🟠 Major

Isolate provider failures so one exception doesn’t drop the rest.

A single try/catch around GA + Meta + PostHog means one throw prevents remaining providers from receiving the page view.

🔧 Suggested fix
-    try {
-      gtag('event', 'page_view', {
-        page_title: pageTitle,
-        page_location: pageLocation,
-        page_path: pagePath,
-      });
-
-      fbq('track', 'PageView', {
-        content_name: pageTitle,
-      });
-
-      posthog.instance.capture('$pageview', {
-        $current_url: pageLocation,
-        $pathname: pagePath,
-        $title: pageTitle,
-      });
-    } catch (e) {
-      console.error('[Analytics] Failed to send page_view:', e);
-    }
+    try {
+      gtag('event', 'page_view', {
+        page_title: pageTitle,
+        page_location: pageLocation,
+        page_path: pagePath,
+      });
+    } catch (e) {
+      console.error('[Analytics][ga] Failed to send page_view:', e);
+    }
+
+    try {
+      fbq('track', 'PageView', {
+        content_name: pageTitle,
+      });
+    } catch (e) {
+      console.error('[Analytics][meta-pixel] Failed to send page_view:', e);
+    }
+
+    try {
+      posthog.capture('$pageview', {
+        $current_url: pageLocation,
+        $pathname: pagePath,
+        $title: pageTitle,
+      });
+    } catch (e) {
+      console.error('[Analytics][posthog] Failed to send page_view:', e);
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@js/app/packages/app/lib/analytics/analytics.ts` around lines 142 - 160, The
current single try/catch around gtag, fbq and posthog.instance.capture causes
one provider error to abort the others; update analytics.ts so each provider
call (gtag('event', ...), fbq('track', ...), and posthog.instance.capture(...))
is wrapped in its own try/catch that logs provider-specific failures (include
the error and provider name) and continues executing the remaining providers to
ensure one failure doesn't prevent others from receiving the page_view.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@js/app/packages/app/lib/analytics/analytics.ts`:
- Line 137: The guard uses an undefined variable "options" causing runtime
errors; change the check to reference the correct options object in scope (for
example replace `if (options.disabled) return;` with `if
(this.options?.disabled) return;` or `if (opts?.disabled) return;` to match the
existing variable name used by the surrounding function/class in analytics.ts),
ensuring you use the same identifier (e.g., this.options or opts or
analyticsOptions) that is defined in the enclosing scope.
- Line 153: The pageview capture call uses a non-existent property: replace the
incorrect posthog.instance.capture call with posthog.capture so it uses the
PostHog instance created by new PostHog(); update the invocation where
posthog.instance.capture(...) appears (matching the existing correct usage of
posthog.capture elsewhere in this module) to call posthog.capture(...) with the
same payload and error handling.

---

Duplicate comments:
In `@js/app/packages/app/lib/analytics/analytics.ts`:
- Around line 142-160: The current single try/catch around gtag, fbq and
posthog.instance.capture causes one provider error to abort the others; update
analytics.ts so each provider call (gtag('event', ...), fbq('track', ...), and
posthog.instance.capture(...)) is wrapped in its own try/catch that logs
provider-specific failures (include the error and provider name) and continues
executing the remaining providers to ensure one failure doesn't prevent others
from receiving the page_view.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d5e75619-5242-4761-b04f-be8c23801e5f

📥 Commits

Reviewing files that changed from the base of the PR and between e320ca1 and 8bd2337.

📒 Files selected for processing (1)
  • js/app/packages/app/lib/analytics/analytics.ts

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
js/app/packages/app/lib/analytics/analytics.ts (1)

142-160: ⚠️ Potential issue | 🟠 Major

Single catch block can drop page-view delivery to remaining providers.

The single try/catch around all three provider dispatches means if gtag throws, neither fbq nor posthog will receive the event. Each provider should be wrapped independently to ensure partial failures don't block other providers.

🔧 Suggested fix
-    try {
-      gtag('event', 'page_view', {
-        page_title: pageTitle,
-        page_location: pageLocation,
-        page_path: pagePath,
-      });
-
-      fbq('track', 'PageView', {
-        content_name: pageTitle,
-      });
-
-      posthog.capture('$pageview', {
-        $current_url: pageLocation,
-        $pathname: pagePath,
-        $title: pageTitle,
-      });
-    } catch (e) {
-      console.error('[Analytics] Failed to send page_view:', e);
-    }
+    try {
+      gtag('event', 'page_view', {
+        page_title: pageTitle,
+        page_location: pageLocation,
+        page_path: pagePath,
+      });
+    } catch (e) {
+      console.error('[Analytics] Failed to send page_view to ga:', e);
+    }
+
+    try {
+      fbq('track', 'PageView', {
+        content_name: pageTitle,
+      });
+    } catch (e) {
+      console.error('[Analytics] Failed to send page_view to meta-pixel:', e);
+    }
+
+    try {
+      posthog.capture('$pageview', {
+        $current_url: pageLocation,
+        $pathname: pagePath,
+        $title: pageTitle,
+      });
+    } catch (e) {
+      console.error('[Analytics] Failed to send page_view to posthog:', e);
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@js/app/packages/app/lib/analytics/analytics.ts` around lines 142 - 160, The
current single try/catch around the three vendor calls (gtag, fbq, posthog) can
stop later providers from receiving the page_view if an earlier call throws;
change the implementation so each provider call (gtag('event','page_view', ...),
fbq('track','PageView', ...), posthog.capture('$pageview', ...)) is wrapped in
its own try/catch, logging the provider name and error (e.g.,
console.error('[Analytics][gtag] ...', e)) so a failure in one does not prevent
the others from running.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@js/app/packages/app/component/auth/Login.tsx`:
- Around line 33-34: Move the analytics.pageView('login') call out of the
component body and into a mount effect so it only runs once; specifically, in
Login (component in Login.tsx) wrap the call inside an onMount callback (same
pattern used in EmailAuth.tsx / usePageViewTracking) so
analytics.pageView('login') executes inside onMount(() => { ... }) instead of at
top-level of the component.

In `@js/app/packages/app/component/EmailAuth.tsx`:
- Around line 89-91: The analytics.pageView('signup') call is currently at
component top-level and will run on every reconciliation; move it into an
onMount() callback so it runs exactly once on mount. Specifically, inside the
EmailAuth component wrap analytics.pageView('signup') in onMount(() =>
analytics.pageView('signup')), import onMount from 'solid-js' if missing, and
follow the same pattern used in componentRegistry.tsx; keep useAnalytics() where
it is and only relocate the pageView invocation.

---

Duplicate comments:
In `@js/app/packages/app/lib/analytics/analytics.ts`:
- Around line 142-160: The current single try/catch around the three vendor
calls (gtag, fbq, posthog) can stop later providers from receiving the page_view
if an earlier call throws; change the implementation so each provider call
(gtag('event','page_view', ...), fbq('track','PageView', ...),
posthog.capture('$pageview', ...)) is wrapped in its own try/catch, logging the
provider name and error (e.g., console.error('[Analytics][gtag] ...', e)) so a
failure in one does not prevent the others from running.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f95fc7a4-aa61-45c8-ae05-13b9c55aceb2

📥 Commits

Reviewing files that changed from the base of the PR and between 8bd2337 and 42a4140.

📒 Files selected for processing (5)
  • js/app/packages/app/component/EmailAuth.tsx
  • js/app/packages/app/component/auth/Login.tsx
  • js/app/packages/app/component/interactive-onboarding/InteractiveOnboarding.tsx
  • js/app/packages/app/component/split-layout/componentRegistry.tsx
  • js/app/packages/app/lib/analytics/analytics.ts

@dev-rb dev-rb merged commit 980df33 into main Mar 24, 2026
22 checks passed
@dev-rb dev-rb deleted the rahul/fix-analytics-pageview-event branch March 24, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant