0

I've got a client who is setting up a system where a certain segment of visitors to a page "A" will receive a Javascript redirect to another page "B". (I know, not ideal but not my idea...)

They're using a Javascript tag-based web analytics solution (Omniture SiteCatalyst) which is deployed on both pages.

My question is, for visitors who we redirect, can we ensure that the redirect will fire and that they'll be "off" of page "A" before the page "A" web analytics code fires and triggers a page view?

Is there something that needs to be done programatically, and is there a more or less "foolproof" way to make sure that page "A"'s analytics code won't fire, or will any solution have some leakage depending on variations in browsers and net / client PC speed and so forth?

2
  • Is the google anyalytics code you are using synchronous or asynchronous? If it's synchronous, just include the redirect before the ga code. If it's asynchronous it's more complex, but probably doable if you're careful. Commented Sep 14, 2011 at 1:45
  • Even if it is synchronous, wouldn't there be a lag between when the redirect code fires and the redirect actually occurs? Commented Sep 14, 2011 at 6:07

2 Answers 2

5

One way you can be certain is to return the JavaScript code that does the redirection, and nothing else. Is there any reason to load the contents of the page when the user will just be redirected, anyway?

In other words, in the server-side language of your choice:

if in experiment B:
   emit javascript redirection template
else:
   emit template for page A

Where, the JavaScript redirection template is nothing more than:

 <script>window.location.href="path/of/page/B";</script>
Sign up to request clarification or add additional context in comments.

3 Comments

What is your server side language there? I'm not familiar with it.
Ideally, we'd only load the template if the visitor passes the test as you mentioned. However, if it was really ideal the test & redirect would both be server-side, but due to a political and technical mishmash both approaches may not be feasible. However since the analytics code is also JS it should be reasonable enough to just include that part in the if-else logic.
@Surreal Dreams, I was just providing pseudo-code, but you can write your server in any language you like.
2

You'd have to structure the code to look something like this (pseudocode):

if( on_page_a ){
  if( user_requires_redirect ){
    redirect( PAGE_B );
  } else {
    fire_analytics( PAGE_A );
  }
} else {
  fire_analytics( PAGE_A );
}

Hope that makes sense

3 Comments

I think you can skip the if (on_page_a) condition - The code goes on page A, so there's no need to check up on it. Otherwise I agree with you.
From the question, I gather that he has the same analytics code on both pages, which is why I included it.. thx
Thanks, I think this is probably the best way to go with the technical & political limitations we have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.