mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-19 21:00:40 +08:00
## Summary
Adds richer analytics overview metrics and filterable dashboard
breakdowns.
- adds hourly overview series for the 1-day range
- adds country, referrer, browser, OS, and device filters to internal
metrics
- adds bounce rate, session duration, top countries, top browsers, top
operating systems, and device breakdowns
- updates the overview dashboard with filter chips, top-list cards,
animated metric states, and 1-day hourly chart support
- captures user agent on page-view analytics events, with a server-side
fallback for older clients
## Validation
Attempted targeted tests:
`pnpm test run
apps/backend/src/app/api/latest/internal/metrics/route.test.ts
'apps/dashboard/src/app/(main)/(protected)/projects/[projectId]/(overview)/analytics-chart-mode.test.ts'`
This did not reach Vitest in the temporary split worktree because
`node_modules` is not installed there and the repo pre-step failed at
`pnpm exec tsx ./scripts/generate-sdks.ts`.
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds analytics overview filters with optional date‑range bounds and
1‑day hourly charts, plus smoother, accessible animations across charts
and top lists. Improves correctness and stability with deterministic
caching, normalized inputs, client‑only user‑agent capture, and
globe/layout fixes.
- **New Features**
- Filterable analytics overview (country, referrer, browser, OS, device)
with normalized inputs and optional `since`/`until`; API/admin/dashboard
accept `AnalyticsOverviewFilters` with deterministic cache keys.
- 1‑day hourly charts (page views, visitors) and a metric mode toggle
(DAU, Visitors, Revenue); animated top‑lists and sparklines powered by
`motion` with reduced‑motion support.
- UI: filter chips/menu, clearer tooltips (incl. user metric cards),
optional interactive globe with dynamic camera distance; exported
`TooltipPortal` from `@hexclave/ui`.
- **Refactors & Bug Fixes**
- Event ingest: client sends `user_agent`; removed server‑side fallback;
added user‑agent filter‑fragment builder and tests.
- Metrics correctness: aligned hourly bounds to start of UTC hour;
derived 1‑day revenue total from daily series; resilient chart x‑axis
formatting; country filter options use analytics `top_regions`;
fixed‑'en' locale for top‑lists; added date‑range parsing/validation for
filters.
- UI/runtime: smoother pill/tab slider animations with guards for
missing Web APIs; added `containedHeight` to `PageLayout` and wired into
sidebar/session replays; globe disables zoom when non‑interactive.
- Misc: instrumentation runs only in Node (`process.env.NEXT_RUNTIME ===
"nodejs"`); analytics/overview page redirects with URL‑encoded
`projectId`; Docker: include `@hexclave/template` in `turbo prune` to
fix CI builds.
<sup>Written for commit 7fcd3558a5.
Summary will update on new commits.</sup>
<a
href="https://cubic.dev/pr/hexclave/hexclave/pull/1496?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Analytics filters (country, referrer, browser, OS, device); hourly
signup and active-user series; expanded hourly/daily analytics payloads
and top-lists UI.
* Chart metric modes (DAU, Visitors, Revenue), optional page-views
series, interactive globe support, animated Top Lists, and sparkline
animations.
* **Improvements**
* Better user-agent capture/normalization for batched events and
page-view tracking; reduced-motion aware animations; enhanced tooltips
and UI slider/tab indicators.
* Added motion library dependency.
* **Tests**
* New unit tests for analytics filters and chart metric mode behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: mantra <mantra@stack-auth.com>
108 lines
3.2 KiB
Docker
108 lines
3.2 KiB
Docker
ARG NODE_VERSION=22.21.1
|
|
|
|
# Base
|
|
FROM node:${NODE_VERSION} AS base
|
|
|
|
WORKDIR /app
|
|
|
|
RUN apt-get update && \
|
|
apt-get upgrade -y && \
|
|
rm -rf /var/lib/apt/lists
|
|
|
|
ENV PNPM_HOME=/pnpm
|
|
ENV PATH=$PNPM_HOME:$PNPM_HOME/bin:$PATH
|
|
|
|
RUN corepack enable
|
|
RUN corepack prepare pnpm@11.5.0 --activate
|
|
RUN pnpm add -g turbo
|
|
RUN pnpm add -g tsx
|
|
|
|
|
|
# Prune stage
|
|
FROM base AS pruner
|
|
|
|
COPY . .
|
|
|
|
RUN tsx ./scripts/generate-sdks.ts
|
|
|
|
# https://turbo.build/repo/docs/guides/tools/docker
|
|
RUN turbo prune --scope=@hexclave/backend --scope=@hexclave/dashboard --scope=@hexclave/template --docker
|
|
|
|
|
|
|
|
# Build stage
|
|
FROM base AS builder
|
|
|
|
# Skip generate-sdks.ts in preinstall hook (file not available in pruned output)
|
|
ENV HEXCLAVE_SKIP_TEMPLATE_GENERATION=true
|
|
|
|
# copy over package.json files and install dependencies
|
|
COPY --from=pruner /app/out/json/ .
|
|
COPY --from=pruner /app/out/pnpm-lock.yaml .
|
|
COPY .gitignore .
|
|
COPY pnpm-workspace.yaml .
|
|
COPY turbo.json .
|
|
COPY configs ./configs
|
|
COPY --from=pruner /app/scripts/postinstall-patch-next-async-debug-info.mjs ./scripts/
|
|
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
|
|
|
|
# copy over the rest of the code for the build
|
|
COPY --from=pruner /app/out/full/ .
|
|
|
|
# docs are currently required for the NextJS backend build, but won't exist in the final image
|
|
COPY docs ./docs
|
|
|
|
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
|
|
ENV NEXT_CONFIG_OUTPUT=standalone
|
|
|
|
# Build the backend NextJS app
|
|
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm turbo run docker-build --filter=@hexclave/backend... --filter=@hexclave/dashboard...
|
|
|
|
# Build the self-host seed script
|
|
RUN --mount=type=cache,id=pnpm,target=/pnpm/store cd apps/backend && pnpm build-self-host-migration-script
|
|
|
|
|
|
|
|
# Final image
|
|
FROM node:${NODE_VERSION}-slim
|
|
|
|
WORKDIR /app
|
|
|
|
# Install packages needed for deployment
|
|
RUN apt-get update && \
|
|
apt-get upgrade -y && \
|
|
apt-get install -y openssl socat && \
|
|
rm -rf /var/lib/apt/lists
|
|
|
|
# Copy built backend
|
|
COPY --from=builder --chown=node:node /app/apps/backend/.next/standalone ./
|
|
COPY --from=builder --chown=node:node /app/apps/backend/.next/static ./apps/backend/.next/static
|
|
COPY --from=builder --chown=node:node /app/apps/backend/prisma ./apps/backend/prisma
|
|
COPY --from=builder --chown=node:node /app/apps/backend/dist ./apps/backend/dist
|
|
COPY --from=builder --chown=node:node /app/apps/backend/node_modules ./apps/backend/node_modules
|
|
|
|
# Copy built dashboard
|
|
COPY --from=builder --chown=node:node /app/apps/dashboard/.next/standalone ./
|
|
COPY --from=builder --chown=node:node /app/apps/dashboard/.next/static ./apps/dashboard/.next/static
|
|
COPY --from=builder --chown=node:node /app/apps/dashboard/public ./apps/dashboard/public
|
|
|
|
# Restore workspace node_modules needed by non-Next runtime scripts (e.g. migrations)
|
|
COPY --from=builder --chown=node:node /app/node_modules ./node_modules
|
|
COPY --from=builder --chown=node:node /app/packages ./packages
|
|
|
|
# Add the entrypoint script
|
|
COPY ./docker/server/entrypoint.sh .
|
|
RUN chmod +x entrypoint.sh
|
|
|
|
WORKDIR /app
|
|
|
|
# Define environment variables for both services
|
|
ENV NODE_ENV=production
|
|
ENV BACKEND_PORT=8102
|
|
ENV DASHBOARD_PORT=8101
|
|
|
|
USER node
|
|
|
|
# Set entrypoint to run both backend and dashboard
|
|
ENTRYPOINT ["./entrypoint.sh"]
|