We Need Website

Blog

  • Home
  • How to
  • Hosting
  • Server
  • WordPress
  • Applications

Javascript code to Reduce Bounce Rate by 50% using Force redirects method

Posted by Praan Kumar 7 Comments

Share this

A simple javascript code that can reduce your bounce rate. What is bounce rate? By Mathematical formula the bounce rate is=Total number of bounces across all the pages on the website in a given time/ Total number of entries across all the pages on the website on the same time * 100

Example: Suppose if you have 100 pages. For a given period of bounce rate calculation, your number of entries pages is 80, say after first visiting your web pages, out of 80, 70 users leave your site immediately, then your total number of bounces is 70. So, your Bounce Rate will be 70/80*100=87.5

Which is a very high rate bounce rate. Note that the bounce rate for a regular blog below 50% is normal but above 50% bounce rate is worrying. There are more options to reduce the bounce rate. These non-technical methods to do so. Today we will show to reduce bounce rate using the javascript redirect method.

 

Step 1:

Create a folder in the root directory in your website say, www.yoursite.com/reduce-bounce/

Step 2:

create a new file with .js extension, say it is redirect.js

Step 3:

Put the code given below in the redirect.js file and change the URL located at location.replace(“www.yoursite.com/your-new-post“); with your desired post. Upload the redirect.js script in the folder called www.yoursite.com/reduce-bounce/

To verify you may locate the script by entering the full URL www.yoursite.com/reduce-bounce/redirect.js

If you see the code, you have successfully installed the reduced bounce rate script.

(function(window, location) { history.replaceState(null, document.title, location.pathname+"#!/history"); history.pushState(null, document.title, location.pathname); window.addEventListener("popstate", function() { if(location.hash === "#!/history") { history.replaceState(null, document.title, location.pathname); setTimeout(function(){ location.replace("www.yoursite.com/your-new-post"); },0); } }, false); }(window, location));

 

Step 4:

After that put this small javascript line in the posts that you want to redirect.

<script src="www.yoursite.com/reduce-bounce/redirect.js"></script>

 

Thus you can create multiple redirection javascript files inside the folder and redirect them to a different post.

For the demo, if you click on the back button of this post, it will redirect to our home page.

Example Result:

reduce bounce rate using javascript

Filed Under: Uncategorized

About Praan Kumar

Co-founder of weneedwebsite.com
Marketing Advisor, Software Tester, Webmaster, & SEO Professional.

Comments

  1. Jan Afridi says

    February 28, 2018 at 3:01 am

    Thanks you so much I am using blogger will you please help me that how to put these script in blogger. .

    Reply
    • Praan says

      August 24, 2018 at 2:21 am

      Goto themes, revert to class themes then you can put this script. But you should keep the javascript on third party server location because blogger doesn’t allow to upload files directly.

      Reply
  2. Saloni says

    October 1, 2018 at 10:47 am

    How to use in WordPress platform. Plz, help me.

    Reply
    • Praan says

      October 1, 2018 at 2:15 pm

      This post is platform independent.

      Reply
  3. Aman Patel says

    November 21, 2018 at 12:17 pm

    Thanks, bro but will it help if I use Blogspot platform?

    Reply
    • Praan Kumar says

      December 26, 2018 at 8:19 am

      Yes, it will help.

      Reply
  4. Ashish says

    March 31, 2022 at 7:47 pm

    Man, You’re a rockstar

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Technologies We Use

  • Hosting: Cloudways
  • Theme: Genesis Framework
  • Keyword Research: Semrush

Recent Posts

  • Learn How to Do Keywords Research Properly and Generate Traffic for Blogs
  • How to redirect subfolder to a new domain [No plugin required]
  • List of Instagram Photos & Videos Downloader Tools & Website
  • How To Create A WordPress Website: Step-by-Step Guide
  • Top 5 Best Push Notifications Services for Growth of Your Business & Blogging

Recent Comments

  • Ashish on Javascript code to Reduce Bounce Rate by 50% using Force redirects method
  • edward on How to Embed Tik Tok Videos Inside a html Web Page / WordPress / CMS
  • CHINWENDU IGBAJI on Step by Step Guide How to Install WordPress on Subdirectory on Cloudways
  • Yusuf Khan on How to Install Viral Festival Wishing Script on WordPress Blogs
  • dipenkumar on How to Install Viral Festival Wishing Script on WordPress Blogs

Copyright © 2023 We Need Website | Privacy Policy . About Us . Contact Us