Home > Paid Traffic Sources > Mobile

redirect on back button click (46)


01-31-2015 09:59 AM #1 vaalion (Member)
redirect on back button click

Hi!

Trying to implement back button script, this shit's confusing.

Here's my code:

Code:
window.addEventListener("popstate", function(e) {
            if(document.URL.indexOf("other.html") >= 0){
                document.location.href = document.location;
            }
        });
    window.history.pushState('other.html', 'Other Page', 'other.html');
    window.history.pushState('first.html', 'Initial Page', 'first.html');
on other.html there's a simple redirect script to voluum campaign.
What I want to do is instead of lp --> other.html --> voluum campaign is to directly do it. lp --> voluum campaign (on back button press)
So I'm looking for something like window.history.pushState('www.Voluum.com/other.html', 'Other Page', 'www.Voluum.com/other.html');

how can I do that?


01-31-2015 12:11 PM #2 aaaart (Member)

This one works for me.

Copy this one in your <head>

Code:
<script type="text/javascript" src="backfix.min.js"></script>
And this one in the bottom of your <body>

Code:
<script language="javascript" type="text/javascript">
bajb_backdetect.OnBack = function(){
window.history.back=function(){document.location=' http://xxxx.voluumtrk.com/YourUniqueCampaignURL'}
}
</script>
copy this file in your directory, where the index.html is and name it backfix.min.js - https://code.google.com/p/group97230...ix.min.js?r=61

There might be a more efficient way, but thats how it works for me.


01-31-2015 02:37 PM #3 vaalion (Member)

Thank aaart! I'm sure there's a better way though.
Can anyone be kind enough to share?


01-31-2015 04:35 PM #4 shakedown (Member)

This one works. Upload other.html into the same directory. I saw some people doing some pretty hilarious/creative shit with this while spying.

Code:
<script type="text/javascript">
         window.history.pushState('other.html', 'Other Page', 'other.html');
         window.history.pushState('initial.html', 'Initial Page', 'initial.html');
    </script>

    <script type="text/javascript">

         window.addEventListener("popstate", function(e) {
            if(document.URL.indexOf("other.html") >= 0){
                document.location.href = document.location;
            }
         });

    </script>


02-01-2015 11:18 AM #5 vaalion (Member)

shakeddown I think you misunderstand, I mean without redirecting through other.html but sending em straight to Voluum


02-02-2015 03:38 AM #6 erikgyepes (Moderator)

Btw guys how do you tracking Voluum data with back button redirects?

As if you redirect straight to a "middle page" (eg. back.html) you lose all the data like Site ID and you will not able to optimize on those data anymore.

Do you have solution for this?


02-02-2015 03:50 AM #7 prof (Member)

You can set-up a new campaign exclusively to track your back button redirect clicks and set rules based on each geo.

Then set your redirect URL to your new Voluum campaign URL. The script aaaart posted will allow for this.


02-02-2015 04:01 AM #8 erikgyepes (Moderator)

That's exactly what I'm doing, but as I'm sending people from my LP instead of traffic source I lose my tokens. Don't know how to carry them so in the end it got tracked. This way I just see them as "Unknown" in Voluum.


02-02-2015 05:11 AM #9 prof (Member)

Ah ok. Getting that granular on a back button redirect will get more tricky.

The only way I can think to do it - and I haven't tried this - would be to pull the whatever variables you need into the query string of your landing pages then extract that information using javascript in a similar way to how you would call out model, browser, city etc.

Code:
<script>
function getURLParameter(name) {
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1] || ''
    );
}
</script>
Then you could carry those variables from the query string into the URL you assign with the redirect script.

Instead of using a token - you'd be using whatever parameter is contained within the URL query of the landing page the user is on.

There may be a better way to do this, to which I'm sure someone with a better hand for coding might be able to enlighten you, but I can't see why the above wouldn't work if you fiddle around with it a bit.


02-02-2015 05:42 AM #10 peterpan (Member)

Quote Originally Posted by prof View Post
You can set-up a new campaign exclusively to track your back button redirect clicks and set rules based on each geo.

Then set your redirect URL to your new Voluum campaign URL. The script aaaart posted will allow for this.
That sounds great, would you mind explaining how we can setup this new rule for this?


02-02-2015 07:57 AM #11 louisachoo (Member)

Quote Originally Posted by shakedown View Post
This one works. Upload other.html into the same directory. I saw some people doing some pretty hilarious/creative shit with this while spying.

Code:
<script type="text/javascript">
         window.history.pushState('other.html', 'Other Page', 'other.html');
         window.history.pushState('initial.html', 'Initial Page', 'initial.html');
    </script>

    <script type="text/javascript">

         window.addEventListener("popstate", function(e) {
            if(document.URL.indexOf("other.html") >= 0){
                document.location.href = document.location;
            }
         });

    </script>
tried this and it works fine on it's own. but when i couple with Voluum's callout scripts the tokens can't seem to pass through. eg my link: abcde.com/index.html?brand={brand} just becomes abcde.com/index.html after hitting enter.

any idea why?


02-03-2015 02:27 PM #12 avn_0903 (Member)

Maybe you should put these codes on your other.html page: http://stmforum.com/forum/showthread...s-querystrings


02-03-2015 02:54 PM #13 erikgyepes (Moderator)

Quote Originally Posted by louisachoo View Post
tried this and it works fine on it's own. but when i couple with Voluum's callout scripts the tokens can't seem to pass through. eg my link: abcde.com/index.html?brand={brand} just becomes abcde.com/index.html after hitting enter.

any idea why?
You not see them because the pushstate rewrites the url, but the tokens should be converted to real data on the LP.


02-03-2015 04:37 PM #14 lazylobster (Member)
redirect on back button click

I have a sophisticated back button redirect script with CPC monetization if anybody is interested. Send me a PM for details

Works all browsers even mobile


02-05-2015 05:32 AM #15 avn_0903 (Member)

Quote Originally Posted by aaaart View Post
This one works for me.

Copy this one in your <head>

Code:
<script type="text/javascript" src="backfix.min.js"></script>
And this one in the bottom of your <body>

Code:
<script language="javascript" type="text/javascript">
bajb_backdetect.OnBack = function(){
window.history.back=function(){document.location=' http://xxxx.voluumtrk.com/YourUniqueCampaignURL'}
}
</script>
copy this file in your directory, where the index.html is and name it backfix.min.js - https://code.google.com/p/group97230...ix.min.js?r=61

There might be a more efficient way, but thats how it works for me.
I believe this script doesn't work with Chrome? I tried this with both Safari and Chrome on iOS but only Safari worked.


02-09-2015 02:13 PM #16 vaalion (Member)

I find it to fire duplicate conversions with the redirect campaign. does it happen to you as well?


02-15-2015 03:42 AM #17 louisachoo (Member)

Quote Originally Posted by avn_0903 View Post
Maybe you should put these codes on your other.html page: http://stmforum.com/forum/showthread...s-querystrings
Quote Originally Posted by erikgyepes View Post
You not see them because the pushstate rewrites the url, but the tokens should be converted to real data on the LP.
Thanks fellas. Figured out. we need to append the same tokens into the html as well.

Ie Instead of just other.html or initial.html we need to place the tokens into the page code as well. In case anyone else is struggling with this.


03-26-2015 12:47 PM #18 Philwil (Member)

The one from aaart works for me " <script type="text/javascript" src="backfix.min.js"></script>"

But I am also trying to make the other script work. I have it like this:
---
<script type="text/javascript">
window.history.pushState('http://google.com', 'Other Page', 'http://google.com');
window.history.pushState('inex.html', 'Initial Page', 'index.html');
</script>

<script type="text/javascript">

window.addEventListener("popstate", function(e) {
if(document.URL.indexOf("http://google.com") >= 0){
document.location.href = document.location;
}
});

</script>
---
I want the back redirect with this script to go to an offer, not to an html or php file in the same directory. To get it to work to redirect to an offer url, I made a back.php file with a redirect to offer url.


03-27-2015 08:19 PM #19 Mr Yaz (Member)

Quote Originally Posted by shakedown View Post
This one works. Upload other.html into the same directory. I saw some people doing some pretty hilarious/creative shit with this while spying.

Code:
<script type="text/javascript">
         window.history.pushState('other.html', 'Other Page', 'other.html');
         window.history.pushState('initial.html', 'Initial Page', 'initial.html');
    </script>

    <script type="text/javascript">

         window.addEventListener("popstate", function(e) {
            if(document.URL.indexOf("other.html") >= 0){
                document.location.href = document.location;
            }
         });

    </script>
