Created
July 8, 2014 05:02
-
-
Save bboyle/2de854350aea5af6b97f to your computer and use it in GitHub Desktop.
Quick and dirty AB testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function( $ ) { | |
'use strict'; | |
// split traffic between this page and a B-variant | |
function ABredirect( path, weight, variationFunction ) { | |
path = path || '/index.html'; | |
weight = weight || 0.5; | |
// is this the B-variant? | |
if ( window.location.pathname.indexOf( path ) === -1 ) { | |
// A variant: redirect some traffic to B variant | |
if ( Math.random() < weight ) { | |
window.location.href = path; | |
} | |
} else { | |
// B variant: run function | |
if ( typeof variationFunction === 'function' ) { | |
// run onready | |
$( variationFunction ); | |
} | |
} | |
} | |
// redirect | |
ABredirect( '/homepage/index.html', 0.5, function() { | |
$( '.content-row.announcements', '#content' ) | |
.insertBefore( '#content .content-row.franchises' ) | |
.addClass( 'featured-news' ); | |
}); | |
}( jQuery )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment