Hawkster
Elite Member
- Jun 22, 2013
- 3,668
- 4,124
This is not a new thing and many of you will be using it, but i couldn't find the thread i found this on so im posting it in its own thread for anyone that could use it and so i can find it easily in future.
Basically this bit of code stops traffic from leaving your site and instead sends them to any URL of your choice.
I have used this on one site for over 2 years without any problems with ranking. Infact the page i direct my traffic to is sitting at the top of search results for a couple competitive terms and has been for a year or so. And i did little link building to this page so take from that what you will.
Place this code above the [/head] tag in your wordpress editor.
Basically this bit of code stops traffic from leaving your site and instead sends them to any URL of your choice.
I have used this on one site for over 2 years without any problems with ranking. Infact the page i direct my traffic to is sitting at the top of search results for a couple competitive terms and has been for a year or so. And i did little link building to this page so take from that what you will.
Place this code above the [/head] tag in your wordpress editor.
Code:
<script>
var ref = document.referrer;
var siteurl = "http://YOURSITE.COM/";//if you have www, then use www.
if (ref.indexOf(siteurl)!= -1){
}
else{
(function(window, location) {
history.replaceState(null, document.title, location.pathname+"#!/auth");
history.pushState(null, document.title, location.pathname);
window.addEventListener("popstate", function() {
if(location.hash === "#!/auth") {
history.replaceState(null, document.title, location.pathname);
setTimeout(function(){
location.replace("http://YOURCHOSENURL.COM/");
},0);
}
}, false);
}(window, location));
}</script>