Implementation of the web page counter in 2013

I am looking to implement a web page hit counter so that the server knows which pages are being viewed, where I try to avoid sending repeated "user hits" to the server by the same user on the same page. (I'm not really worried that they clear their cache, etc. And maybe counted again)

I usually saw something like this:

<img src="/the-hit-counter?pageId=SOME_PAGE_ID" /> 

then use a cookie to make sure that the "hit" does not count again.

But is there any reason not to use AJAX to notify the server, other than the obvious "the user must have JavaScript enabled"? I assume that almost everyone who does not wear a tin foil hat will be included in their browser these days.

With AJAX and JavaScript, I could do something like this and bring the local storage into a mix and reduce some network bandwidth:

 if (!amplify.store('SOME_PAGE_ID')) { $.get('/the-hit-counter?pageId=SOME_PAGE_ID'); amplify.store('SOME_PAGE_ID', ""); } 

What am I missing regarding the JavaScript approach?

+6
source share
1 answer

I think that 2013 for this is to simply register Google Analytics and paste your generated JavaScript into your website. It is much easier than promoting your own solution, and you get a lot of user data (demographic data, locations, exact number of users, etc.).

+9
source

Source: https://habr.com/ru/post/949508/


All Articles