Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

experiment.js 825 B

You have to be logged in to leave a comment. Sign In
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
  1. import murmur from 'imurmurhash'
  2. import { getUserEventsId, sendEvent } from './events'
  3. // import h from './hyperscript'
  4. const TREATMENT = 'TREATMENT'
  5. const CONTROL = 'CONTROL'
  6. export function bucket (test) {
  7. const id = getUserEventsId()
  8. const hash = murmur(test).hash(id).result()
  9. return hash % 2 ? TREATMENT : CONTROL
  10. }
  11. export function sendSuccess (test) {
  12. return sendEvent({
  13. type: 'experiment',
  14. experiment_name: test,
  15. experiment_variation: bucket(test).toLowerCase(),
  16. experiment_success: true
  17. })
  18. }
  19. export default function () {
  20. // *** Example test code ***
  21. // const testName = '$test-name$'
  22. // const xbucket = bucket(testName)
  23. // const x = document.querySelector(...)
  24. // x.addEventListener('click', () => { sendSuccess(testName) })
  25. // if (xbucket === TREATMENT) applyTreatment(x)
  26. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...