Skip to content

feat: CLI - send invitation analytics events from zitadel invitation create and cancel - #2932

Closed
vitorbari wants to merge 44 commits into
mainfrom
2859-cli-invitation-analytics
Closed

vitorbari wants to merge 44 commits into
mainfrom
2859-cli-invitation-analytics

Conversation

@vitorbari

@vitorbari vitorbari commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #2929 — merge after it.

Summary

Closes #2859 for the CLI (ADR 086 §9). Stacked on #2929.

  • zitadel invitation create, including --replaces, sends invitation_created once the API confirms the create, with role (project_viewer, project_editor, project_admin; team_member later) and invitation_journey_id. It replaces the role/is_replace dimensions feat: CLI - add zitadel invitation create, list, get and cancel #2929 records.
  • zitadel invitation cancel sends invitation_cancelled with the same properties once the API confirms the cancel, per a dated amendment to ADR 086: without it a cancelled journey reads as one nobody opened. The cancel answers 204, so the command now reads the invitation before confirming; the question names who it is for and its role, and an accepted or expired invitation is refused before anything is asked. A declined invitation is removed without an event: its journey already ended with invitation_rejected.
  • BaseCommand.trackEvent sends a product event with the header and context every CLI event carries, behind the same consent gate.
  • product-analytics-events.yaml lists the CLI's two events as emitted, the console's invitation_created, invitation_accepted, invitation_rejected and invitation_cancelled as planned (Analytics: invitation events #2859), and the invitation_journey_id property.
  • catalog.test.ts holds every trackEvent call's properties to the catalog.
  • The telemetry docs page and apps/cli/AGENTS.md say when a command sends an event of its own.

Notes

  • The Vercel sink copies every event, so the catalog lists [mixpanel, vercel]. The copy keeps only the eight header keys, never the journey id. Restricting it to Mixpanel would need a sink filter.
  • Mixpanel is paused, so nothing reaches it until its region is fixed.
  • The console events and its Mixpanel sink remain under Analytics: invitation events #2859.

🤖 Generated with Claude Code

vitorbari and others added 4 commits November 10, 2026 14:43
Hand-written commands over the invitations contract (#2849), in a new
Project administration help group. The link appears only in create's
output; telemetry records the role and whether it replaced one.

Refs #2858

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The CLI loads commands from an explicit COMMANDS table, so the
invitation commands were unreachable and missing from the reference
and the docs. Adds the topic and its help group row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implements the CLI half of #2859 (ADR 086 §9): after the API confirms a
create or replace, the command sends invitation_created with role and
invitation_journey_id through a new BaseCommand.trackEvent, replacing
the role/is_replace dimensions. The catalog lists the CLI event as
emitted and the console's three invitation events as planned, and a
catalog test holds every trackEvent call's properties to the catalog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cloud Ready Ready Preview Nov 16, 2026 11:35pm UTC

Request Review

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: e037975

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
@zitadel/cli Minor
@zitadel/testing Minor
@zitadel/server Minor
@zitadel/server-darwin-arm64 Minor
@zitadel/server-darwin-x64 Minor
@zitadel/server-linux-arm64 Minor
@zitadel/server-linux-x64 Minor
@zitadel/server-win32-x64 Minor
@zitadel/api Minor
@zitadel/components Minor
@zitadel/config Minor
@zitadel/sdk-angular Minor
@zitadel/sdk-core Minor
@zitadel/sdk-next Minor
@zitadel/sdk-nuxt Minor
@zitadel/sdk-qwik Minor
@zitadel/sdk-qwik-router Minor
@zitadel/sdk-react Minor
@zitadel/sdk-solid Minor
@zitadel/sdk-solid-start Minor
@zitadel/sdk-svelte Minor
@zitadel/sdk-sveltekit Minor
@zitadel/sdk-tanstack-start Minor
@zitadel/sdk-vue Minor
@zitadel/cloud Patch
@zitadel/client-sdk-contract Patch
@zitadel/server-sdk-contract Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

ADR 086 gains a dated amendment: a cancelled journey ended at
invitation_created and read as one nobody opened. invitation cancel now
reads the invitation before confirming, names it in the question,
refuses one that is no longer pending, and sends invitation_cancelled
with role and invitation_journey_id after the delete. The catalog lists
it emitted for the CLI and planned for the console.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vitorbari vitorbari changed the title feat: send invitation_created from zitadel invitation create feat: send invitation analytics events from zitadel invitation create and cancel Nov 10, 2026
@vitorbari vitorbari changed the title feat: send invitation analytics events from zitadel invitation create and cancel feat: CLI - send invitation analytics events from zitadel invitation create and cancel Nov 11, 2026
vitorbari and others added 5 commits November 12, 2026 08:09
…ommands

# Conflicts:
#	apps/cli/src/lib/backend/index.ts
#	apps/cli/tests/unit/commands/api-coverage.test.ts
…analytics

# Conflicts:
#	apps/cli/src/commands/invitation/cancel.ts
#	apps/cli/src/commands/invitation/create.ts
#	apps/cli/src/lib/backend/index.ts
A dry run now answers with the request it would send. --replaces reads
the original first: an accepted one is refused before anything is
asked, and a replacement without --name keeps the original's name, as
the server does. The name prompt asks one question, and list gains a
unit test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…analytics

# Conflicts:
#	apps/cli/skills/zitadel-cli/SKILL.md
#	apps/cli/src/commands/invitation/create.ts
A dry run of invitation cancel <id> now reads nothing: the read that
names the invitation in the question moves into prepare. Also lists the
amendment in the ADR index, fixes the telemetry page's grammar, and
adds a changeset for the invitation events.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vitorbari and others added 2 commits November 12, 2026 09:46
- create --dry-run answers before connecting or reading the original.
- cancel --dry-run needs the id instead of reading the pending list.
- The printed link and the picker's hints are escaped for the terminal.
- --name counts characters, as the API's maxLength does.
- The API reference's CLI samples spell invitation create and list
  with their flags, and fall back to the api call for team invitations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…analytics

# Conflicts:
#	apps/cli/skills/zitadel-cli/SKILL.md
#	apps/cli/src/commands/invitation/cancel.ts
vitorbari and others added 2 commits November 12, 2026 11:10
A non-interactive run, like a dry run, now refuses an omitted id before
reading the pending list, so a down server cannot hide the missing
input. Regenerates the CLI README, which lacked the invitation commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…analytics

# Conflicts:
#	apps/cli/src/commands/invitation/cancel.ts
vitorbari and others added 2 commits November 12, 2026 12:24
Follow-ups and retries are { id, flags } suggestions, refusals take no
suggester, list declares --all's exclusion through relatedFlags, and its
page carries only the token. Regenerates the CLI README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vitorbari and others added 3 commits November 16, 2026 19:24
Adapt the invitation commands to main: the task-based help groups put
them under Users and access, the test fixtures moved to tests/fixtures,
and the invitation contract now names the path parameter invitation_id,
reports responded_by/responded_at and takes status as a list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…analytics

The server now deletes a declined invitation on cancel, so `invitation
cancel` accepts one too and sends invitation_cancelled only for a pending
invitation: a declined journey already ended with invitation_rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-list-contract

The invitation contract landed on main, so the API, ADR and generated
files take main's versions and this branch keeps only the CLI changes:
the list's default statuses and repeated --status, and the cancel picker
offering declined invitations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from 2858-cli-invitation-commands to main November 16, 2026 18:41
@vitorbari
vitorbari added this pull request to stack #3175 November 16, 2026 18:42
@vitorbari
vitorbari marked this pull request as ready for review November 16, 2026 18:43
Copilot AI balanced review requested due to automatic review settings November 16, 2026 18:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Cancellation telemetry relies on stale invitation status and can distort acceptance-rate metrics, while event emission and opt-out behavior lack runtime tests.

2 open issues
What changed in this PR

Adds consent-gated invitation analytics to the CLI, correlating creation and cancellation events through a shared journey ID.

Changes:

  • Adds shared product-event dispatch and emits invitation events after successful API operations.
  • Reads invitation details before cancellation, improves confirmation text, and refuses accepted or expired invitations.
  • Updates analytics contracts, documentation and tests; console events remain planned.
File Description
packages/​api-mock/​src/​platform-handlers.ts Adds declined-invitation test setup.
docs/​product-analytics-events.yaml Catalogs CLI events, planned console events and journey IDs.
docs/​adrs/​README.md Updates the invitation amendment summary.
docs/​adrs/​086-invitations.md Defines cancellation analytics semantics.
apps/​docs/​content/​docs/​reference/​cli/​telemetry.mdx Documents invitation events and privacy boundaries.
apps/​cli/​tests/​unit/​lib/​telemetry/​catalog.test.ts Checks product-event declarations against the catalog.
apps/​cli/​tests/​integration/​invitation-cancel.spec.ts Covers declined removal and the updated refusal code.
apps/​cli/​tests/​helpers/​platform.ts Exposes declined-invitation setup to tests.
apps/​cli/​src/​lib/​oclif/​base.ts Adds consent-gated product-event dispatch.
apps/​cli/​src/​lib/​backend/​services/​invitation.ts Adds invitation grant labels for analytics.
apps/​cli/​src/​lib/​backend/​index.ts Exports the grant-label helper.
apps/​cli/​src/​cli/​commands/​invitation/​create.ts Emits creation events with role and journey ID.
apps/​cli/​src/​cli/​commands/​invitation/​cancel.ts Adds state-aware confirmation and cancellation events.
apps/​cli/​skills/​zitadel-cli/​SKILL.md Documents cancellation validation behavior.
apps/​cli/​AGENTS.md Clarifies when commands should emit product events.
.changeset/​cli-invitation-analytics.md Adds the CLI release note.

Review effort: Balanced

Comment thread apps/cli/src/lib/oclif/base.ts Resolved
vitorbari and others added 3 commits November 16, 2026 18:49
A list that found nothing drops its footer, so the empty message carries
the hint. The docs' sample for an unfiltered invitation list names every
status, since the command alone leaves accepted ones out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
trackEvent sends the event with its properties and the command's context,
and nothing when telemetry is off. invitation cancel sends
invitation_cancelled once a pending invitation is cancelled, and none for
a declined one, a failed cancel, a dry run or a declined confirmation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The new invitation_created event lacks command-level tests for delivery timing, response properties, and non-emitting paths, while the release note misstates cancellation behavior for rejected invitations.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Add command-level invitation_created event tests

apps/​cli/​src/​cli/​commands/​invitation/​create.ts:153

The new invitation_created emission has no command-level assertions: create.test.ts covers prompts, replacement and dry runs, while the catalog test checks only property names and the base-command tests invoke trackEvent directly. Add create-command tests verifying one event after a successful create and replacement, using the response's role and journey ID, and no event after a failed create, dry run or declined confirmation. This protects the delivery timing and replacement correlation that this PR introduces.

Low severity Clarify cancellation behavior in the release note

.changeset/​cli-invitation-analytics.md:5

The release note says cancellation refuses every invitation that is no longer pending, but readCancellable explicitly allows rejected invitations, and the new integration test verifies their removal. It also implies every successful cancel sends an event, although rejected invitations deliberately send none. Please distinguish pending cancellations from declined-record removal so the published changelog describes the actual behavior.

2 resolved since last review

Review effort: Balanced

vitorbari and others added 3 commits November 16, 2026 23:30
The invitation analytics now stack on top of this branch instead of under
it, so this branch keeps only the list's default statuses and the cancel
flow: the read before the question, the refusal of an accepted or expired
invitation, and the picker offering declined ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Restores the invitation analytics on top of the list and cancel-flow
branch, which now merges first: trackEvent, invitation_created and
invitation_cancelled, the catalog, the ADR 086 amendment and their tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vitorbari

Copy link
Copy Markdown
Contributor Author

Replaced by #3177, stacked on #3176: the order is inverted so the cancel-flow changes merge first and this PR carries only the analytics.

This branch was successfully deployed

1 active deployment
Preview — e037975b Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Analytics: invitation events

2 participants