I need to collect data for statistics that people did for each visit to the site. Those. A person came to the site, he was given the visit id, which is saved only for a while while he is walking around the site. And when traveling around the site, the visit id and some data are sent to the database, the names of the pages visited and some more data.
In the script below, according to my logic, a timer is started to check for the presence of cookies with the visit id, if there is no cookie, then set the visit id and write it to the cookie, if there is a cookie, then take it from the cookie and overwrite the cookie.
What is wrong doing?
My code is:
// Π€ΡΠ½ΠΊΡΠΈΡ ΡΡΡΠ°Π½ΠΎΠ²ΠΊΠΈ id Π²ΠΈΠ·ΠΈΡΠ° ΠΈ ΠΏΡΠΎΠ²Π΅ΡΠΊΠΈ Π½Π°Ρ
ΠΎΠΆΠ΄Π΅Π½ΠΈΡ ΡΠ΅Π»ΠΎΠ²Π΅ΠΊΠ° Π½Π° ΡΠ°ΠΉΡΠ΅ function check_vicit_id() { if (!getCookie(VISIT_ID_COOKIE)) { var date = new Date; date.setTime(date.getTime()+(5*1000)); visit_id = rand(1111111, 9999999)+"."+date.getTime(); // Π³Π΅Π½Π΅ΡΠΈΡΡΠ΅ΠΌ ΡΠ½ΠΈΠΊΠ°Π»ΡΠ½ΡΠΉ visit_id ΠΏΠΎΡΠ΅ΡΠΈΡΠ΅Π»Ρ document.cookie = ""+ VISIT_ID_COOKIE + "="+ visit_id +";expires="+ date.toGMTString() + "; path='/'"; console.log( 'ID VISIT: ' + visit_id); } else { var date = new Date; date.setTime(date.getTime()+(5*1000)); visit_id = getCookie(VISIT_ID_COOKIE); document.cookie = ""+ VISIT_ID_COOKIE + "="+ visit_id +";expires="+ date.toGMTString() + "; path='/'"; console.log( 'ID VISIT: ' + visit_id); } } function check_vicit() { setInterval(function() { check_vicit_id (); }, 1000); }