Skip to content

Instantly share code, notes, and snippets.

@shankarps
Last active August 8, 2020 01:10
Show Gist options
  • Save shankarps/6dffaf3c98454fc73a21b93f2b67bcb2 to your computer and use it in GitHub Desktop.
Save shankarps/6dffaf3c98454fc73a21b93f2b67bcb2 to your computer and use it in GitHub Desktop.
Alephbet test code
<HTML>
<HEAD>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-GTAGID-1"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-GTAGID-1');
</script>
<script src="alephbet.min.js"></script>
<script>
$(document).ready(function() {
AlephBet.options.debug = true
var button_color_experiment = new AlephBet.Experiment({
name: 'button color', // the name of this experiment; required.
variants: { // variants for this experiment; required.
green: {
activate: function() { // activate function to execute if variant is selected
$('#my-btn').attr('style', 'color: green;');
console.log('activate blue');
}
},
red: {
activate: function() {
$('#my-btn').attr('style', 'color: red;');
console.log('activate red');
}
}
},
});
// creating a goal
var button_clicked_goal = new AlephBet.Goal('button clicked');
$('#my-btn').on('click', function() {
console.log('clicked button');
// The chosen variant will be tied to the goal automatically
button_clicked_goal.complete();
gtag('event', 'aaa', {
'event_category' : 'bbb',
'event_label' : 'ccc'
});
});
// adding experiment to the goal
button_clicked_goal.add_experiment(button_color_experiment);
// alternatively - add the goal to the experiment
//button_color_experiment.add_goal(button_clicked_goal);
// tracking non-unique goals, e.g. page views
var page_views = new AlephBet.Goal('page view', {unique: false});
});
</script>
<TITLE>Your Title Here</TITLE>
</HEAD>
<BODY BGCOLOR="FFFFFF" >
<button id="my-btn" > A/B Test </button>
</BODY>
</HTML>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment