Is there a way to retrieve the URL of the last visited page using JavaScript? I want to be able to track which product the user viewed most recently. I have attempted the following code:
var x = document.referrer;
document.getElementById("demo").innerHTML = x;
I also tried this alternative method:
var currentLocation = window.history.previous.href;
Unfortunately, neither of these solutions worked for me. If you know of a working solution, please share - I would greatly appreciate it.