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

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

Comments

Loading...