GithubHelp home page GithubHelp logo

swizec / web-session-counter Goto Github PK

View Code? Open in Web Editor NEW
25.0 4.0 9.0 7 KB

Utility to count a user's web sessions based on the definition GA uses.

License: MIT License

JavaScript 100.00%
es6 analytics session localstorage momentjs querystring

web-session-counter's Introduction

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
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. The tl;dr is that a new session starts after every:

  • 30 minutes of inactivity
  • midnight
  • utm_campaign query change

Enjoy.

web-session-counter's People

Contributors

swizec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

web-session-counter's Issues

window.localStorage can't be read when cookies are disabled

When cookies are disabled, the class crashes because window.localStorage is protected.

'Failed to read the 'localStorage' property from 'Window': Access is denied for this document.'

We'll need to add in isLocalStorageSupported() a try{} on 'storage = window.localStorage;' and return false on the catch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.