Use this Back Button Script and Exit Intent Code to Convert Unwanted Conversions

By Ian Fernando

When buying traffic you want to try to monetize every bit of it as much as you can. This post is something you should bookmark.

Just in case your traffic doesn't convert, you still want to try to monetize it any way possible - trying to retain your ad spend as much as you can.

Today, I am going to share 2 JS code for you to utilize when trying to monetize other traffic you might know about. There are 2 ways to monetize your clicks by 2 simple things users are doing when trying to leave, back button traffic and exit intent traffic.

The way to do this is to redirect the traffic to a new offer. The way we do this is to use affiliate smart links.

What Are Affiliate Smart Links?

Smart links are just affiliate links that redirect the traffic to other offers. Some are base on pure randomness and some are base on the actual logic, figuring out the device and location of the user to send them the perfect offer.

Smart links are meant to try to optimize and monetize the user as much as possible by their device, browser, wifi or 3g, etc. There are a lot of variables to figure out and the smart link will try to optimize base on the actual user.

One popular smartlink platform to use is and TopOffers. I will probably go in depth more about smart links in another post.

Now, let us take a look at the first script, this is a back button script. This essentially disables the back button and then turns it into a link. So when the user clicks on the back button they are clicking on a redirect link.

Here is the code for back button traffic redirect:

<script type="text/javascript">
! function () {
var t;
try {
for (t = 0; 10 > t; ++t) history.pushState({}, "", "#");
onpopstate = function (t) {
t.state && location.replace("https://URLHERE")
} catch (o) {}

This next script is a version of a exit intent popup. It will popup a dialogue box with a message and a single button 'OK' - when the user clicks on the ok button they are redirected to an offer via the affiliate smart link.

Here is the code for exit intent traffic redirect:

window.exitMessage = "Do You Really Want to Exit?";
window.redirectURL = "https://URLHERE";
var isAlert = false;
function exitStopper()
if (isAlert){
isAlert = false;
if( window.redirectURL)
window.location.href = window.redirectURL;
window.addEventListener('blur', exitStopper );
document.body.addEventListener("mouseleave", function(e)
if( e.offsetY <= 0 )
isAlert = true;
}, false);

You can use your own exit intent like maybe collect a lead maybe or last minute click graphical button offering an incentive like what you see on this blog sometimes. This script doesn't make anything graphical but pops a message box for the user confirming they want to leave.

If they do, they are redirected.

Why not just send the traffic to the original offer?

People ask this a lot in the affiliate forums and the reason is - why would you when the end user is already not interested in the offer. You are just going to ruin the LP CTR and your analytics even more.

The user will not convert anyways, because they are trying to leave and forcing them on the offer will just get them mad, BUT maybe showing them another offer might help them engage and hopefully convert.

I personally just utilize a smart link, I can focus on 2 affiliate offers and send the remnant traffic to a similar offer but I would rather focus the conversion on the 1 and then let the smart link handle the exit traffic.

The goal of these scripts is to utilize another offer or a smart link and try to recoup the ad spend just a bit.

Ian Fernando
Involved in the internet space since 2002 and have been through the ups and downs of this online industry. I am a traveling digital nomad, media buyer, online strategist, and many more online titles.

Start Affiliate Marketing Today.

An high overview of how to get started in affiliate marketing. $ straight forward videos on understanding the basics of affiliate marketing and generating revenue online.