Event Tracking Configuration
Set up custom event tracking to measure user interactions beyond automatic session tracking.
Event Structure
Countly events support:
- key (required): Event name
- count: Number of occurrences
- sum: Numeric value (revenue, points, etc.)
- dur: Duration in seconds
- segmentation: Key-value pairs for dimensions
Basic Implementation
Simple Events
// Track occurrence
Countly.add_event({
key: 'button_click',
count: 1
});
Events with Value
// Track with sum
Countly.add_event({
key: 'purchase',
count: 1,
sum: 49.99
});
Events with Duration
// Track time spent
Countly.add_event({
key: 'video_watch',
count: 1,
dur: 120 // 2 minutes
});
Segmented Events
Countly.add_event({
key: 'search',
count: 1,
segmentation: {
query: 'analytics',
results: 25,
category: 'software'
}
});
Timed Events
Automatic Duration
// Start timer
Countly.start_event('video_watch');
// ... activity occurs ...
// End and record
Countly.end_event('video_watch');
// End with additional data
Countly.end_event({
key: 'video_watch',
segmentation: {
video_id: 'intro_001',
completed: true
}
});
Cancel Event
// Start event
Countly.start_event('checkout');
// User cancels - don't record
Countly.cancel_event('checkout');
Common Patterns
E-commerce Events
// Product view
Countly.add_event({
key: 'product_view',
segmentation: {
product_id: 'SKU001',
category: 'Electronics',
price: 299
}
});
// Add to cart
Countly.add_event({
key: 'add_to_cart',
count: 1,
sum: 299,
segmentation: {
product_id: 'SKU001'
}
});
// Purchase
Countly.add_event({
key: 'purchase',
count: 3, // items count
sum: 599, // total
segmentation: {
order_id: 'ORD123',
payment: 'credit_card'
}
});
Feature Usage
function trackFeature(name, context = {}) {
Countly.add_event({
key: 'feature_use',
count: 1,
segmentation: {
feature: name,
...context
}
});
}
trackFeature('export', { format: 'pdf' });
trackFeature('share', { platform: 'email' });
Form Events
// Form started
Countly.start_event('form_completion');
// Form submitted
Countly.end_event({
key: 'form_completion',
segmentation: {
form: 'contact',
fields_filled: 5
}
});
Dashboard Configuration
Viewing Events
- Navigate to Events
- Select event from list
- View metrics:
- Count over time
- Sum totals
- Average duration
- Segment breakdowns
Creating Funnels
- Go to Funnels
- Create new funnel
- Add event steps:
- product_view
- add_to_cart
- checkout_start
- purchase
- Analyze conversion rates