# Keep the view in the URL and follow live events

URL: https://docs.analytics.remcostoeten.nl/docs/tutorial/keep-the-view-in-the-url

> Step 6 of 7. Store the view in the URL hash so it survives a reload and can be shared, and add a live event stream.

The view so far is lost on reload. This step writes it to the URL hash, in the same spelling the API takes, and adds a panel that shows visitors right now and each event as it arrives.

## 1. Store the view and add the live panel

<StepDiff
  step="6"
  notes="[
  {
    file: &#x22;src/state.ts&#x22;,
    match: &#x22;export function toHash&#x22;,
    text: &#x22;period, traffic when it is not human, and one filter[<dimension>] per filter: the query string the API itself takes.&#x22;,
  },
  {
    file: &#x22;src/state.ts&#x22;,
    match: &#x22;export function fromHash&#x22;,
    text: &#x22;Anything missing or unknown falls back to the default, so an edited or old link still opens.&#x22;,
  },
  {
    file: &#x22;src/app.tsx&#x22;,
    match: 'history.replaceState(null, &#x22;&#x22;, hash)',
    text: &#x22;replaceState keeps every filter change out of the back button's history.&#x22;,
  },
  {
    file: &#x22;src/components/realtime.tsx&#x22;,
    match: &#x22;scope.realtimeEvents({ limit: streamLimit })&#x22;,
    text: &#x22;The latest 30 events and a cursor that marks where they end.&#x22;,
  },
  {
    file: &#x22;src/components/realtime.tsx&#x22;,
    match: &#x22;scope.liveEvents({ after, signal: controller.signal })&#x22;,
    text: &#x22;An async iterable that follows the cursor and yields each new event. Aborting the signal ends the loop.&#x22;,
  },
  {
    file: &#x22;src/components/realtime.tsx&#x22;,
    match: &#x22;scope.realtime()&#x22;,
    text: &#x22;Visitors in the last five minutes and pageviews per minute, read again every 30 seconds.&#x22;,
  },
]"
/>

## 2. Try it

Pick a period and a filter, then reload: the view stays. Open `http://localhost:3301` in a second tab, and the first tab's **Latest events** panel shows the new pageview.

Next, [switch projects](https://docs.analytics.remcostoeten.nl/docs/tutorial/switch-projects.md).
