forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperiment.js
30 lines (26 loc) · 825 Bytes
/
experiment.js
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
import murmur from 'imurmurhash'
import { getUserEventsId, sendEvent } from './events'
// import h from './hyperscript'
const TREATMENT = 'TREATMENT'
const CONTROL = 'CONTROL'
export function bucket (test) {
const id = getUserEventsId()
const hash = murmur(test).hash(id).result()
return hash % 2 ? TREATMENT : CONTROL
}
export function sendSuccess (test) {
return sendEvent({
type: 'experiment',
experiment_name: test,
experiment_variation: bucket(test).toLowerCase(),
experiment_success: true
})
}
export default function () {
// *** Example test code ***
// const testName = '$test-name$'
// const xbucket = bucket(testName)
// const x = document.querySelector(...)
// x.addEventListener('click', () => { sendSuccess(testName) })
// if (xbucket === TREATMENT) applyTreatment(x)
}