@shakedown - what do you put in other.html, are you using the same exact web page code or something else?


03-27-2015 08:20 PM #20 Mr Yaz (Member)

Seeing this on a few landers I'm trying to mod, don't really understand what the code is doing. Further insight is very welcomed..


03-28-2015 02:17 AM #21 sleenirvana (Member)

It's called a back trap script. It redirects to click url when the user hits back.


03-28-2015 04:59 PM #22 Mr Yaz (Member)

Thx Sleen. So basically you throw in your Voluum tracking URL or do you put in your full lander URL? I'm trying to get mine to work... Also have you used it quite a bit/experience on how it impacts conversions?


03-29-2015 04:09 AM #23 sleenirvana (Member)

Just put the click url. The same url you use for your cta


03-29-2015 05:18 PM #24 sleenirvana (Member)

Depends. It's a little better when you add an exit popup and then redirect them


03-29-2015 05:21 PM #25 Mr Yaz (Member)

Thanks again Sleen..


03-30-2015 06:59 PM #26 louisachoo (Member)

Quote Originally Posted by erikgyepes View Post
You not see them because the pushstate rewrites the url, but the tokens should be converted to real data on the LP.
Noticed that the the parameters do not get written onto the LP afterall. Because of the pushstate, anyone can advise? Works fine without the loop, but with the pushwrite, tokens no longer get passed. Hmm.


05-26-2015 03:29 PM #27 pain2k (Veteran Member)

Here's one I found on StackOverFlow that worked well in Chrome. Place above the closing </body> tag and make sure you are calling the jquery library.

Code:
<script>
jQuery(document).ready(function($) {

      if (window.history && window.history.pushState) {

        $(window).on('popstate', function() {
          var hashLocation = location.hash;
          var hashSplit = hashLocation.split("#!/");
          var hashName = hashSplit[1];

          if (hashName !== '') {
            var hash = window.location.hash;
            if (hash === '') {
              alert('Back button was pressed.');
                window.location='www.example.com';
                return false;
            }
          }
        });

        window.history.pushState('forward', null, './#forward');
      }

    });
</script>


05-27-2015 02:27 AM #28 vortex (Senior Moderator)

Just want to report that aaaart's method worked for me as well! Thanks so much!

Amy


05-31-2015 05:58 AM #29 orisin1 (Member)

Quote Originally Posted by vortex View Post
Just want to report that aaaart's method worked for me as well! Thanks so much!

Amy
Works for me to for the most part, there is something that I haven't figured out yet, with some URL's it just doesn't work. Is there an issue with how long the back URL can be?


06-01-2015 01:25 AM #30 vortex (Senior Moderator)

Quote Originally Posted by orisin1 View Post
Works for me to for the most part, there is something that I haven't figured out yet, with some URL's it just doesn't work. Is there an issue with how long the back URL can be?
Can you please give more details on which URLs don't work? Would be nice to know where exactly the method fails so we could look out for them. Thanks in advance!


Amy


06-01-2015 06:08 AM #31 orisin1 (Member)

