I need to track my users time on website using javascript. My website is only one page long so something like piwik or google whatever is too heavy handed. How can I generate a random 12 letter long id (for example “sEjhWixldIdy”) when the user first connects and repeatedly ping “example.com/tracker.py?id=sEjhWixldIdy” every 1000 milliseconds or so. I know how to do the python end of it, but how to do the client side?
EDIT:
is this possible without using jQuery?
The easiest strategy to achieve this in vanilla JS is probably to add an image on the page (
src= your Python file) and update it every second:Alternatively, you can use the
XMLHttpRequestobject (and do aPOSTto eliminate cache-related issues):