Rich-text Reply

URLs and varitions

stefanthorpe 02-08-15

URLs and varitions

I'm doing some testing with a display ads campaign and want to show different varitions based on the url the user is sent to by the ad. For example


User 1 clicks ad 1 and gets sent to this should display varitions 1

User 2 clicks ad 2 and gets sent to this should display varitions 2


and so on.


How do I achieve this?



Amanda 02-08-15

Re: URLs and varitions

Hi @stefanthorpe - There are a few different ways you can achieve this. The best solution depends on how many variations you're looking to display. 


Option 1: You could create a different experiment for each ad campaign. In the audience conditions for each experiment, you could specifiy the URL parameter for the specific ad, ie utm_campaign=ad1. This will ensure that the experiment only runs for traffic coming from this specific source. You'd see the results vs the variation for each ad and you could feasibly have more than one variation for a specific ad. 


Option 2: If you want to do this one experiment, you could open the "edit code" section of your variation and write your code in an if statement. For example, if the utm_campaign paramter = ad1, then populate #1 on the page, else if the utm_campaign parameter = ad2, populat #2 on the page, and so on. 


Option 3: Check out the response by @EricF and @tobyurff in the discussion here: provide another great option to the scenario you are describing.


Here are 2 more articles you might find interesting: 

How to use query parameters for personalization and symmetric messaging

The impact of symmetry in online marketing


Let me know if any of the above sound interesting to you. We can definitely provide some more detail. 


Re: URLs and varitions

Hi Amanda,

Thanks for the response I think Option 2 sounds like the best way for us to tackle the this but I have no clue as to what this code would look like. I read the query params article but this didn't seem to match option2.

Please could you give me some more guidance


Amanda 02-09-15

Re: URLs and varitions

Sure, you can actually leverage the code provided in the article you mentioned. Here is a sample of what this might look like -- you'll have to swap out the parameter name and values in the noted locations. 


Let me know if this helps! 


function getParameterByName(name) {
 name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
 var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
 results = regex.exec(;
 return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));

//Swap out utm_term with whatever your parameter name is.

var paramValue = getParameterByName('utm_campaign')

// Here is a sample if statement. You would swap out the paramValue with the required values. 

if (paramValue = "ad1") {
    //variation code for ad1 goes here;
} else if (paramValue = "ad2") {
    //variation code for ad2 goes here;
} else {
    //generic catch all variation code goes here;



Re: URLs and varitions

Hi thanks for the email, I think I'm starting to understand this. The only question I have is this:

If a have a test with 3 variations can I use an if statement to say if paramValue = "ad1" then load variation 1?
if (paramValue = "ad1") {
    //if yes what code goes here to load variation?