1
0
mirror of synced 2025-12-22 19:34:15 -05:00
Files
docs/components/lib/experiment.ts
Kevin Heis 688a274f1f Remove CSRF check (#29910)
* Use color_mode for gating "sign up" button

* Remove csrf check

* Add `res.removeHeader('set-cookie')` to cache-control

* Update static-assets.js

* Remove package

* Remove tough-cookie

* Update cache-control.js

* Update cache-control.js

* Update cache-control.js
2022-08-15 19:28:42 +00:00

34 lines
911 B
TypeScript

import murmur from 'imurmurhash'
import { getUserEventsId, sendEvent, EventType } from './events'
let initialized = false
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 function initializeExperiments() {
if (initialized) return
initialized = true
// *** 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)
}