1

I'm trying A/B test a number of landing pages. I need some Javascript code that will replace the breadcrumbs and logo URL for the homepage across the whole site depending on which landing page the user visits. So if they land on page B, but then navigate to page X, they can click on the logo to return to page B.

My original site has:

<a id="logo" href="A"></a>
<p id="breadcrumbs"><a href="A"></a></p>

And I need the code to do something like:

if page B has been visited {
   (#logo).href(B);
   (#breadcrumbs a).href(B)   
}


if page C has been visited {
   (#logo).href(C);
   (#breadcrumbs a).href(C)   
}

Is it even possible to do this across the whole site, or would it only change urls on this page?

Could I drop a cookie on page B and use the cookie as my condition?

if user has cookie C {
   (#logo).href(C);
   (#breadcrumbs a).href(C)   
}
James Thorpe
  • 31,411
  • 5
  • 72
  • 93
vexalist
  • 67
  • 6

1 Answers1

1

You can use window.name to send info between pages, from A/B to other page (and only that)

Something like this

window.name = "This message will survive between page loads.";
Now add the following code to any other page:
alert(window.name);

More info here

Now, you can use cookies to set/use it on the entire website...

Something like

document.cookie="landingPage=B: expires=Thu, 18 Dec 2013 12:00:00 UT";

And to read it its just like

var x = document.cookie;

So, you can just add it on function like

function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    }
    return "";
}

More advance write cookie methods:

function writeCookie(name,value,days) {
    var date, expires;
    if (days) {
        date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        expires = "; expires=" + date.toGMTString();
            }else{
        expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}

You should check this link

And this one

Community
  • 1
  • 1
jpganz18
  • 5,508
  • 17
  • 66
  • 115