Skip to content

Instantly share code, notes, and snippets.

@MaxPower15
Last active January 27, 2016 00:27
Show Gist options
  • Save MaxPower15/4019868 to your computer and use it in GitHub Desktop.
Save MaxPower15/4019868 to your computer and use it in GitHub Desktop.
Conditional A/B testing with Wistia's API embed
<!--
Steps to do A/B testing.
1. Pick any number of videos in your Wistia account. If they're in the same project, you can compare them in the Project View.
2. Get the hashed ID for each of them (this is the alphanumeric code after /medias/ in the URL bar).
3. Go into the Embed Builder for one of the videos, and grab an API embed code.
4. Change the id attribute in the API embed code to something legible. I renamed it to "thumbnail_test" below.
5. Add a `container` option to the embed code and specify your ID.
5. Modify the embed code to use a different hashed ID based on whatever conditions you want.
The code below chooses one hashed ID if they've come from an email (wemail is in the URL), and one of two others if not.
-->
<div id="thumbnail_test" class="wistia_embed" style="width:580px;height:353px;" data-video-width="580" data-video-height="326">&nbsp;</div>
<script charset="ISO-8859-1" src="http://fast.wistia.com/static/concat/E-v1%2Csocialbar-v1.js"></script>
<script>
var hashedIds = ["wfu7q0s0pf", "ck7avcilwk"];
var rand = Math.floor(Math.random() * hashedIds.length);
var hashedId, autoPlay = false;
if (/wemail=/.test(window.location.href)) {
hashedId = "i9owsigbsm";
autoPlay = true;
} else {
hashedId = hashedIds[rand];
}
wistiaEmbed = Wistia.embed(hashedId, {
container: "thumbnail_test",
autoPlay: autoPlay,
version: "v1",
videoWidth: 580,
videoHeight: 326,
volumeControl: true,
controlsVisibleOnLoad: true,
playerColor: "81b7db",
plugin: {
"socialbar-v1": {
buttons: "embed-twitter-facebook",
logo: true,
badgeUrl: "http://wistia.com",
badgeImage: "http://static.wistia.com/images/badges/wistia_100x96_black.png"
}
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment