Skip to content

Commit

Permalink
Merge pull request #666 from ygowthamr/UniqueVisitorCount
Browse files Browse the repository at this point in the history
Fixed homepage visitor counter to track unique visits only once per user session
  • Loading branch information
YadavAkhileshh authored Nov 4, 2024
2 parents f64fb37 + a5d6e29 commit f688d7c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
11 changes: 8 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,14 @@ <h2 class="primary-btn" id="instructionsTitle">Player Instructions</h2>

// Function to increment and save the count
function incrementVisitorCount() {
let count = parseInt(getVisitorCount()) + 1;
localStorage.setItem('visitorCount', count);
return count;
if (!localStorage.getItem('visitedHomePage')) {
let count = parseInt(getVisitorCount()) + 1;
localStorage.setItem('visitorCount', count);
localStorage.setItem('visitedHomePage', 'true');
return count;
}

return getVisitorCount();
}

// Function to display the count
Expand Down
12 changes: 8 additions & 4 deletions visi.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ function getVisitorCount() {

// Function to increment and save the count
function incrementVisitorCount() {
let count = parseInt(getVisitorCount()) + 1;
localStorage.setItem('visitorCount', count);
return count;
}
if (!localStorage.getItem('visitedHomePage')) {
let count = parseInt(getVisitorCount()) + 1;
localStorage.setItem('visitorCount', count);
localStorage.setItem('visitedHomePage', 'true');
return count;
}

return getVisitorCount();
}
// Function to display the count
function displayVisitorCount() {
const counterElement = document.querySelector('.website-counter');
Expand Down

0 comments on commit f688d7c

Please sign in to comment.