1
0
mirror of synced 2025-12-20 10:28:40 -05:00
Files
docs/components/lib/experiment.ts
Kevin Heis dc952b9dcf Upgrade minor packages (#20960)
* Upgrade minor packages

* Add dockerfile syntax back

* Update create-processor.js

* Update create-processor.js
2021-08-19 12:57:39 -07:00

30 lines
836 B
TypeScript

import murmur from 'imurmurhash'
import { getUserEventsId, sendEvent, EventType } from './events'
const TREATMENT = 'TREATMENT'
const CONTROL = 'CONTROL'
export function bucket(test: string) {
const id = getUserEventsId()
const hash = murmur(test).hash(id).result()
return hash % 2 ? TREATMENT : CONTROL
}
export function sendSuccess(test: string) {
return sendEvent({
type: EventType.experiment,
experiment_name: test,
experiment_variation: bucket(test).toLowerCase(),
experiment_success: true,
})
}
export default function experiment() {
// *** 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)
}