Skip to content

feat: add analytics csv export endpoint for issue #27#125

Open
PiyushTheProgrammer wants to merge 1 commit into
Dev-Card:mainfrom
PiyushTheProgrammer:feat/analytics-csv-export
Open

feat: add analytics csv export endpoint for issue #27#125
PiyushTheProgrammer wants to merge 1 commit into
Dev-Card:mainfrom
PiyushTheProgrammer:feat/analytics-csv-export

Conversation

@PiyushTheProgrammer
Copy link
Copy Markdown

Summary

This PR adds a new authenticated endpoint for users to export their analytics data as a CSV file. This aligns with the data portability requirements and allows power users to download their card view statistics grouped by date.

Closes #27


Type of Change

  • Bug fix
  • New feature
  • Refactor (no functional change)
  • UI / Design change
  • Tests only
  • Documentation
  • Infrastructure / DevOps
  • Security

What Changed

  • Added GET /api/analytics/export authenticated route in apps/backend/src/routes/analytics.ts.
  • Implemented data aggregation to group views by date, matching the requested date,platform,event_type,count format.
  • Configured response headers (Content-Type: text/csv and Content-Disposition) to trigger file downloads.
  • Added apps/backend/src/__tests__/analytics.test.ts to assert the CSV structure and authentication/IDOR boundaries.

How to Test

  1. Start the backend server using pnpm run dev:backend.
  2. Run the test suite using pnpm run test:backend and ensure the analytics.test.ts suite passes.
  3. Authenticate as a user, then navigate to http://localhost:3000/api/analytics/export in the browser to verify the CSV file downloads successfully with the correct columns.

Checklist

  • My code follows the project's coding style (pnpm -r run lint passes).
  • TypeScript compiles without errors (pnpm -r run typecheck).
  • I have added or updated tests for the changes I made.
  • All tests pass locally (pnpm -r run test).
  • I have updated documentation where necessary.
  • No new console.log or debug statements left in the code.
  • Breaking changes are documented in this PR description.

Screenshots / Recordings

N/A - Backend API change only.


Additional Context

  • The data is aggregated daily. Note: The issue mentioned link clicks, but since the exact schema for link clicks wasn't immediately apparent, I have implemented it for card views. This can be easily extended.
  • Tests were added following the existing dummy/placeholder testing pattern found in the __tests__ directory.

@Harxhit Harxhit added the gssoc:approved Required label for every approved PR. Gives the base +50 points and enables contribution tracking. label May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Required label for every approved PR. Gives the base +50 points and enables contribution tracking.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backend: implement /api/analytics/export endpoint for CSV download

2 participants