Skip to content

feat: Track individual subscription start and cancel events#2079

Merged
charlesvien merged 2 commits into
mainfrom
05-06-track_individual_subscription_start_and_cancel_events
May 7, 2026
Merged

feat: Track individual subscription start and cancel events#2079
charlesvien merged 2 commits into
mainfrom
05-06-track_individual_subscription_start_and_cancel_events

Conversation

@charlesvien
Copy link
Copy Markdown
Member

@charlesvien charlesvien commented May 7, 2026

Problem

Existing billing reports only track at the org level, leaving individual user subscription activity invisible.

Changes

  1. Add Subscription started and Subscription cancelled event types with plan_key properties
  2. Fire start event in seatStore.upgradeToPro on both upgrade and fresh-create paths
  3. Fire cancel event in seatStore.cancelSeat capturing the pre-cancel plan_key
  4. Skip tracking on the no-op upgrade path (already on Pro)
  5. Cover the new tracking in seatStore.test.ts

How did you test this?

Manually

Publish to changelog?

@charlesvien charlesvien changed the title Track individual subscription start and cancel events feat: Track individual subscription start and cancel events May 7, 2026
Copy link
Copy Markdown
Member Author

charlesvien commented May 7, 2026

@charlesvien charlesvien changed the base branch from 05-05-handle_ssh_over_https_github_remote_urls to graphite-base/2079 May 7, 2026 06:26
@charlesvien charlesvien force-pushed the graphite-base/2079 branch from 07b789b to ed295c4 Compare May 7, 2026 06:27
@charlesvien charlesvien force-pushed the 05-06-track_individual_subscription_start_and_cancel_events branch from 4b95895 to 20283f4 Compare May 7, 2026 06:27
@graphite-app graphite-app Bot changed the base branch from graphite-base/2079 to main May 7, 2026 06:27
@charlesvien charlesvien force-pushed the 05-06-track_individual_subscription_start_and_cancel_events branch 2 times, most recently from 4e338fc to 8b8adff Compare May 7, 2026 19:26
@charlesvien charlesvien marked this pull request as ready for review May 7, 2026 19:26
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 7, 2026

Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
apps/code/src/renderer/features/billing/stores/seatStore.ts:227-229
The third fallback to `PLAN_PRO` is a hardcoded guess that will silently emit an incorrect `plan_key` whenever `cancelSeat` is called without a seat loaded in the store (e.g., stale state) and the post-cancel API also returns `null`. Analytics data reporting the wrong cancelled plan is worse than a missing event. If neither the pre-cancel store state nor the post-cancel API response provides a plan key, the track call should be skipped rather than inventing a value.

```suggestion
      const cancelledPlanKey = previousPlanKey ?? seat?.plan_key;
      if (cancelledPlanKey) {
        track(ANALYTICS_EVENTS.SUBSCRIPTION_CANCELLED, {
          plan_key: cancelledPlanKey,
        });
      }
```

### Issue 2 of 2
apps/code/src/renderer/features/billing/stores/seatStore.test.ts:233-255
**Missing test for the `cancelSeat` fallback path**

The sole `cancelSeat` test always pre-seeds the store with a `proSeat`, so `previousPlanKey` is always defined. The fallback branches (`seat?.plan_key` and the hardcoded `PLAN_PRO` default) are never exercised. A test starting with `seat: null` in the store would cover the path where the pre-cancel plan key has to come from the post-cancel API response — and would expose the incorrect-default behaviour described in the inline comment on the implementation.

Reviews (1): Last reviewed commit: "Track individual subscription start and ..." | Re-trigger Greptile

Comment thread apps/code/src/renderer/features/billing/stores/seatStore.ts Outdated
Comment thread apps/code/src/renderer/features/billing/stores/seatStore.test.ts
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 7, 2026

Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
apps/code/src/renderer/features/billing/stores/seatStore.test.ts:282-285
Weak no-call assertion — only checks args, not presence. `not.toHaveBeenCalledWith(...)` passes even if `track` was called with different arguments (e.g., a future event added on the same code path). Use `not.toHaveBeenCalled()` to fully assert that no tracking fires in this branch.

