Stop Traffic From Bouncing off Your Site with this....

Hawkster

Elite Member
Joined
Jun 22, 2013
Messages
3,668
Reaction score
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.

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>
 
Nice thanks for the share, just so i'm clear when does this function work? Is it when the users tries to go "back" in the browser? What browsers does this work with?
 
Nice thanks for the share, just so i'm clear when does this function work? Is it when the users tries to go "back" in the browser? What browsers does this work with?

Yep when the user backs up it redirects them to the URL you want.

I know it works on chrome and firefox on desktop and on chrome on mobile. Unsure about any other browsers but it'll work the same i guess.
 
Great share hawkster, thanks for swooping in with this.
 
Nice share thanks. Just tried it and I see that if you visit from Google for example, then you click back button it takes you to the page you put in the code, rather than taking you back to Google. So I see how it will reduce bounce rate. I know I am stating the obvious but just for everyones benefit :-)

I tested it on latest versions of IE and Chrome and it works on both.

I have taken a screenshot of my bounce rate stats in GA and will check for improvement in next few days, and keep an eye on ranking as well.

Thanks, great share!!
 
I know about this trick, tested and working in all browsers, but the question is, it is safe for google search engine and rankings?
 
Nothing makes me exit a browser quicker than someone taking control if it to push me into seeing what they want.
Yea, but it serves its purpose, at worst the redirected user won't become a returning visitor. :)

I guess it can be modified to a less aggressive, timed redirection, so the user only gets redirected, if he hits the back button shortly after he arrived on the site, but not after he stayed for a while and looked at more than one page.
 
Seems to be working pretty well for me. I recorded bounce rate - 84.38% before I added the code. 7 days later, bounce rate is reduced to 54.74%. Nice :)

One question for you, what if someone Visited my site from Google, then clicked any internal link, then clicked back button? in such case I would rather have him go back to previous post he was at, rather than the one i set in script.
 
One question for you, what if someone Visited my site from Google, then clicked any internal link, then clicked back button? in such case I would rather have him go back to previous post he was at, rather than the one i set in script.

Just just tested like this -

visited google.
typed search query.
clicked link to take me to mysite.com/page1
clicked internal link taking me to mysite.com/page2
clicked back, and it takes me to mysite.com/page1

But if i do like this -
visited google.
typed search query.
clicked link to take me to mysite.com/page1
clicked back, and it takes me to mysite.com/my-bounce-page

So it works only if you click back without going to other pages.
So that means its not an issue what you mention :-)
 
Was my thread...

I am using it for several months now but only on 1 of my sites. Thanks for reminding me to add it on the other sites.

Here is screen of the last 30 days I've been using this

hF8ubz8

Average session duration 16 minutes? :eek:
Is this a streaming site?

I forgot to copy the script on my site lol going to do it now.
 
Seems to be working pretty well for me. I recorded bounce rate - 84.38% before I added the code. 7 days later, bounce rate is reduced to 54.74%. Nice :)

This is only useful if that in turn leads to higher rankings.

Otherwise all you're looking at is an artificial decrease in a fairly useless stat.
 
This is only useful if that in turn leads to higher rankings.

Otherwise all you're looking at is an artificial decrease in a fairly useless stat.

Its true of course.

And I don't know the answer to that. Traffic on this particular site is up 5% compared to previous 7 day period (Before code was added). But I think its impossible to correlate the two - especially as the traffic for this site is quite low anyway.

And I also installed code on another site, for which rankings have improved quite a bit in past 7 days, BUT I am also in the process of link building for this site, so its hard to say where the effect has come from.

Would this really have any effect on rankings anyway? I am not sure. I guess google will track when visitors return to make same queries. For example, if lots of users are clicking on number 1 result and then returning to the results and clicking the number 2 result, Google will take note if this? And maybe also they take note of the period of time between those returns?????
 
Back
Top