Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/swizec/web-session-counter
Utility to count a user's web sessions based on the definition GA uses.
https://github.com/swizec/web-session-counter
analytics es6 localstorage momentjs querystring session
Last synced: 3 days ago
JSON representation
Utility to count a user's web sessions based on the definition GA uses.
- Host: GitHub
- URL: https://github.com/swizec/web-session-counter
- Owner: Swizec
- License: mit
- Created: 2017-05-11T06:22:43.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-26T21:29:37.000Z (over 5 years ago)
- Last Synced: 2024-10-28T12:12:02.044Z (16 days ago)
- Topics: analytics, es6, localstorage, momentjs, querystring, session
- Language: JavaScript
- Size: 6.84 KB
- Stars: 25
- Watchers: 4
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Web Session Counter
What do you do if your boss comes up to you and asks *"So how many
times must a person come to our app before they give us $500?"*As an engineer you might not care, but this is the stuff that keeps
your CEO and growth lead and head of product up at night. A business
owner that can answer that 👆 question reliably is god amongst men.You can use this repo :)
## How to use
```
$ npm install --save web-session-counter
``````javascript
import WebSessionCounter from 'web-session-counter';
// Do this on user activity
WebSessionCounter.update();// To get the total count of sessions
const count = WebSessionCounter.count;```
`.update()` is called automatically every time you import
WebSessionCounter. I recommend calling `.update()`, if you have a
single page app that doesn't perform a lot of refreshes. Calling
`.update` frequently, ensures your code will correctly detect every 30
minute period of inactivity.## What is a session
We use the [same definition as Google Analytics](https://support.google.com/analytics/answer/2731565?hl=en). The tl;dr is that a new session starts after every:
- 30 minutes of inactivity
- midnight
- `utm_campaign` query changeEnjoy.