Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6894330
fix: previous period data was included in the table
tdgao Jun 2, 2026
3c74442
fix: revenue displaying stale data when viewing it from different met…
tdgao Jun 2, 2026
8b2264d
fix: remove staletime on analytics query so switching tabs does not r…
tdgao Jun 2, 2026
3552429
feat: add monetization alert
tdgao Jun 2, 2026
c1e66e7
fix-small: missing space in tooltip
tdgao Jun 2, 2026
f9255c1
fix: incorrect y-axis formatting for trailing decimal 0s
tdgao Jun 2, 2026
90ed37b
fix: switching tabs resets table series selection due to other refetches
tdgao Jun 2, 2026
62c2fd9
fix: always show month first in chart tooltip
tdgao Jun 2, 2026
e74d3ef
fix: change all time start date to be project published date
tdgao Jun 2, 2026
298802d
fix: increase length on project name column
tdgao Jun 2, 2026
2fdca19
fix: unknown download source data points not showing for download sou…
tdgao Jun 2, 2026
57c08ce
fix: double unknown for loader
tdgao Jun 2, 2026
ebd9b13
fix: no data on country labeling incorrectly as "Unknown" instead of …
tdgao Jun 2, 2026
3fa5d1a
fix: date picker number inputs showing arrows
tdgao Jun 2, 2026
c4fec2a
fix: stat card showing enormous percentage for prev period by switchi…
tdgao Jun 2, 2026
b5d185e
fix: decimal values for playtime being rounded badly, resulting in 0.…
tdgao Jun 2, 2026
25f233b
fix: chips having stroke
tdgao Jun 2, 2026
c09cfd1
refactor: pnpm prepr
tdgao Jun 3, 2026
4774d16
fix: spacing in annoucement link
tdgao Jun 3, 2026
d6c713d
Merge branch 'main' into truman/analytics-fixes
tdgao Jun 3, 2026
4e6c8be
fix: legend scroll shadow on top of event tooltip
tdgao Jun 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
>
<div
v-if="showLegendTopFade"
class="pointer-events-none absolute left-0 right-0 top-0 z-10 h-5 bg-gradient-to-b from-surface-3 to-transparent"
class="z-1 pointer-events-none absolute left-0 right-0 top-0 h-5 bg-gradient-to-b from-surface-3 to-transparent"
/>
</Transition>

Expand Down Expand Up @@ -99,7 +99,7 @@
>
<div
v-if="showLegendBottomFade"
class="pointer-events-none absolute bottom-0 left-0 right-0 z-10 h-5 bg-gradient-to-t from-surface-3 to-transparent"
class="z-1 pointer-events-none absolute bottom-0 left-0 right-0 h-5 bg-gradient-to-t from-surface-3 to-transparent"
/>
</Transition>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
:href="event.announcement_url"
target="_blank"
rel="noopener noreferrer"
class="mt-1.5 inline-flex items-center gap-1 text-sm font-medium text-primary underline !transition-all hover:text-contrast"
class="my-0.5 inline-flex items-center gap-1 text-xs font-medium text-primary underline !transition-all hover:text-contrast"
>
{{ formatMessage(analyticsChartMessages.seeAnnouncement) }}
<ExternalIcon class="size-3.5" aria-hidden="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
({{ durationLabel }})
</span>
</span>
<span v-if="previousRangeLabel" class="min-w-0 truncate text-xs text-primary">
<span v-if="previousRangeLabel" class="min-w-0 space-x-1 truncate text-xs text-primary">
<span class="font-medium">{{ previousRangeLabel }}</span>
<span class="font-normal text-secondary">
{{ formatMessage(analyticsChartMessages.previousPeriodShort) }}
Expand Down Expand Up @@ -197,6 +197,7 @@ function getEntryAriaLabel(entry: AnalyticsChartTooltipEntry) {
const ONE_DAY_MS = 24 * 60 * 60 * 1000
const ONE_HOUR_MS = 60 * 60 * 1000
const ONE_MINUTE_MS = 60 * 1000
const DATE_LOCALE = 'en-US'

function formatRangeLabel(
start: Date,
Expand Down Expand Up @@ -225,13 +226,13 @@ function formatRangeLabel(
}

if (includeTime) {
const startLabel = new Intl.DateTimeFormat(undefined, startOptions).format(start)
const endLabel = new Intl.DateTimeFormat(undefined, timeOptions).format(end)
const startLabel = new Intl.DateTimeFormat(DATE_LOCALE, startOptions).format(start)
const endLabel = new Intl.DateTimeFormat(DATE_LOCALE, timeOptions).format(end)
const range = `${startLabel}–${endLabel}`

if (!showTrailingYear) return range

const yearLabel = new Intl.DateTimeFormat(undefined, { year: 'numeric' }).format(end)
const yearLabel = new Intl.DateTimeFormat(DATE_LOCALE, { year: 'numeric' }).format(end)
return `${range}, ${yearLabel}`
}

Expand All @@ -244,13 +245,13 @@ function formatRangeLabel(
endOptions = { day: 'numeric' }
}

const startLabel = new Intl.DateTimeFormat(undefined, startOptions).format(start)
const endLabel = new Intl.DateTimeFormat(undefined, endOptions).format(end)
const startLabel = new Intl.DateTimeFormat(DATE_LOCALE, startOptions).format(start)
const endLabel = new Intl.DateTimeFormat(DATE_LOCALE, endOptions).format(end)
const range = `${startLabel}–${endLabel}`

if (!showTrailingYear) return range

const yearLabel = new Intl.DateTimeFormat(undefined, { year: 'numeric' }).format(end)
const yearLabel = new Intl.DateTimeFormat(DATE_LOCALE, { year: 'numeric' }).format(end)
return `${range}, ${yearLabel}`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export function useAnalyticsChartEvents(
placeholderData: [],
refetchOnMount: 'always',
retry: false,
staleTime: 0,
})

const localAnalyticsChartEvents = computed(() => analyticsEvents.value ?? [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function getRegionDisplayNames(locale: string): Intl.DisplayNames | null {
function formatCountryCode(countryCode: string, formatMessage: FormatMessage): string {
const normalized = countryCode.trim().toUpperCase()
if (normalized === OTHER_COUNTRY_CODE) {
return formatMessage(analyticsMessages.unknown)
return formatMessage(analyticsMessages.other)
}

if (!REGION_CODE_PATTERN.test(normalized)) {
Expand Down Expand Up @@ -146,6 +146,9 @@ export function formatBreakdownLabel(
normalizedLowercaseValue === 'other' ||
normalizedLowercaseValue === 'unknown'
) {
if (selectedBreakdown === 'country') {
return formatMessage(analyticsMessages.other)
}
return formatMessage(analyticsMessages.unknown)
}
if (selectedBreakdown === 'country') {
Expand Down Expand Up @@ -753,7 +756,7 @@ export function formatMetricValue(
case 'playtime': {
const hours = value / 3600
return formatMessage(analyticsStatCardMessages.playtimeHours, {
hours: hours.toFixed(1),
hours: Math.abs(hours) < 1 ? hours.toFixed(2) : hours.toFixed(1),
})
}
case 'views':
Expand All @@ -770,7 +773,11 @@ function formatSmallAxisNumber(value: number): string {
}

const formattedValue = Math.abs(value) < 1 ? value.toFixed(2) : value.toFixed(1)
return formattedValue.replace(/\.?0+$/, '')
return trimTrailingFractionZeros(formattedValue)
}

function trimTrailingFractionZeros(value: string): string {
return value.replace(/(\.\d*?)0+$/, '$1').replace(/\.$/, '')
}

const COMPACT_AXIS_UNITS = [
Expand Down Expand Up @@ -814,7 +821,7 @@ function formatCompactAxisValue(value: number): string {
return String(truncatedValue)
}

return roundedValue.toFixed(fractionDigitCount).replace(/\.?0+$/, '')
return trimTrailingFractionZeros(roundedValue.toFixed(fractionDigitCount))
}

export function formatAxisValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ export const analyticsGraphTitleMessages = defineMessages({
})

export const analyticsStatCardMessages = defineMessages({
monetizationBannerTitle: {
id: 'analytics.stat.monetization-banner.title',
defaultMessage: 'How does monetization work?',
},
monetizationBannerBody: {
id: 'analytics.stat.monetization-banner.body',
defaultMessage:
'Only views and downloads made through Modrinth are eligible for monetization and must pass fraud-prevention filtering. Modrinth App downloads also require the user to be logged in. Because all projects have a similar ratio of monetized downloads, your revenue would not meaningfully change if all downloads were counted.',
},
monetizationBannerLearnMore: {
id: 'analytics.stat.monetization-banner.learn-more',
defaultMessage: 'Learn more',
},
revenueValue: {
id: 'analytics.stat.revenue-value',
defaultMessage: '${value}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export function buildAnalyticsTableColumns({
key: getAnalyticsTableBreakdownColumnKey(breakdown),
label: getAnalyticsTableBreakdownColumnLabel(breakdown, formatMessage),
enableSorting: true,
width: breakdown === 'project' ? '25%' : undefined,
})
}
}
Expand All @@ -75,6 +76,7 @@ export function buildAnalyticsTableColumns({
key: 'project',
label: formatAnalyticsBreakdownLabel('project', formatMessage),
enableSorting: true,
width: '25%',
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ export function formatAnalyticsTableCompactPlaytime(
formatMessage: FormatMessage,
): string {
const totalSeconds = Math.max(0, Math.round(value))
const hours = totalSeconds / SECONDS_PER_HOUR
const fractionDigits = hours < 1 ? 2 : 1
return formatMessage(analyticsStatCardMessages.playtimeHours, {
hours: (totalSeconds / SECONDS_PER_HOUR).toLocaleString(undefined, {
minimumFractionDigits: 1,
maximumFractionDigits: 1,
hours: hours.toLocaleString(undefined, {
minimumFractionDigits: fractionDigits,
maximumFractionDigits: fractionDigits,
}),
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getSliceCount,
} from '../analytics-chart/analytics-chart-utils'
import type { FormatMessage } from '../analytics-messages'
import { analyticsMessages } from '../analytics-messages'
import {
ALL_BREAKDOWN_VALUE,
COMBINED_BREAKDOWN_LABEL_SEPARATOR,
Expand Down Expand Up @@ -64,6 +65,8 @@ export function buildAnalyticsTableRows({

const timeRange = fetchRequest.time_range
const sliceCount = getSliceCount(timeRange, timeSlices.length)
const currentTimeSlices =
timeSlices.length > sliceCount ? timeSlices.slice(timeSlices.length - sliceCount) : timeSlices
const includeDate = mode === 'date_breakdown'
const breakdownDisplayValues = new Map<string, string>()
const projectDisplayValues = new Map<string, string>()
Expand Down Expand Up @@ -119,9 +122,22 @@ export function buildAnalyticsTableRows({
}

function getCombinedBreakdownDisplay(displays: AnalyticsTableBreakdownDisplayValues) {
const unknownBreakdownLabel = formatMessage(analyticsMessages.unknown)
let hasUnknownBreakdownLabel = false

return selectedBreakdowns
.map((breakdown) => displays[breakdown])
.filter((displayValue): displayValue is string => Boolean(displayValue))
.filter((displayValue) => {
if (displayValue !== unknownBreakdownLabel) {
return true
}
if (hasUnknownBreakdownLabel) {
return false
}
hasUnknownBreakdownLabel = true
return true
})
.join(COMBINED_BREAKDOWN_LABEL_SEPARATOR)
}

Expand Down Expand Up @@ -184,7 +200,7 @@ export function buildAnalyticsTableRows({
}
}

timeSlices.forEach((slice, sliceIndex) => {
currentTimeSlices.forEach((slice, sliceIndex) => {
const bucketLabel = includeDate ? getBucketLabel(sliceIndex) : undefined

for (const point of slice) {
Expand Down
12 changes: 10 additions & 2 deletions apps/frontend/src/components/analytics-dashboard/breakdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ export function getAnalyticsBreakdownValue(
case 'user_agent': {
const downloadSource = normalizeBreakdownValue(
'user_agent' in point ? point.user_agent : undefined,
UNKNOWN_BREAKDOWN_VALUE,
)
return downloadSource === ALL_BREAKDOWN_VALUE
? ALL_BREAKDOWN_VALUE
return downloadSource === UNKNOWN_BREAKDOWN_VALUE
? UNKNOWN_BREAKDOWN_VALUE
: getDownloadSourceLabel(downloadSource, formatMessage)
}
case 'download_reason':
Expand Down Expand Up @@ -98,5 +99,12 @@ function normalizeBreakdownValue(
fallback = ALL_BREAKDOWN_VALUE,
): string {
const normalized = value?.trim()
const normalizedLowercase = normalized?.toLowerCase()
if (
fallback === UNKNOWN_BREAKDOWN_VALUE &&
(normalizedLowercase === 'unknown' || normalizedLowercase === 'other')
) {
return fallback
}
return normalized && normalized.length > 0 ? normalized : fallback
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const {
selectedCustomTimeframeEndDate,
selectedGroupBy,
queryRefreshTimestamp,
analyticsAllTimeStartDate,
refreshAnalyticsQuery,
} = injectAnalyticsDashboardContext()

Expand Down Expand Up @@ -107,6 +108,7 @@ function handleTimeframeDraftChange(selection: TimeFramePickerSelection) {
customStartDate: selection.customStartDate,
customEndDate: selection.customEndDate,
nowTimestamp: queryRefreshTimestamp.value,
allTimeStartDate: analyticsAllTimeStartDate.value,
})
const { start, end } = ensureMinimumTimeRange(range.start, range.end)
const durationMinutes = Math.max(1, Math.floor((end.getTime() - start.getTime()) / 60000))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -894,12 +894,6 @@ function isRevenueHourlyGroupBy(groupBy: AnalyticsGroupByPreset): boolean {
return groupBy === '1h' || groupBy === '6h'
}

function getAllTimeYearGroupStart(end: Date): Date {
const start = new Date(end)
start.setFullYear(2021)
return start
}

const groupByOptions = computed<ComboboxOption<AnalyticsGroupByPreset>[]>(() => {
const timeframeMinutes = selectedTimeframeDurationMinutes.value
const options = groupByPresetOptions.map((option) => {
Expand Down Expand Up @@ -1159,13 +1153,7 @@ function buildMetricFilters(

const fetchRequest = computed<Labrinth.Analytics.v3.FetchRequest>(() => {
const rawRange = selectedTimeRange.value
const rawStart =
selectedTimeframeMode.value === 'preset' &&
selectedTimeframe.value === 'all_time' &&
selectedGroupBy.value === 'year'
? getAllTimeYearGroupStart(rawRange.end)
: rawRange.start
const { start, end } = ensureMinimumTimeRange(rawStart, rawRange.end)
const { start, end } = ensureMinimumTimeRange(rawRange.start, rawRange.end)

const groupByMs = getAnalyticsGroupByPresetMinutes(selectedGroupBy.value) * 60 * 1000
const desiredSlices = Math.max(1, Math.floor((end.getTime() - start.getTime()) / groupByMs))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function subtractCalendarMonths(date: Date, months: number): Date {
export function getTimeRangeForPreset(
preset: AnalyticsTimeframePreset,
nowTimestamp: number,
allTimeStartDate: Date = new Date(Date.UTC(2023, 0, 1, 0, 0, 0, 0)),
): AnalyticsTimeRange {
const now = getRoundedNow(nowTimestamp)
const end = new Date(now)
Expand Down Expand Up @@ -130,7 +131,7 @@ export function getTimeRangeForPreset(
}
case 'all_time':
return {
start: new Date(Date.UTC(2023, 0, 1, 0, 0, 0, 0)),
start: new Date(allTimeStartDate),
end,
}
default:
Expand Down Expand Up @@ -193,6 +194,7 @@ export function getAnalyticsTimeRange({
customStartDate,
customEndDate,
nowTimestamp,
allTimeStartDate,
}: {
mode: AnalyticsTimeframeMode
preset: AnalyticsTimeframePreset
Expand All @@ -201,6 +203,7 @@ export function getAnalyticsTimeRange({
customStartDate: string
customEndDate: string
nowTimestamp: number
allTimeStartDate?: Date
}): AnalyticsTimeRange {
switch (mode) {
case 'last':
Expand All @@ -211,7 +214,7 @@ export function getAnalyticsTimeRange({
return getTimeRangeForCustomDateTimeRange(customStartDate, customEndDate)
case 'preset':
default:
return getTimeRangeForPreset(preset, nowTimestamp)
return getTimeRangeForPreset(preset, nowTimestamp, allTimeStartDate)
}
}

Expand Down Expand Up @@ -269,6 +272,7 @@ export function useSelectedAnalyticsTimeRange() {
selectedCustomTimeframeStartDate,
selectedCustomTimeframeEndDate,
queryRefreshTimestamp,
analyticsAllTimeStartDate,
} = injectAnalyticsDashboardContext()

const selectedTimeRange = computed(() =>
Expand All @@ -280,6 +284,7 @@ export function useSelectedAnalyticsTimeRange() {
customStartDate: selectedCustomTimeframeStartDate.value,
customEndDate: selectedCustomTimeframeEndDate.value,
nowTimestamp: queryRefreshTimestamp.value,
allTimeStartDate: analyticsAllTimeStartDate.value,
}),
)

Expand Down
Loading
Loading