vinaysomawat / vinaysomawat.github.io

A cutting-edge portfolio web page utilizing vanilla JavaScript.
https://vinaysomawat.github.io/
MIT License
318 stars 367 forks source link

Count visited session using sessionStorage #58

Open vinaysomawatshiprocket opened 2 months ago

vinaysomawatshiprocket commented 2 months ago
  1. Start:

    • The system needs to track both the total number of visits and the number of unique visitors using total visit count and unique visit count stored in two separate text files.
  2. Step 1: Check LocalStorage for a visit flag:

    • If the visit flag exists in LocalStorage:
      • Proceed to Step 2.
    • If the visit flag does not exist in LocalStorage:
      • This is a unique visit. Increment both the total visit count and unique visit count by reading the current values from their respective files, updating them, and writing back the new counts to the files.
      • Set a visit flag in LocalStorage to indicate this unique visit.
      • Set a session flag in SessionStorage to track the current session visit.
  3. Step 2: Check SessionStorage for a session flag:

    • If the session flag exists in SessionStorage:
      • Do nothing (the user has already visited in this session).
    • If the session flag does not exist in SessionStorage:
      • This is a new session for the same user. Increment only the total visit count by reading the current value from the file, updating it, and writing back the new count.
      • Set a session flag in SessionStorage to indicate the session visit.
  4. End:

    • The system keeps track of both total visits and unique visitors without unnecessary updates, ensuring efficient session management.