Skip to content

Commit b0794a3

Browse files
committed
test download button label
1 parent 14243f5 commit b0794a3

1 file changed

Lines changed: 56 additions & 23 deletions

File tree

home.js

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,60 @@
1-
fetch('https://services.minbrowser.org/web-events/v1/collect', {
2-
method: 'post',
3-
headers: {
4-
'Content-Type': 'application/json'
5-
},
6-
body: JSON.stringify({
7-
os: getUserPlatform(),
8-
event: 'pageview',
9-
version: 'a'
10-
})
11-
})
1+
const variants = [
2+
['a', 0.8],
3+
['b', 0.2]
4+
]
5+
6+
let chosenVariant = ''
7+
let sum = 0
8+
let r = Math.random();
9+
for (let variant of variants) {
10+
sum += variant[1];
11+
if (r <= sum) {
12+
chosenVariant = variant[0]
13+
break
14+
}
15+
}
16+
17+
document.body.classList.add('variant-' + chosenVariant)
1218

13-
Array.from(document.querySelectorAll('.download-button')).forEach(function(button) {
14-
button.addEventListener('click', function() {
15-
fetch('https://services.minbrowser.org/web-events/v1/collect', {
16-
method: 'post',
17-
headers: {
18-
'Content-Type': 'application/json'
19-
},
20-
body: JSON.stringify({
21-
os: getUserPlatform(),
22-
event: 'downloadbutton',
23-
version: 'a'
19+
if (chosenVariant === 'b') {
20+
Array.from(document.querySelectorAll('.download-button .button-label')).forEach(function(label) {
21+
const platform = getUserPlatform()
22+
if (platform === 'mac') {
23+
label.textContent = 'Download for macOS';
24+
} else if (platform === 'windows') {
25+
label.textContent = 'Download for Windows';
26+
} else if (platform === 'linux') {
27+
label.textContent = 'Install for Linux';
28+
}
29+
});
30+
}
31+
32+
if (window.location.hostname === 'minbrowser.org') {
33+
fetch('https://services.minbrowser.org/web-events/v1/collect', {
34+
method: 'post',
35+
headers: {
36+
'Content-Type': 'application/json'
37+
},
38+
body: JSON.stringify({
39+
os: getUserPlatform(),
40+
event: 'pageview',
41+
version: chosenVariant,
42+
})
43+
})
44+
45+
Array.from(document.querySelectorAll('.download-button')).forEach(function(button) {
46+
button.addEventListener('click', function() {
47+
fetch('https://services.minbrowser.org/web-events/v1/collect', {
48+
method: 'post',
49+
headers: {
50+
'Content-Type': 'application/json'
51+
},
52+
body: JSON.stringify({
53+
os: getUserPlatform(),
54+
event: 'downloadbutton',
55+
version: chosenVariant
56+
})
2457
})
2558
})
2659
})
27-
})
60+
}

0 commit comments

Comments
 (0)