```suggestion
      expect(mockTrack).not.toHaveBeenCalled();
```

### Issue 2 of 2
apps/code/src/renderer/features/billing/stores/seatStore.test.ts:233-287
Prefer parameterised tests here. The three `cancelSeat` tests share the same skeleton — call `cancelSeat()`, assert `cancelSeat` was invoked, then assert on `mockTrack` — varying only `initialSeat`, `getMySeatResponse`, and the expected `track` arguments. An `it.each` table would remove the repetition and make it trivial to add new cases. The same pattern applies to the `upgradeToPro` block above.

Reviews (2): Last reviewed commit: "skip cancel tracking when plan key is un..." | Re-trigger Greptile

@charlesvien charlesvien force-pushed the 05-06-track_individual_subscription_start_and_cancel_events branch from 341073d to 4cdb1d2 Compare May 7, 2026 22:23
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 7, 2026

Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
apps/code/src/renderer/features/billing/stores/seatStore.test.ts:282-285
The assertion uses `not.toHaveBeenCalledWith(event, anything)`, which only checks that `track` was not called with _this specific event and any args_. It would still pass if `track` was called with a different event entirely. Since tracking should be completely skipped on this path, `not.toHaveBeenCalled()` is both cleaner and a stricter guarantee.

```suggestion
      expect(mockTrack).not.toHaveBeenCalled();
```

### Issue 2 of 2
apps/code/src/renderer/features/billing/stores/seatStore.test.ts:233-288
**Prefer parameterised tests for `cancelSeat`**

The three `cancelSeat` tests share the same shape — seed store state, mock `getMySeat`, call `cancelSeat`, assert on `mockTrack` — and differ only in inputs and expected outcome. Collapsing them into a single `it.each` table (with `initialSeat`, `apiSeat`, and `expectedPlanKey` columns) would follow the team's rule of always preferring parameterised tests, make the coverage matrix instantly readable, and ensure future cases get added to one place.

Reviews (3): Last reviewed commit: "skip cancel tracking when plan key is un..." | Re-trigger Greptile

@charlesvien charlesvien force-pushed the 05-06-track_individual_subscription_start_and_cancel_events branch from 4cdb1d2 to a2eaeaf Compare May 7, 2026 22:26
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 7, 2026

Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
apps/code/src/renderer/features/billing/stores/seatStore.test.ts:282-285
The assertion `not.toHaveBeenCalledWith(SUBSCRIPTION_CANCELLED, expect.anything())` only guards against that specific call signature — it would silently pass if `mockTrack` were called with a different event (e.g. `SUBSCRIPTION_STARTED`). Since this test's intent is "no tracking at all on cancel", `not.toHaveBeenCalled()` is the correct, stricter form.

```suggestion
      expect(mockTrack).not.toHaveBeenCalled();
```

### Issue 2 of 2
apps/code/src/renderer/features/billing/stores/seatStore.test.ts:165-214
**Prefer parameterised tests for the two upgrade-path scenarios**

The "upgrades existing free seat to pro" and "upgrades alpha pro seat to paid pro" tests are structurally identical — they differ only in the pre-existing plan key and the expected `previous_plan_key` assertion. Per the project's convention, these should be collapsed into a single `it.each` table, e.g. `it.each([[PLAN_FREE, PLAN_FREE], [PLAN_PRO_ALPHA, PLAN_PRO_ALPHA]])("upgrades %s seat to pro", ...)`. This avoids repeating the same setup/assertion block twice and makes it trivial to add new plan variants.

Reviews (4): Last reviewed commit: "skip cancel tracking when plan key is un..." | Re-trigger Greptile

@charlesvien charlesvien merged commit 1663f08 into main May 7, 2026
17 of 18 checks passed
Copy link
Copy Markdown
Member Author

Merge activity

@charlesvien charlesvien deleted the 05-06-track_individual_subscription_start_and_cancel_events branch May 7, 2026 22:44
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