Rich-text Reply
Highlighted

Redirect Slow Load time

smcurrey528 05-13-19

Redirect Slow Load time

Hi, 

 

We are wanting to run some redirect tests on some web pages, and the redirect has such slow load time that the user could click on CTAs from the previous page before being redirected. I tried using the Optimizely built-in option, and then the code below. 

 

var jq = window.optimizely.get("jquery");
jq(document).ready(function() {
  window.location.replace("http://urlhere.com");
});

Does anyone have any recommendations?

JasonDahlin 05-14-19
 

Re: Redirect Slow Load time

The snippet you posted is waiting for document.ready() which means that the entire page has loaded before the redirect occurs. The redirect function I developed for us looks like this:

 

(function(){
	var thisPath = window.location.pathname;
	var thisQS = window.location.search;
	var newPath = "";

	if (newPath === "" && thisPath.indexOf('/unique-pagename) > -1) {
		newPath = thisPath.replace('/unique-pagename','/new-page-here');
	}

	if (newPath !== "" && newPath != thisPath) {
		window.location.replace(newPath + thisQS + '&newParameters=GoHere');
	}
})();

 

 

The snippet above allows the experiment to run on one general Page Type such as "All Category Pages" but the code itself will only affect the specific page .It has 3 basic parts:

1- dissect the URL into chunks

 

2- replace the portion of the path with the new URL path

When the experiment runs on the "/unique-pagename" we replace that portion of the URL with the path we want to send the user to instead.  The conditions in the "if" statement allow for this to be repeated several times in cases where you want to run the experiment on multiple pages all inside the Page Type you have for URL targeting.  For example, you could replace "/mens-sale" with "/mens-offers" and then replaces "/womens-sale" with "/womens-offers", etc.

 

3- put it all together and redirect

This section tells the experiment to perform the redirect only if it has actually changed the URL. This is also where you can add any new URL parameters which may help with identifying users in your web analytics platform. If you are not using a robust web analytics platform for your analysis, you will want to narrow the definition of your URL Targeting.

--Jason Dahlin
Analytics and Testing Guru Smiley Happy


Experimentation Hero
Michal 05-14-19
 

Re: Redirect Slow Load time

I can second what Jason is saying in that your snippet waits for the page to fully load before the redirect gets executed - i.e. the opposite of what you're probably after.

I would just like to add that you don't need to write your own redirect function at all with Optimizely. You can also simply use the built-in functionality and only enter the URL that you want to be redirected to. For more information about this have a look here: https://help.optimizely.com/Build_Campaigns_and_Experiments/Redirect_experiments%3A_Test_two_URLs_in...
Optimizely
smcurrey528 05-14-19
 

Re: Redirect Slow Load time

I did try using the bulilt-in functionality first but the redirect is too slow to use. Users can click on buttons from the page we are testing against before they get redirected which gives bad data.
JasonDahlin 05-14-19
 

Re: Redirect Slow Load time

Sounds like you may have the snippet loading late?
Can you share a URL of your site so we can see where it is placed?
--Jason Dahlin
Analytics and Testing Guru Smiley Happy


Experimentation Hero