Skip to content

feat(analytics): add AI consent and event tracking schema#2243

Merged
k11kirky merged 2 commits into
mainfrom
posthog-code/event-tracking
May 20, 2026
Merged

feat(analytics): add AI consent and event tracking schema#2243
k11kirky merged 2 commits into
mainfrom
posthog-code/event-tracking

Conversation

@k11kirky
Copy link
Copy Markdown
Contributor

TL;DR

Added comprehensive event tracking for AI consent flows and onboarding steps, along with a detailed schema documentation file that defines naming conventions, property standards, and the complete event catalog for the desktop app's PostHog integration.

What changed?

  • New file: apps/code/SCHEMA.md - Comprehensive analytics schema documentation including:

    • Naming conventions for event names (Object + past-tense verb format)
    • Property naming standards (snake_case, prefixes like is_, has_, suffixes like _count, _seconds, _id)
    • Enum value conventions and PII guidelines
    • Instructions for adding new events
    • Common properties used across events (task_id, execution_type, adapter, repository_provider, etc.)
    • Complete event catalog organized by feature area:
      • App lifecycle (App started, App quit)
      • Authentication (User logged in, User logged out)
      • Onboarding flow with detailed funnel structure
      • New AI consent events: Ai consent gate shown and Ai consent approved
      • Additional tracking for inbox signal cards with relative timestamp display
  • Added new analytics events to support:

    • AI consent gating with admin-level tracking (is_org_admin property)
    • Onboarding completion flows with AI consent conditional logic
    • Relative timestamp tracking on signal cards (via Onboarding step viewed and related events)

How did you test this?

Schema documentation reviewed for compliance with PostHog naming conventions and consistency with existing event patterns in the codebase.

Publish to changelog?

yes


Created with PostHog Code

Generated-By: PostHog Code
Task-Id: 925c17d3-8b1f-4494-8c9b-f8de61478a85
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 20, 2026

Comments Outside Diff (1)

  1. apps/code/src/shared/types/analytics.ts, line 980 (link)

    P2 INBOX_VIEWED is added to ANALYTICS_EVENTS and EventPropertyMap but has no corresponding row in SCHEMA.md. The schema document's own instructions (step 5) require a catalog entry for every new event — consumers querying PostHog won't have documented property expectations or context for this event.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: apps/code/src/shared/types/analytics.ts
    Line: 980
    
    Comment:
    `INBOX_VIEWED` is added to `ANALYTICS_EVENTS` and `EventPropertyMap` but has no corresponding row in `SCHEMA.md`. The schema document's own instructions (step 5) require a catalog entry for every new event — consumers querying PostHog won't have documented property expectations or context for this event.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
Fix the following 3 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 3
apps/code/src/renderer/features/onboarding/hooks/useOnboardingFlow.ts:12-19
The fallback `return "github"` misclassifies any unrecognised remote (Bitbucket, Azure DevOps, self-hosted Gitea, etc.) as GitHub, silently corrupting the `repository_provider` dimension in PostHog for those users. Since the type already includes `"none"` for "unidentifiable provider", that is the correct sentinel here.

```suggestion
function inferRepositoryProvider(
  remote: string | undefined,
): RepositoryProvider {
  if (!remote) return "local";
  if (remote.includes("gitlab.com")) return "gitlab";
  if (remote.includes("github.com")) return "github";
  return "none";
}
```

### Issue 2 of 3
apps/code/src/renderer/features/ai-approval/components/AiApprovalScreen.tsx:33-35
The `[isAdmin]` dependency means `AI_CONSENT_GATE_SHOWN` fires again whenever the parent re-renders with a different `isAdmin` value — e.g. if the `useIsOrgAdmin()` query resolves after the screen is already mounted. The intent is clearly "fire once when this screen appears", so an empty dependency array (with an inline suppression comment, consistent with the pattern already used in `OnboardingFlow.tsx`) is the right call.

```suggestion
  // biome-ignore lint/correctness/useExhaustiveDependencies: fire once on mount with current isAdmin value
  useEffect(() => {
    track(ANALYTICS_EVENTS.AI_CONSENT_GATE_SHOWN, { is_org_admin: isAdmin });
  }, []);
```

### Issue 3 of 3
apps/code/src/shared/types/analytics.ts:980
`INBOX_VIEWED` is added to `ANALYTICS_EVENTS` and `EventPropertyMap` but has no corresponding row in `SCHEMA.md`. The schema document's own instructions (step 5) require a catalog entry for every new event — consumers querying PostHog won't have documented property expectations or context for this event.

Reviews (1): Last reviewed commit: "feat(analytics): add AI consent and onbo..." | Re-trigger Greptile

Comment thread apps/code/src/renderer/features/ai-approval/components/AiApprovalScreen.tsx Outdated
Comment thread apps/code/src/renderer/features/ai-approval/components/AiApprovalScreen.tsx Outdated
Comment thread apps/code/src/renderer/App.tsx
- Use strict host matching in inferRepositoryProvider to avoid CodeQL URL substring sanitization issue
- Return "none" for unrecognised remotes instead of misclassifying as github
- Fire AI consent gate shown once on mount even if isAdmin resolves later
- Add Inbox viewed row to SCHEMA.md catalog

Generated-By: PostHog Code
Task-Id: 925c17d3-8b1f-4494-8c9b-f8de61478a85
@k11kirky k11kirky merged commit 352ca86 into main May 20, 2026
15 checks passed
@k11kirky k11kirky deleted the posthog-code/event-tracking branch May 20, 2026 13:36
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.

3 participants