Is there an easy way to track how many pages a user on your site has visited with Javascript (preferably jQuery)?
I need to execute a function after a user has visited more than 5 pages on the site.
I was thinking of storing the window.location.href into a variable and checking it to see if it matches the next page. If it doesn’t I would register it as one page change and so on. This sounds theoretically sound to me but please do direct me if I’m on the wrong path.
jQuery does not have native cookie functions.
While I completely agree this should be done server-side and would never do this myself… You can do this entirely with plain-old Javascript.
I’ve put together a function that should suit your purposes. It returns true only if they’ve visited 6 pages where each page was different than the immediately preceding page.
I didn’t specifically test this… let me know if you have any issues.