@analytics/session-utils

Tiny session utility library

Usage no npm install needed!

<script type="module">
  import analyticsSessionUtils from 'https://cdn.skypack.dev/@analytics/session-utils';
</script>

README

Session Utilities

A tiny session utility library in 775 bytes.

  • Persisted Sessions - saved as cookie for 30min
    • getSession
    • setSession
  • Tab Sessions - saved until tab/window closed
    • getTabSession
    • setTabSession
  • Page Sessions - saved until page changes
    • getPageSession
    • setPageSession

See live demo.

Example

import { getSession, setSession } from '@analytics/session-utils'

const currentSession = getSession()
console.log('currentSession', currentSession)

// Update session
const newSessionInfo = setSession()
console.log('newSessionInfo', newSessionInfo)

About

┌─────────────────────────────────────────────────────────────────┐
│                        Persisted Session                        │
│                                                                 │
│   ┌──────────────────────────┐    ┌──────────────────────────┐  │
│   │       Tab Session        │    │       Tab Session        │  │
│   │                          │    │                          │  │
│   │  ┌────────────────────┐  │    │  ┌────────────────────┐  │  │
│   │  │    Page Session    │  │    │  │    Page Session    │  │  │
│   │  │                    │  │    │  │                    │  │  │
│   │  │                    │  │    │  │                    │  │  │
│   │  │                    │  │    │  │                    │  │  │
│   │  │                    │  │    │  │                    │  │  │
│   │  │                    │  │    │  │                    │  │  │
│   │  │                    │  │    │  │                    │  │  │
│   │  │                    │  │    │  │                    │  │  │
│   │  │                    │  │    │  │                    │  │  │
│   │  └────────────────────┘  │    │  └────────────────────┘  │  │
│   └──────────────────────────┘    └──────────────────────────┘  │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