It's not a specific URL but from what I noticed if I put http://myurl.com it works and if I put http://myurl.com?s1=z&s2=b it doesn't work for example. I thought maybe it had to do with tokens or something but it looks more that from a certain length it gives me problems, just my guess I have zero clue in programming (:


06-02-2015 09:41 AM #32 vortex (Senior Moderator)

Quote Originally Posted by orisin1 View Post
It's not a specific URL but from what I noticed if I put http://myurl.com it works and if I put http://myurl.com?s1=z&s2=b it doesn't work for example.
My team member has just told me the same problem you experienced - that parameters passed via url were "getting messed up" by the backbutton code. His solution? Just put the backbutton code at the very end of the lander and it should work! Good luck and please let me know if it doesn't fix the problem - we'll figure it out!


Amy


06-03-2015 04:37 AM #33 orisin1 (Member)

[QUOTE=vortex;227365]My team member has just told me the same problem you experienced - that parameters passed via url were "getting messed up" by the backbutton code. His solution? Just put the backbutton code at the very end of the lander and it should work! Good luck and please let me know if it doesn't fix the problem - we'll figure it out!

Thank you Amy
Honestly I don't know at this point if it helped or not. testing it on different browsers and devices made me a bit confused-sometimes it works sometimes not. I have been seeing conversions however. Maybe sometime it's a cookie issue.
We'll stick with it for now (:


06-03-2015 05:07 AM #34 vortex (Senior Moderator)

Yeah I've noticed that a lot of code will only work for some browsers and not others....as long as implementing the code makes the lander perform better than before overall speaking, then the purposes is served. It may also help to look into stats to see whether the lander's performing especially poorly for certain browsers/devices and try to track down the problem for these specifically.

Alternatively, we could just spend the time testing new offers...

Depends on how keen of a problem-solver you are I guess!

Amy


06-03-2015 05:09 AM #35 orisin1 (Member)

Quote Originally Posted by vortex View Post
Yeah I've noticed that a lot of code will only work for some browsers and not others....as long as implementing the code makes the lander perform better than before overall speaking, then the purposes is served. It may also help to look into stats to see whether the lander's performing especially poorly for certain browsers/devices and try to track down the problem for these specifically.

Alternatively, we could just spend the time testing new offers...

Depends on how keen of a problem-solver you are I guess!

Amy
Haha, I think in my instance it'd better testing new offes/scaling. We'll take what we can get from this back button script. Thank you very much for your help!


06-10-2015 06:37 PM #36 orisin1 (Member)

**Quick Update**
I have been using the redirect back function for the past 2 weeks or so and it added another $150 to my revenue that I wouldn't have seen otherwise. Think of smart ways to incorporate it into the funnel, meaning the back page needs to make sense even though that's not the page the user meant to go to.
Example:
anti virus lp
hits back button
JS alert : "virus attack in progress, click ok to remove viruses"
Offer

Technically what I would like to know is how use the imobitrax landing page link as the back link
"<?php echo $offer; ?>"


06-10-2015 06:53 PM #37 vortex (Senior Moderator)

Wow thanks for that update orisin!!

Regarding flow/funnel, I have some additional food for thought: If you're using pop traffic, remember that it's "interrupt" marketing, meaning whatever it is you're promoting on your first lander, the visitor did NOT ask for it! What I'm trying to say is that it may work better to direct them to a totally different lander when they hit the backbutton - something promoting an entirely different offer - because chances are if they've hit the backbutton in the first place it's because that type of offer didn't appeal to them, so we hit them with a different offer!

Of course ultimately everything will depend on how good your particular landers and offers are...

Stats don't lie so only testing will tell.


Amy


08-02-2015 11:50 PM #38 guyver888 (AMC Alumnus)

Quote Originally Posted by erikgyepes View Post
That's exactly what I'm doing, but as I'm sending people from my LP instead of traffic source I lose my tokens. Don't know how to carry them so in the end it got tracked. This way I just see them as "Unknown" in Voluum.
Does anyone have a solution to this?

So I have campaign set up exclusively to track my back button redirect clicks. However when I view my traffic source tokens in Voluum they do not get tracked. How do I pass the tokens from my initial voluum campaign to the redirect campaign?

Any help appreciated.

Thanks


08-03-2015 07:02 AM #39 shogun (Member)

OK, this will pass all current campaign tokens except voluumdata token.

Code:
	var redirect_camp_link="your_link";
	var querystring=window.location.search;
	function removePar(name,qString){
		el=decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(qString)||[,null])[0] ||'' );
		new_st=qString.replace(el,'');
		return new_st;
	}
	history.replaceState(null, document.title, location.pathname +querystring+ "#!/stackthatmoney");
	history.pushState(null, document.title, location.pathname+querystring);
	window.addEventListener("popstate", function() {
		if (location.hash === "#!/stackthatmoney") setTimeout(function() {
			location.replace(redirect_camp_link+removePar('voluumdata',querystring))
		}, 0)
	}, false);
Important part:
delete ?ad={ad} from your redirect camp link
so it will be something like
Code:
redirect_camp_link='http://xxxx.voluumtrk.com/23369d27-b2ad-4b3a-9c4d-27542914e176b'
and not
Code:
redirect_camp_link='http://xxxx.voluumtrk.com/23369d27-b2ad-4b3a-9c4d-27542914e176b?ad={ad}'


08-03-2015 08:07 AM #40 shogun (Member)

I've put together another script that will pass only needed tokens.
I've intentionally make it long and added comments. Enjoy!

