-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
156 lines (139 loc) · 5.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ablab - sample</title>
<style>
.animation-experiment {
display: flex;
align-items: center;
width: 120px;
height: 48px;
border: 1px solid black;
}
.animation-experiment .animation-inner {
width: 32px;
height: 32px;
border: 1px solid black;
border-radius: 50%;
animation-name: slide;
animation-direction: alternate;
animation-iteration-count: infinite;
}
@keyframes slide {
from {
transform: translateX(0%);
}
to {
transform: translateX(86px);
}
}
</style>
</head>
<body>
<div class="uniqueId-container">
<input type="text" name="uniqueId-input" id="uniqueId-input" disabled>
<button id="uniqueId-button">Regenerate Id</button>
</div>
<div class="animation-experiment">
<div class="animation-inner"></div>
</div>
<div class="copy-experiment"></div>
<hr>
<div class="shipped-experiment"></div>
<script src="https://cdn.jsdelivr.net/npm/uuid@8.3.2/dist/umd/uuidv4.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ablab@0.0.5/dist/iife/ablab.min.js"></script>
<script>
// ablab stuff
const experimentConfig = {
"changing the button color": {
"variations": {
"treatment": {
"traffic": 50,
"data": {
"color": "yellow",
"textColor": "black"
}
},
"control": {
"traffic": 50,
"data": {
"color": "blue",
"textColor": "white"
}
}
}
},
"make the animation slower": {
"variations": {
"treatment": {
"traffic": 50,
"data": {
"speed": 2
}
},
"control": {
"traffic": 50,
"data": {
"speed": 0.5
}
}
}
},
"change the copy/text": {
"variations": {
"a": 33.33,
"b": 33.33,
"c": 33.33
}
},
// Represents an experiment that was successful
// and would later need to be cleaned up/promoted in code
"shipped flight/experiment": {
"variations": {
"treatment": 100,
"control": 0
}
}
};
const experimenter = ablab.createExperimenter(experimentConfig);
// dom elements
const uniqueIdTextInput = document.getElementById('uniqueId-input');
const uniqueIdRegenerateButton = document.getElementById('uniqueId-button');
const animationInnerDiv = document.querySelector('.animation-inner');
const copyDiv = document.querySelector('.copy-experiment');
const shippedDiv = document.querySelector('.shipped-experiment');
function bucket() {
uniqueIdTextInput.value = uuidv4();
const uniqueIdVariations = experimenter.getVariationsForUniqueId(uniqueIdTextInput.value);
console.log(uniqueIdVariations);
uniqueIdRegenerateButton.style.backgroundColor = uniqueIdVariations['changing the button color'].variationData.color;
uniqueIdRegenerateButton.style.color = uniqueIdVariations['changing the button color'].variationData.textColor;
animationInnerDiv.style.animationDuration = `${uniqueIdVariations['make the animation slower'].variationData.speed}s`;
switch (uniqueIdVariations['change the copy/text'].variationName) {
case 'b':
copyDiv.textContent = 'This is the copy for variant b.';
break;
case 'c':
copyDiv.textContent = 'This is the copy for variant c.';
break;
default:
copyDiv.textContent = 'This is the copy for variant a or the control.';
}
switch (uniqueIdVariations['shipped flight/experiment'].variationName) {
case 'treatment':
shippedDiv.textContent = "We are shipping this sweet copy, it shouldn't change no matter how many times we regenerate.";
break;
default:
shippedDiv.textContent = 'Uh oh! This variant should never be hit, check this shit out!';
}
}
function init() {
bucket();
uniqueIdRegenerateButton.addEventListener('click', bucket);
}
window.addEventListener('load', init);
</script>
</body>
</html>