Skip to content

Commit b77eb4b

Browse files
committed
!F add include_event_description option to log event descriptions and update related documentation
1 parent 23932f4 commit b77eb4b

17 files changed

Lines changed: 172 additions & 33 deletions

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
All notable changes to this project will be documented in this file.
44

55
## [0.1.6] - Unreleased
6+
- Add `include_event_description` config option to optionally include an
7+
event's `description` property inside the emitted `logger.logEvent`
8+
parameters map. This flag defaults to `false` to preserve existing
9+
behavior; enable it via `analytics_gen.yaml` (key: `include_event_description`).
10+
- The code generator now inserts a `'description'` key for events that
11+
have a non-empty description when the flag is enabled.
12+
- The example config and `README.md` were updated to document this flag.
13+
- Unit tests assert that descriptions are properly included when enabled
14+
and omitted otherwise.
615
- Support interpolated placeholders in custom `event_name` strings
716
- You can now include parameter placeholders in `event_name` using
817
`{parameter_name}` and the code generator will replace them with

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ analytics_gen:
199199
generate_json: true
200200
generate_sql: true
201201
generate_plan: true
202+
# When true, event descriptions are included in the emitted
203+
# `logger.logEvent` parameters under the key `description`. Defaults to
204+
# `false`.
205+
# include_event_description: false
202206
```
203207

204208
When `generate_docs` or any export flag is enabled in the config, the CLI will run those generators automatically (no need to pass `--docs` or `--exports`). Use `--no-docs` or `--no-exports` to temporarily override config.

example/analytics_gen.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
analytics_gen:
22
# Path to YAML event files (relative to project root)
33
events_path: events
4-
4+
55
# Path where generated code will be written (relative to lib/)
66
output_path: src/analytics/generated
7-
7+
88
# Path for documentation (optional)
99
docs_path: docs/analytics_events.md
10-
10+
1111
# Path for export files (optional)
1212
exports_path: assets/generated
13-
13+
1414
# Enable/disable various generators
1515
generate_docs: true
1616
generate_csv: true
1717
generate_json: true
1818
generate_sql: true
1919
generate_plan: true
20+
# If true, each generated logEvent call will include the event description
21+
# under the 'description' key in the parameters map. Default: false
22+
include_event_description: true

example/assets/generated/analytics_events.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Domain,Action,Event Name,Description,Parameters,Deprecated,Replacement
22
auth,login,auth: login,User logs in to the application,"method (string): Login method (email, google, apple)",true,auth.login_v2
33
auth,login_v2,auth: login_v2,User logs in to the application (v2),"method (string): Login method v2 (email, google, apple)",false,
44
auth,logout,auth: logout,User logs out,,false,
5+
auth,phone_login,Auth: Phone,When user logs in via phone,user_exists (bool?): Whether the user exists or not,false,
56
auth,signup,auth: signup,User creates a new account,method (string); referral_code (string?): Optional referral code used during signup,false,
67
purchase,cancelled,purchase: cancelled,User cancelled a purchase,product_id (string); reason (string?): Reason for cancellation,false,
78
purchase,completed,purchase: completed,User completed a purchase,currency (string); price (double); product_id (string); quantity (int): Number of items purchased,false,
0 Bytes
Binary file not shown.

example/assets/generated/analytics_events.json

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"metadata": {
3-
"fingerprint": "-16b6279a2f73b424",
3+
"fingerprint": "-3889fe4dbbfad68f",
44
"total_domains": 3,
5-
"total_events": 7,
6-
"total_parameters": 13
5+
"total_events": 8,
6+
"total_parameters": 14
77
},
88
"domains": [
99
{
1010
"name": "auth",
11-
"event_count": 4,
12-
"parameter_count": 4,
11+
"event_count": 5,
12+
"parameter_count": 5,
1313
"events": [
1414
{
1515
"name": "login",
@@ -47,6 +47,20 @@
4747
"deprecated": false,
4848
"parameters": []
4949
},
50+
{
51+
"name": "phone_login",
52+
"event_name": "Auth: Phone",
53+
"description": "When user logs in via phone",
54+
"deprecated": false,
55+
"parameters": [
56+
{
57+
"name": "user_exists",
58+
"type": "bool",
59+
"nullable": true,
60+
"description": "Whether the user exists or not"
61+
}
62+
]
63+
},
5064
{
5165
"name": "signup",
5266
"event_name": "auth: signup",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"metadata":{"fingerprint":"-16b6279a2f73b424","total_domains":3,"total_events":7,"total_parameters":13},"domains":[{"name":"auth","event_count":4,"parameter_count":4,"events":[{"name":"login","event_name":"auth: login","description":"User logs in to the application","deprecated":true,"replacement":"auth.login_v2","parameters":[{"name":"method","type":"string","nullable":false,"description":"Login method (email, google, apple)"}]},{"name":"login_v2","event_name":"auth: login_v2","description":"User logs in to the application (v2)","deprecated":false,"parameters":[{"name":"method","type":"string","nullable":false,"description":"Login method v2 (email, google, apple)"}]},{"name":"logout","event_name":"auth: logout","description":"User logs out","deprecated":false,"parameters":[]},{"name":"signup","event_name":"auth: signup","description":"User creates a new account","deprecated":false,"parameters":[{"name":"method","type":"string","nullable":false},{"name":"referral_code","type":"string","nullable":true,"description":"Optional referral code used during signup"}]}]},{"name":"purchase","event_count":2,"parameter_count":6,"events":[{"name":"cancelled","event_name":"purchase: cancelled","description":"User cancelled a purchase","deprecated":false,"parameters":[{"name":"product_id","type":"string","nullable":false},{"name":"reason","type":"string","nullable":true,"description":"Reason for cancellation"}]},{"name":"completed","event_name":"purchase: completed","description":"User completed a purchase","deprecated":false,"parameters":[{"name":"currency","type":"string","nullable":false},{"name":"price","type":"double","nullable":false},{"name":"product_id","type":"string","nullable":false},{"name":"quantity","type":"int","nullable":false,"description":"Number of items purchased"}]}]},{"name":"screen","event_count":1,"parameter_count":3,"events":[{"name":"view","event_name":"Screen: {screen_name}","description":"User views a screen","deprecated":false,"parameters":[{"name":"duration_ms","type":"int","nullable":true,"description":"Time spent on previous screen in milliseconds"},{"name":"previous_screen","type":"string","nullable":true,"description":"Name of the previous screen"},{"name":"screen_name","type":"string","nullable":false}]}]}]}
1+
{"metadata":{"fingerprint":"-3889fe4dbbfad68f","total_domains":3,"total_events":8,"total_parameters":14},"domains":[{"name":"auth","event_count":5,"parameter_count":5,"events":[{"name":"login","event_name":"auth: login","description":"User logs in to the application","deprecated":true,"replacement":"auth.login_v2","parameters":[{"name":"method","type":"string","nullable":false,"description":"Login method (email, google, apple)"}]},{"name":"login_v2","event_name":"auth: login_v2","description":"User logs in to the application (v2)","deprecated":false,"parameters":[{"name":"method","type":"string","nullable":false,"description":"Login method v2 (email, google, apple)"}]},{"name":"logout","event_name":"auth: logout","description":"User logs out","deprecated":false,"parameters":[]},{"name":"phone_login","event_name":"Auth: Phone","description":"When user logs in via phone","deprecated":false,"parameters":[{"name":"user_exists","type":"bool","nullable":true,"description":"Whether the user exists or not"}]},{"name":"signup","event_name":"auth: signup","description":"User creates a new account","deprecated":false,"parameters":[{"name":"method","type":"string","nullable":false},{"name":"referral_code","type":"string","nullable":true,"description":"Optional referral code used during signup"}]}]},{"name":"purchase","event_count":2,"parameter_count":6,"events":[{"name":"cancelled","event_name":"purchase: cancelled","description":"User cancelled a purchase","deprecated":false,"parameters":[{"name":"product_id","type":"string","nullable":false},{"name":"reason","type":"string","nullable":true,"description":"Reason for cancellation"}]},{"name":"completed","event_name":"purchase: completed","description":"User completed a purchase","deprecated":false,"parameters":[{"name":"currency","type":"string","nullable":false},{"name":"price","type":"double","nullable":false},{"name":"product_id","type":"string","nullable":false},{"name":"quantity","type":"int","nullable":false,"description":"Number of items purchased"}]}]},{"name":"screen","event_count":1,"parameter_count":3,"events":[{"name":"view","event_name":"Screen: {screen_name}","description":"User views a screen","deprecated":false,"parameters":[{"name":"duration_ms","type":"int","nullable":true,"description":"Time spent on previous screen in milliseconds"},{"name":"previous_screen","type":"string","nullable":true,"description":"Name of the previous screen"},{"name":"screen_name","type":"string","nullable":false}]}]}]}

example/assets/generated/create_database.sql

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- Analytics Events Database Schema
2-
-- Fingerprint: -16b6279a2f73b424 (domains=3, events=7, parameters=13)
2+
-- Fingerprint: -3889fe4dbbfad68f (domains=3, events=8, parameters=14)
33

44
-- Create domains table
55
CREATE TABLE IF NOT EXISTS domains (
@@ -39,7 +39,7 @@ CREATE INDEX IF NOT EXISTS idx_events_domain ON events(domain_id);
3939
CREATE INDEX IF NOT EXISTS idx_parameters_event ON parameters(event_id);
4040

4141
-- Insert domain data
42-
INSERT INTO domains (id, name, event_count, parameter_count) VALUES (1, 'auth', 4, 4);
42+
INSERT INTO domains (id, name, event_count, parameter_count) VALUES (1, 'auth', 5, 5);
4343
INSERT INTO domains (id, name, event_count, parameter_count) VALUES (2, 'purchase', 2, 6);
4444
INSERT INTO domains (id, name, event_count, parameter_count) VALUES (3, 'screen', 1, 3);
4545

@@ -49,21 +49,23 @@ INSERT INTO parameters (event_id, name, type, nullable, description, allowed_val
4949
INSERT INTO events (id, domain_id, name, event_name, description, deprecated, replacement) VALUES (2, 1, 'login_v2', 'auth: login_v2', 'User logs in to the application (v2)', 0, NULL);
5050
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (2, 'method', 'string', 0, 'Login method v2 (email, google, apple)', NULL);
5151
INSERT INTO events (id, domain_id, name, event_name, description, deprecated, replacement) VALUES (3, 1, 'logout', 'auth: logout', 'User logs out', 0, NULL);
52-
INSERT INTO events (id, domain_id, name, event_name, description, deprecated, replacement) VALUES (4, 1, 'signup', 'auth: signup', 'User creates a new account', 0, NULL);
53-
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (4, 'method', 'string', 0, NULL, NULL);
54-
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (4, 'referral_code', 'string', 1, 'Optional referral code used during signup', NULL);
55-
INSERT INTO events (id, domain_id, name, event_name, description, deprecated, replacement) VALUES (5, 2, 'cancelled', 'purchase: cancelled', 'User cancelled a purchase', 0, NULL);
56-
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (5, 'product_id', 'string', 0, NULL, NULL);
57-
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (5, 'reason', 'string', 1, 'Reason for cancellation', NULL);
58-
INSERT INTO events (id, domain_id, name, event_name, description, deprecated, replacement) VALUES (6, 2, 'completed', 'purchase: completed', 'User completed a purchase', 0, NULL);
59-
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (6, 'currency', 'string', 0, NULL, NULL);
60-
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (6, 'price', 'double', 0, NULL, NULL);
52+
INSERT INTO events (id, domain_id, name, event_name, description, deprecated, replacement) VALUES (4, 1, 'phone_login', 'Auth: Phone', 'When user logs in via phone', 0, NULL);
53+
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (4, 'user_exists', 'bool', 1, 'Whether the user exists or not', NULL);
54+
INSERT INTO events (id, domain_id, name, event_name, description, deprecated, replacement) VALUES (5, 1, 'signup', 'auth: signup', 'User creates a new account', 0, NULL);
55+
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (5, 'method', 'string', 0, NULL, NULL);
56+
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (5, 'referral_code', 'string', 1, 'Optional referral code used during signup', NULL);
57+
INSERT INTO events (id, domain_id, name, event_name, description, deprecated, replacement) VALUES (6, 2, 'cancelled', 'purchase: cancelled', 'User cancelled a purchase', 0, NULL);
6158
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (6, 'product_id', 'string', 0, NULL, NULL);
62-
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (6, 'quantity', 'int', 0, 'Number of items purchased', NULL);
63-
INSERT INTO events (id, domain_id, name, event_name, description, deprecated, replacement) VALUES (7, 3, 'view', 'Screen: {screen_name}', 'User views a screen', 0, NULL);
64-
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (7, 'duration_ms', 'int', 1, 'Time spent on previous screen in milliseconds', NULL);
65-
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (7, 'previous_screen', 'string', 1, 'Name of the previous screen', NULL);
66-
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (7, 'screen_name', 'string', 0, NULL, NULL);
59+
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (6, 'reason', 'string', 1, 'Reason for cancellation', NULL);
60+
INSERT INTO events (id, domain_id, name, event_name, description, deprecated, replacement) VALUES (7, 2, 'completed', 'purchase: completed', 'User completed a purchase', 0, NULL);
61+
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (7, 'currency', 'string', 0, NULL, NULL);
62+
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (7, 'price', 'double', 0, NULL, NULL);
63+
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (7, 'product_id', 'string', 0, NULL, NULL);
64+
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (7, 'quantity', 'int', 0, 'Number of items purchased', NULL);
65+
INSERT INTO events (id, domain_id, name, event_name, description, deprecated, replacement) VALUES (8, 3, 'view', 'Screen: {screen_name}', 'User views a screen', 0, NULL);
66+
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (8, 'duration_ms', 'int', 1, 'Time spent on previous screen in milliseconds', NULL);
67+
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (8, 'previous_screen', 'string', 1, 'Name of the previous screen', NULL);
68+
INSERT INTO parameters (event_id, name, type, nullable, description, allowed_values) VALUES (8, 'screen_name', 'string', 0, NULL, NULL);
6769

6870
-- Create useful views
6971
CREATE VIEW IF NOT EXISTS events_with_domain AS

example/docs/analytics_events.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Analytics Events Documentation
22

3-
Fingerprint: `-16b6279a2f73b424`
4-
Domains: 3 | Events: 7 | Parameters: 13
3+
Fingerprint: `-3889fe4dbbfad68f`
4+
Domains: 3 | Events: 8 | Parameters: 14
55

66
## Table of Contents
77

@@ -12,18 +12,19 @@ Domains: 3 | Events: 7 | Parameters: 13
1212
## Summary
1313

1414
- **Total Domains**: 3
15-
- **Total Events**: 7
16-
- **Total Parameters**: 13
15+
- **Total Events**: 8
16+
- **Total Parameters**: 14
1717

1818
## auth
1919

20-
Events: 4 | Parameters: 4
20+
Events: 5 | Parameters: 5
2121

2222
| Event | Description | Status | Parameters |
2323
|-------|-------------|--------|------------|
2424
| auth: login | User logs in to the application | **Deprecated** -> `auth.login_v2` | `method` (string): Login method (email, google, apple) |
2525
| auth: login_v2 | User logs in to the application (v2) | Active | `method` (string): Login method v2 (email, google, apple) |
2626
| auth: logout | User logs out | Active | - |
27+
| Auth: Phone | When user logs in via phone | Active | `user_exists` (bool?): Whether the user exists or not |
2728
| auth: signup | User creates a new account | Active | `method` (string)<br>`referral_code` (string?): Optional referral code used during signup |
2829

2930
### Code Examples

example/events/auth.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,11 @@ auth:
2626
referral_code:
2727
type: string?
2828
description: Optional referral code used during signup
29+
30+
phone_login:
31+
description: When user logs in via phone
32+
event_name: "Auth: Phone"
33+
parameters:
34+
user_exists:
35+
bool?:
36+
description: Whether the user exists or not

0 commit comments

Comments
 (0)