Analytics Module
Track custom events and user activity via base44.analytics.
Contents
Methods
| Method | Signature | Description |
|---|---|---|
track(params) |
void |
Track a custom event |
Examples
Track Custom Event
// Track a simple event
base44.analytics.track({
eventName: "button_clicked"
});
// Track event with properties
base44.analytics.track({
eventName: "purchase_completed",
properties: {
product_id: "prod-123",
amount: 99.99,
currency: "USD"
}
});Track User Actions
// Track page view
base44.analytics.track({
eventName: "page_view",
properties: {
page: "/dashboard",
referrer: document.referrer
}
});
// Track feature usage
base44.analytics.track({
eventName: "feature_used",
properties: {
feature: "export_data",
format: "csv"
}
});Automatic Tracking
The analytics module automatically tracks:
- Initialization events: When the app loads
- Heartbeat events: Periodic activity signals
- Session duration: Time spent in the app
These internal events help measure user engagement without manual instrumentation.
Best Practices
- Use descriptive event names:
order_completedinstead ofclick - Include relevant properties: Add context that helps analyze the event
- Be consistent: Use the same event names and property keys across your app
- Don't track sensitive data: Avoid PII in event properties
// Good: Descriptive with relevant properties
base44.analytics.track({
eventName: "subscription_started",
properties: {
plan: "pro",
billing_cycle: "annual"
}
});
// Avoid: Vague event name, no context
base44.analytics.track({
eventName: "click"
});Type Definitions
/** Properties that can be attached to a tracked event. */
type TrackEventProperties = {
[key: string]: string | number | boolean | null | undefined;
};
/** Parameters for the track() method. */
interface TrackEventParams {
/** The name of the event to track. */
eventName: string;
/** Optional properties to attach to the event. */
properties?: TrackEventProperties;
}
/** The analytics module interface. */
interface AnalyticsModule {
/** Track a custom event with optional properties. */
track(params: TrackEventParams): void;
}