Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
Run different js on each user visit

I want to load javascript functions on a wordpress site based on user visit, if it's the first time, then one function will run, if its second visit another code will run., I found that using cookies and local storage we can set it, but only track user if visited or not., I want to count the user visit, and based on that run the functions.

var first_visit = false;
checkFirstVisit();
function checkFirstVisit(){
    if(localStorage.getItem('was_visited')){
        return;
    }
    first_visit = true;
    localStorage.setItem('was_visited', 1);
}
console.log(first_visit);

this code is to track the first visit, How do I make it to track the number of visits?

almost 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

it is the same thing set a cookie for visiting if it is not set so it is the first visit so set it to 1 if it is 1 so second visit so set it to 2 if it is n so it is n + 1 visit so incrment n

almost 4 years ago · Santiago Trujillo Denunciar

0

You can use session storage in PHP (https://www.w3schools.com/php/php_sessions.asp) to store in a variable whether this is the user's first visit or not. Then using an if-else statement, display the required code. The good thing about PHP session storage is that it can retain the storage even after the user closes the browser.

almost 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda