1
0
mirror of synced 2025-12-21 10:57:10 -05:00
Files
docs/components/lib/experiment.ts
Grace Park 8ba413cabc React Cleanup: Documentation (#20517)
* initial documentation changes

* editing layouts terminology

* update to match other files

* move javascripts to components/lib

* fix: dockerfile

* update based on Mikes updates to the javascripts directory

* update components/README.md

Co-authored-by: Mike Surowiec <mikesurowiec@users.noreply.github.com>
2021-07-27 09:07:18 -07:00

30 lines
826 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 () {
// *** 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)
}