Skip to content

Instantly share code, notes, and snippets.

@bmuller
Last active December 17, 2015 15:19
Show Gist options
  • Select an option

  • Save bmuller/5631082 to your computer and use it in GitHub Desktop.

Select an option

Save bmuller/5631082 to your computer and use it in GitHub Desktop.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Track conversion if user clicks (default)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<a class="opbandit" href="/some/video" data-conversion="click">
Click Here!
</a>
// or
<a class="opbandit" href="/some/video">
Click Here!
</a>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Track conversion only if (1) user clicks and then (2) in JS on another page you explicitly call conversion
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<a class="opbandit" href="/some/video" data-experiment-name="video url" data-conversion="click,explicit">
Click Here!
</a>
<script type="text/javascript">
BANDIT.convert("video url")
</script>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Track conversion if user shares (regardless of click)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<a class="opbandit" href="/some/video" data-conversion="share">
Click Here!
</a>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Specify new conversion event type
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BANDIT.newConversion("timeonsite", function(expname) {
// get first page load
var firstPageLoad = BANDIT.getCookie('first-page-load', new Date());
// set cookie if not set yet
BANDIT.setCookie('first-page-load', firstPageLoad);
var now = new Date();
// if user is on site for at least 5 minutes
if((now - firstPageLoad) > (60*60*5))
BANDIT.convert(expname);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment