Appearance
Codegen Schema ​
The codegen config JS file defines how your analytics types and tracking configuration should be generated. It purposefully uses a .js module so that CI can inject env variables into the config.
Note: the voltage codegen config file must be named "voltage.config.js".
Configuration ​
Field | Type | Required | Description |
---|---|---|---|
events | string | yes | Path to the events file that types & tracking config will be generated from |
groups | string[] | no | Paths to group file(s) for tracked events |
dimensions | string[] | no | Paths to dimension file(s) for tracked events |
meta | string | no | Path to meta file(s) to extend tracked events |
disableComments | boolean | no | Disable JSDoc style comments in generated files |
eventKeyPropertyName | string | no | Auto-track the event key under this property name |
output | string | yes | File path for generated types & tracking config |
Example ​
javascript
export default {
generates: [
{
events: "./analytics/events/unauthed-events.volt.yaml",
meta: './analytics/meta/global-event-meta.volt.yaml',
output: "/__analytics_generated__/unauthed-analytics.ts"
},
{
events: "./analytics/events/authed-events.volt.yaml",
groups: [
"./analytics/groups/user-group.volt.yaml",
"./analytics/groups/team-group.volt.yaml"
],
dimensions: [
"./analytics/dimensions/user-role-dimensions.volt.yaml",
"./analytics/dimensions/team-plan-dimensions.volt.yaml"
],
meta: './analytics/meta/global-event-meta.volt.yaml',
output: "/__analytics_generated__/authed-analytics.ts"
}
]
}
Running the codegen ​
To generate tracking config & typescript types from your codegen config, run voltage generate
.
Auto association of groups, dimensions, & meta ​
Each codegen config supports only 1 events schema. The groups, dimensions, & meta supplied for the codegen config are auto-applied to the events in that single events schema.
For example, if a codegen config includes a "user-group", then it is assumed that all events in the event schema are tracked with an authed user context, and thus all of the properties associated with that user group are auto-associated with the events.
The same is true for dimensions & meta. Events, groups, dimensions, & meta can be mixed & matched arbitrarily within as many codegen configs as you want to support. The autodoc will detect & combine all data from each codegen config.
Why support multi-config codegen? ​
Simple codebases likely don't need more than 1 codegen config, so why support multiple?
Voltage is designed to scale with complex codebases & auth contexts. For example, a software platform with multiple auth contexts (unauthed / authed / end-users), will likely want different groups & dimensions associated with each context, and will need separate codegen configs to support that.
You can read more about this scenario on our Authed vs. Unauthed doc.