Appearance
Authed vs. Unauthed Tracking ​
Voltage Schema supports different tracking configurations for authenticated and unauthenticated users.
Why Separate Configs? ​
Authenticated users often have additional context (user data, team data) that should be included with events. By separating the configurations, we can:
- Ensure proper type safety for each context
- Prevent tracking authenticated events without proper context
- Keep tracking configurations clean and focused
Configuration Example ​
javascript
export default {
generates: [
{
events: "./analytics/events/unauthed-events.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"
],
output: "/__analytics_generated__/authed-analytics.ts"
}
]
}
Implementation Example ​
typescript
import { createAnalyticsTracker } from 'voltage-schema';
import {
UnauthedAnalyticsTracker,
UnauthedTrackerEvents,
unauthedTrackingConfig
} from './__analytics_generated__/unauthed-analytics';
import {
AuthedAnalyticsTracker,
AuthedTrackerEvents,
authedTrackingConfig
} from './__analytics_generated__/authed-analytics';
// Create trackers for different contexts
const unauthedTracker = createAnalyticsTracker<UnauthedTrackerEvents>(
unauthedTrackingConfig,
{
onEventTracked: (eventName, { properties, groups, meta }) => {
// Send unauthed event
}
}
);
const authedTracker = createAnalyticsTracker<AuthedTrackerEvents>(
authedTrackingConfig,
{
onEventTracked: (eventName, { properties, groups, meta }) => {
// Send authed event with group context
}
}
);
// Tracking an event for authenticated users
authedTracker.track('page_view', {
'Page Name': 'Home',
});
// Tracking an event for anonymous users
unauthedTracker.track('page_view', {
'Page Name': 'Login',
});