0

I am new with javascript and i have to implement some functionality with javascript. I want to redirect users who are coming to my site via browser back button. SO how i can track my website visitors that they are coming to my site via browser back button or directly by typing my site URL in a browser tab.
I am able to find out similar solution but all those are working for the exiting web page users but i want to implement this for incoming users so whether they are coming to my web page via browser back button or not.
I will really appreciate if someone will be able to guide me about this.
Thank you!!

wplearner
  • 405
  • 6
  • 19
  • 1
    Possible duplicate of [JavaScript or jQuery browser back button click detector](https://stackoverflow.com/questions/17594413/javascript-or-jquery-browser-back-button-click-detector) – apires Jun 02 '17 at 20:19
  • Thanks for your response but Sorry but this is not a solution to my problem. It is working for the existing users who are already on my page but i want to track incoming users so whether they are coming to my web page via browser back button or not. – wplearner Jun 02 '17 at 20:25
  • Possible duplicate of [Back button redirect script](https://stackoverflow.com/questions/30990027/back-button-redirect-script) – Reed Jun 02 '17 at 20:27
  • I would honestly be surprised if there was a way to detect this. Seems like a very edge use case. – David Jun 02 '17 at 20:44
  • So @David is it not possible? – wplearner Jun 02 '17 at 20:53

2 Answers2

0

I've tackled this problem using local storage .. simply put

Example :

window.onload = function(){

    var timesVisited = window.localStorage.getItem('tracker');

    if(!timesVisited){

        //If never visited set tracker for first time

        window.localStorage.setItem('tracker' , JSON.stringify({count : 1}))
        return;

    }else{

        timesVisited = JSON.parse(timesVisited).count
    }

    if(timesVisited > 1){
        alert('Welcome Back !!!!')
    }

}

Local value storage is permanent until deleted by you or user

Hope this helps

KpTheConstructor
  • 3,153
  • 1
  • 14
  • 22
0

You can inspect and parse document.referrer to see if user came from inside your site or elsewhere

charlietfl
  • 170,828
  • 13
  • 121
  • 150