Skip to content

[Feature] URL parameter for deep linking to specific sites #141

Description

@ricardocamiloconsir

Problem

When users have multiple projects (websites) tracked by counter.dev and switch between them using the dropdown selector, the dashboard often fails to load the correct data for the selected project. The root cause is a lack of synchronization between the URL state and the internal dashboard state.

Current Behavior

  • Dashboard loads all projects via SSE (/dump)
  • First project in list (by visit count) is displayed, not the one user intended
  • When switching projects via <select>:
    • Frontend calls /setPrefSite?site=x
    • Backend updates Redis preference
    • Frontend reuses cached dump with different selector.site
    • Graphs/components display WRONG data (from previous site)
  • No URL state: refreshing page loses selected project

Proposed Solution

Add ?project=x parameter to dashboard URL

Backend Changes (/dump endpoint)

  1. Accept project query parameter
  2. If project present:
    • Add to dump.meta for frontend consumption
  3. If project absent:
    • Use prefs.site (current behavior)

Frontend Changes (selector.js)

  1. Read project parameter on load
  2. Use meta.project for initial site selection (priority over prefs.site)
  3. Update URL when switching projects via history.pushState()
  4. Handle browser back/forward via popstate events

Benefits

  • Fix data loading bug when switching projects
  • Enable deep linking to specific projects
  • Allow bookmarking project views
  • Improve cross-device consistency (same URL = same view)
  • Maintain backward compatibility (URL param optional)
  • Enable sharing of project dashboards

Example URLs

/dashboard.html?user=CamillusBloodfallen&token=Q5ysSKM8YJI%3D&project=example.com
/dashboard.html?project=myportfolio.com

Acceptance Criteria

  • URL parameter ?project=x is read on dashboard load
  • Dropdown selects the correct project from URL
  • Switching projects updates URL with new project
  • Browser back/forward navigation works correctly
  • Refreshing page maintains selected project (via URL)
  • Sessionless access (token-based) works with URL parameter
  • No regression in existing flows

Implementation

Implemented in PR #140

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions