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)
- Accept
project query parameter
- If
project present:
- Add to
dump.meta for frontend consumption
- If
project absent:
- Use
prefs.site (current behavior)
Frontend Changes (selector.js)
- Read
project parameter on load
- Use
meta.project for initial site selection (priority over prefs.site)
- Update URL when switching projects via
history.pushState()
- 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
Implementation
Implemented in PR #140
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
/dump)<select>:/setPrefSite?site=xselector.siteProposed Solution
Add
?project=xparameter to dashboard URLBackend Changes (
/dumpendpoint)projectquery parameterprojectpresent:dump.metafor frontend consumptionprojectabsent:prefs.site(current behavior)Frontend Changes (
selector.js)projectparameter on loadmeta.projectfor initial site selection (priority overprefs.site)history.pushState()popstateeventsBenefits
Example URLs
Acceptance Criteria
?project=xis read on dashboard loadImplementation
Implemented in PR #140