Web Codegen Setup
A guide to integrating EventPanel CLI into a web / Node.js project (NestJS demo) for type-safe analytics event code generation in TypeScript.
Live Demo: Try the Interactive Demo β
Explore how analytics events are used in our frontend demo project with generated, type-safe TypeScript code.
Overviewβ
EventPanel CLI generates type-safe TypeScript analytics events from YAML configuration files, ensuring compile-time safety and reducing runtime errors in your web application or API services.
Featuresβ
- π― Type-Safe Analytics: Generated analytics events with compile-time safety
- π YAML Configuration: Event definitions managed through
EventPanel.yaml - π Code Generation: Automated TypeScript code generation from event schemas
- π‘οΈ Type Safety: Compile-time validation of event parameters
Installationβ
Prerequisitesβ
- Node.js 18 or later
- Yarn or npm
- Existing web or API project (the demo uses NestJS)
Install EventPanel CLIβ
Option 1: Homebrew (Recommended)β
brew tap eventpanel/eventpanel
brew install eventpanel
Option 2: Manual Installationβ
Download the latest release from the EventPanel CLI repository and add it to your PATH.
Verify Installationβ
eventpanel --version
Project Initializationβ
Step 1: Initialize EventPanel Configurationβ
Run the initialization command in your project root directory:
eventpanel init --output src/analytics/events.ts --source web
This command will:
- Create
EventPanel.yamlconfiguration file - Set up the default TypeScript configuration
- Configure the output path for generated events
Note: Replace the output path with your actual project structure. For example:
src/analytics/events.tsapps/api/src/analytics/events.tspackages/analytics/src/generated/events.ts
The generated EventPanel.yaml will look similar to:
source: web
plugin:
typescriptgen:
outputFilePath: src/analytics/events.ts
namespace: AnalyticsEvents
shouldGenerateType: true
eventClassName: AnalyticsEvent
documentation: true
imports: # (Optional)
- mixpanel-browser
events: []
You can then add your events to the events array or configure them through the EventPanel web interface.
Step 2: Set API Tokenβ
After initialization, you need to authenticate with EventPanel by setting your API token:
-
Create an API Token:
- Go to your EventPanel workspace settings
- Navigate to the API tokens section
- Create a new token
-
Set the Token:
eventpanel set-token YOUR_API_TOKEN
The token will be securely stored and used for all authenticated requests to EventPanel.
Note: Replace YOUR_API_TOKEN with the actual token you created in the workspace settings.
Step 3: Add Events to Configurationβ
After initialization, you can add events to your EventPanel.yaml using the eventpanel add command. There are several ways to add events:
Add a Single Event by IDβ
# Add latest version of an event
eventpanel add DWnQMGoYrvUyaTGpbmvr9
# Add specific version of an event
eventpanel add DWnQMGoYrvUyaTGpbmvr9 --version 2
Add an Event by Nameβ
# Add latest version of an event by name
eventpanel add --name "Dialog Screen Test Option Tapped"
Add All Eventsβ
# Add all available events for the configured source
eventpanel add --all
Add Events by Categoryβ
# Add all events from a category by ID
eventpanel add --category-id abc123
# Add all events from a category by name
eventpanel add --category-name "Dialog Screen"
Manual Configurationβ
You can also manually edit EventPanel.yaml to add events:
events:
- id: YOUR_EVENT_ID_1
- id: YOUR_EVENT_ID_2
version: 2
Sync workspace latest revisions into YAMLβ
eventpanel pull fetches the scheme for each event using the version from EventPanel.yaml, or 1 if version is omitted β it does not automatically pick the newest catalog revision for that event id. After the workspace bumps an eventβs schema revision, run:
eventpanel outdated # list YAML entries that lag workspace latest
eventpanel update # write newer version: lines into EventPanel.yaml, then pull + generate (defaults)
Use eventpanel update <id> [<id>...] to update specific events. This is CLI update β not the EventPanel MCP tool update_event, which edits the live catalog on the server but does not change your local YAML.
Step 4: Integrate Codegen into Your Buildβ
For backend / Node.js projects, you can run generation:
- On demand (e.g. before commits or deployments)
- As part of your build scripts
Add a script to your package.json:
{
"scripts": {
"analytics:generate": "eventpanel generate",
"analytics:outdated": "eventpanel outdated",
"analytics:update": "eventpanel update",
"build": "eventpanel generate && nest build"
}
}
You can also run generation manually:
eventpanel generate
Step 5: Install and Run the Demo App (Optional)β
If you are using the EventPanel web demo:
yarn install
eventpanel generate
yarn start:dev
Usageβ
Basic Event Trackingβ
The generated TypeScript code exposes a namespace (for example AnalyticsEvents) with strongly-typed factory functions for each event.
import { AnalyticsEvents } from './analytics/events';
// Track a dialog screen test option tap
const event = AnalyticsEvents.dialogScreenTestOptionTapped();
analytics.track(event);
// Example event payload shape
// {
// name: 'Dialog Screen Test Option Tapped',
// parameters: {}
// }
Generated Code Structureβ
The CLI generates TypeScript code in the following structure (demo app):
src/
βββ analytics/
β βββ events.ts # Generated event code
βββ app.controller.ts # HTTP controller
βββ app.service.ts # Service with analytics integration
βββ app.module.ts # Root NestJS module
βββ main.ts # App entry point
Example Generated Eventsβ
Your generated events.ts will contain type-safe helpers (shape simplified):
// Generated using EventPanel β https://github.com/eventpanel/eventpanel-cli
export namespace AnalyticsEvents {
/**
* User selected an answer option in a test question
*/
export function dialogScreenTestOptionTapped(): AnalyticsEvent {
return {
name: 'Dialog Screen Test Option Tapped',
parameters: {},
};
}
}
export interface AnalyticsEvent {
name: string;
parameters: Record<string, unknown>;
}
The actual structure may vary based on the CLI version and configuration, but the core ideas are:
- Strongly-typed event names
- Strongly-typed parameters
- Centralized, generated API for analytics events
Configuration Referenceβ
EventPanel.yaml Structureβ
source: web # Event source
plugin:
typescriptgen:
outputFilePath: src/analytics/events.ts
namespace: AnalyticsEvents # Namespace for generated code
shouldGenerateType: true # Generate the event type
eventClassName: AnalyticsEvent # Base event class / interface name
documentation: true # Include documentation comments
imports: # (Optional) Additional TypeScript imports
- mixpanel-browser
events:
- id: EVENT_ID # Event ID from EventPanel
version: 1 # Event schema version
Plugin Optionsβ
| Option | Type | Required | Description |
|---|---|---|---|
outputFilePath | String | Yes | Path to the generated TypeScript file |
namespace | String | Yes | Namespace for generated event types |
shouldGenerateType | Bool | Yes | Generate the event type definition |
eventClassName | String | Yes | Base event class / interface name |
documentation | Bool | Yes | Include documentation comments in generated code |
imports | [String] | No | Additional TypeScript import statements to include in the generated file |
Adding Events Command Referenceβ
The eventpanel add command provides multiple ways to add events:
| Command | Description |
|---|---|
eventpanel add <event-id> | Add latest version of an event by ID |
eventpanel add <event-id> --version <version> | Add specific version of an event |
eventpanel add --name <event-name> | Add latest version of an event by name |
eventpanel add --all | Add all available events for the configured source |
eventpanel add --category-id <id> | Add all events from a category by ID |
eventpanel add --category-name <name> | Add all events from a category by name |
Options:
--scheme-update/--no-scheme-update: Control whether to apply scheme updates during generation (default: enabled)
Example Configurationβ
A complete example configuration for the web demo:
source: web
plugin:
typescriptgen:
outputFilePath: src/analytics/events.ts
namespace: AnalyticsEvents
shouldGenerateType: true
eventClassName: AnalyticsEvent
documentation: true
imports:
- mixpanel-browser
events:
- id: F53ZoV4lBswnVy_wWj8kU # Dialog Screen Test Option Tapped
version: 2
Tip: You can also manage events through the EventPanel web interface, and they will be synced to your EventPanel.yaml file.
Project Structure Exampleβ
Typical NestJS demo layout with analytics:
src/
βββ analytics/
β βββ analytics-event.interface.ts # Base analytics event interface (optional)
β βββ events.ts # Generated event code
βββ app.controller.ts # HTTP controller
βββ app.service.ts # Service with analytics integration
βββ app.module.ts # Root NestJS module
βββ main.ts # App entry point
Authenticationβ
Setting API Tokenβ
The EventPanel CLI requires authentication to fetch event schemas from your workspace. After running eventpanel init, you must set your API token:
eventpanel set-token YOUR_API_TOKEN
How to get your API token:
- Log in to EventPanel web interface
- Navigate to your workspace settings
- Go to the API tokens section
- Create a new token
- Copy the token and use it with the
set-tokencommand
The token is securely stored locally and will be used for all authenticated CLI operations.
Verifying Authenticationβ
After setting the token, you can verify it works by running:
eventpanel generate
If authentication fails, you'll see an error message. Make sure:
- The token is valid and not expired
- The token has the necessary permissions for your workspace
- You're connected to the internet
Learn Moreβ
- π EventPanel CLI
- π EventPanel Website
- π NestJS Documentation