1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/javascripts/experiment.js
Kevin Heis 912ac50034 End AB test on moving helpfulness prompt to bottom (#16552)
* End AB test on moving helpfulness prompt to bottom

* Move helpfulness to bottom of page only

* Update helpfulness.js

Co-authored-by: Chiedo John <2156688+chiedo@users.noreply.github.com>
2020-11-20 12:24:33 -08:00

45 lines
1.2 KiB
JavaScript

import murmur from 'imurmurhash'
import { getUserEventsId, sendEvent } from './events'
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 async function sendSuccess (test) {
return sendEvent({
type: 'experiment',
experiment_name: test,
experiment_variation: bucket(test).toLowerCase(),
experiment_success: true
})
}
const xmlns = 'http://www.w3.org/2000/svg'
export function h (tagName, attributes = {}, children = []) {
const el = ['svg', 'path'].includes(tagName)
? document.createElementNS(xmlns, tagName)
: document.createElement(tagName)
Object.entries(attributes).forEach(
([key, value]) => el.setAttribute(key, value)
)
children.forEach(child =>
typeof child === 'string'
? el.append(document.createTextNode(child))
: el.append(child)
)
return el
}
export default function () {
// const testName = '$test-name$'
// const xbucket = bucket(testName)
// if (xbucket === TREATMENT) { ... }
// x.addEventListener('click', () => { sendSuccess(testName) })
}