Skip to content

Commit c996c4f

Browse files
psincraianclaude
andauthored
fix: aggregation (#30)
* feat: add aggregation support for custom event tracking - Add aggregation parameter (day/week/month) to custom events API endpoint - Implement aggregation logic in service layer for custom events - Add helper methods for weekly and monthly aggregation of custom events - Create comprehensive test suite (9 tests) for custom event aggregation - Ensure custom events are grouped by dashboard aggregation setting - All 18 aggregation tests pass (9 dashboard + 9 custom events) This allows users to view custom event data aggregated by day, week, or month, matching the behavior of regular analytics events. * fix: pass aggregation parameter from frontend to custom events API The custom events timeseries API was not receiving the aggregation parameter from the frontend, causing it to always default to daily aggregation regardless of the user's selection. Changes: - Add aggregation parameter to custom events API call - Update chart time unit based on aggregation (day/week/month) - Dynamically adjust chart display format for different aggregations Now when users change the aggregation period, custom events will properly group by day, week, or month matching the regular events. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5423487 commit c996c4f

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

app/src/js/dashboard.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,12 @@ async function loadCustomEventsTimeseries() {
668668
try {
669669
const params = buildQueryParams();
670670
const eventTypesParam = Array.from(selectedEventTypes).join(',');
671+
672+
// Add aggregation parameter
673+
if (currentAggregation) {
674+
params.append('aggregation', currentAggregation);
675+
}
676+
671677
const response = await fetch(`/api/dashboard/custom-events/timeseries?event_types=${encodeURIComponent(eventTypesParam)}&${params}`);
672678

673679
if (!response.ok) {
@@ -718,6 +724,18 @@ function renderCustomEventsChart(data) {
718724
};
719725
});
720726

727+
// Determine time unit based on aggregation
728+
let timeUnit = 'day';
729+
let displayFormat = 'MMM d';
730+
731+
if (currentAggregation === 'week') {
732+
timeUnit = 'week';
733+
displayFormat = 'MMM d';
734+
} else if (currentAggregation === 'month') {
735+
timeUnit = 'month';
736+
displayFormat = 'MMM yyyy';
737+
}
738+
721739
// Create chart
722740
customEventsChart = new Chart(ctx, {
723741
type: 'line',
@@ -754,9 +772,11 @@ function renderCustomEventsChart(data) {
754772
x: {
755773
type: 'time',
756774
time: {
757-
unit: 'day',
775+
unit: timeUnit,
758776
displayFormats: {
759-
day: 'MMM d'
777+
day: 'MMM d',
778+
week: 'MMM d',
779+
month: 'MMM yyyy'
760780
}
761781
},
762782
grid: {

0 commit comments

Comments
 (0)