Code:
<script>
	//redirect campaign link, without tokens
	var redirect_camp_link="your_link";
	//put your tokens to pass to back btn campaign here, respect the format.
	var tokens_to_pass=['ad','taffic_source'];
	
	//get tokens part of the link
	var querystring=window.location.search;
	
	// put tokens in a readable and reusable array
	var urlParams;
	function getURLPars() {
		var match,pl=/\+/g, search=/([^&=]+)=?([^&]*)/g, decode=function (s){ return decodeURIComponent(s.replace(pl, " "));},query  = querystring.substring(1);
		urlParams = {};
		while (match = search.exec(query))
		urlParams[decode(match[1])] = decode(match[2]);
	}
	getURLPars();
	
	//create a new tokens string
	function addPars(parrArray){
		var new_pars='';
		if(urlParams[parrArray[0]]) new_pars=new_pars+'?'+parrArray[0]+'='+urlParams[parrArray[0]];
		for(i=1;i<parrArray.length;i++){
			if(urlParams[parrArray[i]]) new_pars=new_pars+'&'+parrArray[i]+'='+urlParams[parrArray[i]];
		}
		return new_pars;
	}

	//back button hack
	history.replaceState(null, document.title, location.pathname +querystring+ "#!/stackthatmoney");
	history.pushState(null, document.title, location.pathname+querystring);
	window.addEventListener("popstate", function() {
		if (location.hash === "#!/stackthatmoney") setTimeout(function() {
			//setup redirect link + tokens
			location.replace(redirect_camp_link+addPars(tokens_to_pass))
		}, 0)
	}, false);
</script>


08-03-2015 01:06 PM #41 guyver888 (AMC Alumnus)

Quote Originally Posted by shogun View Post
OK, this will pass all current campaign tokens except voluumdata token.
Code:
	var redirect_camp_link="your_link";
	var querystring=window.location.search;
	function removePar(name,qString){
		el=decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(qString)||[,null])[0] ||'' );
		new_st=qString.replace(el,'');
		return new_st;
	}
	history.replaceState(null, document.title, location.pathname +querystring+ "#!/stackthatmoney");
	history.pushState(null, document.title, location.pathname+querystring);
	window.addEventListener("popstate", function() {
		if (location.hash === "#!/stackthatmoney") setTimeout(function() {
			location.replace(redirect_camp_link+removePar('voluumdata',querystring))
		}, 0)
	}, false);
Important part:
delete ?ad={ad} from your redirect camp link
so it will be something like
Code:
redirect_camp_link='http://xxxx.voluumtrk.com/23369d27-b2ad-4b3a-9c4d-27542914e176b'
and not
Code:
redirect_camp_link='http://xxxx.voluumtrk.com/23369d27-b2ad-4b3a-9c4d-27542914e176b?ad={ad}'
Thanks Shogun for the script but I guess this will not work for me as this does not track Voluum data. Basically I am unable to identify which placements from my traffic source is providing me conversions for my redirect button campaign. Is a script even possible? My coding knowledge is limited.


08-03-2015 01:55 PM #42 shogun (Member)

hm... you confuse me

How do I pass the tokens from my initial Voluum campaign to the redirect campaign?
the scripts i've posted do just that


08-03-2015 02:51 PM #43 shogun (Member)

Let's brake it down:
Your initial campaign link

Code:
http://xxx.voluumtrk.com/some_code1?ad=ad1&placement=reddit
Your redirect campaign link
Code:
http://xxx.voluumtrk.com/some_code2
you use the second script and set
Code:
tokens_to_pass=['ad','placement'];
when redirect occur your redirect campaign link will look like
Code:
http://xxx.voluumtrk.com/some_code2?ad=ad1&placement=reddit
Obviously you have to setup your traffic source variables on the back btn campaign to match those (use the same traffic source as the main campaign)


08-03-2015 05:10 PM #44 erikgyepes (Moderator)

Didnt try your solution, but I bought the script from affkit few months ago that exactly solved my issues with passing tokens above.


08-04-2015 09:56 AM #45 guyver888 (AMC Alumnus)

Thanks Shogun. The 2nd script where I passed my chosen tokens works for me.


08-04-2015 11:40 AM #46 shogun (Member)

awesome!


Home > Paid Traffic Sources > Mobile