java script execute code on every 10th vistor

Make it count every unique visitor automatically, once the count hits 10, run X and reset count.
 
is there anyway to code a piece of JS (very basic) to only execute/work on every 10th or 100th or what ever visitor/hit to to your webpage
I would want to put it in an if else statement but cant find away of setting this limitation

I created a gist for you: https://gist.github.com/c0d3r111/96baee9ba1692b601bfb61187684af1e

You'll need to run the script behind a nginx reverse proxy

Deps:
npm i -g pm2
npm i metrohash

Run:
pm2 start counter.server.js

Simply copy the counter.client.js code to your app (script return 1 if hit count total divisible by specified divisor or 0 if not), then in your app access hit total variable assigned to window named TOTAL_HITS (window.TOTAL_HITS).

Let me know if you need more help. (Sorry didn't test script, but simple enough to debug in my mind).
 
Back
Top