Skip to content

feat: add GA4 login event tracking#916

Merged
NoopDog merged 3 commits into
mainfrom
mim/913-login-event-tracking
May 12, 2026
Merged

feat: add GA4 login event tracking#916
NoopDog merged 3 commits into
mainfrom
mim/913-login-event-tracking

Conversation

@MillenniumFalconMechanic
Copy link
Copy Markdown
Collaborator

@MillenniumFalconMechanic MillenniumFalconMechanic commented May 11, 2026

Ticket

Closes #913

Summary

  • Add GA4 login event (recommended event) that fires when a user authenticates via Google Sign-In
  • Track the falsetrue transition of isAuthenticated in both auth providers (GoogleSignInAuthenticationProvider and NextAuthAuthenticationProvider)
  • Gate tracking on AUTH_STATUS.SETTLED to prevent false positives during session hydration
  • Use existing tool_name custom dimension (instead of method) to avoid provisioning a new GA4 dimension

Test plan

  • Unit tests pass (useLoginTracking.test.ts — 6 cases covering mount, transition, logout, and hydration scenarios)
  • Run AnVIL CMG locally, sign in, and verify window.dataLayer contains { event: "login", params: { tool_name: "google" } }
  • Verify the event does not appear on page refresh when already signed in

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 11, 2026 21:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds GA4-recommended login analytics tracking to the @databiosphere/findable-ui auth flows so consuming apps automatically emit a login event when authentication completes (without firing on initial mount for persisted sessions).

Changes:

  • Added EVENT_NAME.LOGIN and EVENT_PARAM.METHOD (plus typed params) to the analytics entities.
  • Introduced useLoginTracking(isAuthenticated) hook to detect false → true authentication transitions and send track("login", { method: "google" }).
  • Wired useLoginTracking into both GoogleSignInAuthenticationProvider and NextAuthAuthenticationProvider, and added unit tests for the hook.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/useLoginTracking.test.ts Adds unit coverage for initial mount vs. auth transitions for the login tracking hook.
src/nextauth/provider.tsx Invokes login tracking based on authState.isAuthenticated in the NextAuth provider.
src/hooks/authentication/useLoginTracking.ts New hook that tracks GA4 login on false → true isAuthenticated transitions.
src/google/provider.tsx Invokes login tracking based on authState.isAuthenticated in the Google Sign-In provider.
src/common/analytics/entities.ts Extends analytics enums and event-param typing to include GA4 login with method.

Comment thread tests/useLoginTracking.test.ts Outdated
…tant for login event #913

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Comment thread tests/useLoginTracking.test.ts Outdated
Comment thread src/hooks/authentication/useLoginTracking.ts Outdated
Comment thread src/common/analytics/entities.ts
Comment thread src/common/analytics/entities.ts
Comment thread src/hooks/authentication/useLoginTracking.ts
Comment thread src/nextauth/provider.tsx
Comment thread tests/useLoginTracking.test.ts Outdated
…false positives #913

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread src/hooks/authentication/useLoginTracking.ts
@NoopDog NoopDog merged commit c305aed into main May 12, 2026
6 checks passed
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.

Add GA4 login event tracking

3 participants