@shiva004/surveys 0.10.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,8 @@ export interface WireEvent {
11
11
  user_id: string;
12
12
  session_id: string;
13
13
  properties: Record<string, unknown>;
14
+ /** Where the event came from: browser, OS, screen, timezone, network, plus your own fields (see IngestionConfig.context). */
15
+ context?: Record<string, unknown>;
14
16
  }
15
17
  export interface IngestEvent {
16
18
  id: string;
@@ -57,6 +59,10 @@ export interface IngestionConfig {
57
59
  maxPerSecond?: number;
58
60
  maxRetries?: number;
59
61
  source?: Source;
62
+ /** Extra fields added to every event's `context`, e.g. { app: 'portal', release: '1.4.2', env: 'uat' }. */
63
+ context?: Record<string, unknown>;
64
+ /** Add browser / OS / screen / timezone / network info to every event's `context`. Default true. Set false to switch off. */
65
+ device?: boolean;
60
66
  }
61
67
  export interface CaptureOptions {
62
68
  pageViews?: boolean;
@@ -0,0 +1,12 @@
1
+ export interface SnapshotOptions {
2
+ /** How often to report. Default 30000 (30 s). A report is also sent when the tab is hidden. */
3
+ intervalMs?: number;
4
+ /** Send environment_snapshot (browser, network, storage key counts). Default true. */
5
+ environment?: boolean;
6
+ /** Send heatmap_summary for pages that changed since the last report. Default true. */
7
+ heatmap?: boolean;
8
+ /** Also send public IP, ISP and location (only filled when the Environment panel's public lookup is on). Default false. */
9
+ includeIp?: boolean;
10
+ }
11
+ /** Start reporting. Returns a stop function. Call after startEventCapture({ endpoint }). */
12
+ export declare const startSnapshotReporting: (opts?: SnapshotOptions) => (() => void);
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import '../logs/logs.css';
3
+ import './experiments.css';
4
+ export interface ExperimentsAppProps {
5
+ /** Called by the "Open Live Events" link in the details panel. */
6
+ onOpenEvents?: () => void;
7
+ }
8
+ export declare const ExperimentsApp: React.FC<ExperimentsAppProps>;
@@ -0,0 +1,129 @@
1
+ export type ExperimentStatus = 'draft' | 'running' | 'paused' | 'completed';
2
+ export declare const EXPERIMENT_STATUSES: ExperimentStatus[];
3
+ export interface Variant {
4
+ key: string;
5
+ name: string;
6
+ weight: number;
7
+ }
8
+ export interface Assignment {
9
+ variant: string;
10
+ at: number;
11
+ converted: boolean;
12
+ value: number;
13
+ convertedAt?: number;
14
+ }
15
+ export interface Experiment {
16
+ id: string;
17
+ key: string;
18
+ name: string;
19
+ hypothesis?: string;
20
+ status: ExperimentStatus;
21
+ /** First variant is the control. Weights add up to 100. */
22
+ variants: Variant[];
23
+ /** Name of the event that counts as a conversion. */
24
+ goal: string;
25
+ /** Percent of users that take part (the rest get null from getVariant and see your default). */
26
+ traffic: number;
27
+ createdAt: number;
28
+ startedAt?: number;
29
+ endedAt?: number;
30
+ /** Variant shipped to everyone once the experiment is completed. */
31
+ winner?: string;
32
+ /** user id -> what that user saw and did. */
33
+ assigned: Record<string, Assignment>;
34
+ }
35
+ export interface ExperimentInput {
36
+ key: string;
37
+ name: string;
38
+ hypothesis?: string;
39
+ goal: string;
40
+ traffic?: number;
41
+ /** Default: control 50 / treatment 50. */
42
+ variants?: {
43
+ key: string;
44
+ name?: string;
45
+ weight: number;
46
+ }[];
47
+ }
48
+ export interface ExperimentsConfig {
49
+ /** localStorage key. Default "exp_experiments_v1". */
50
+ storageKey?: string;
51
+ /** Who is the current user. Default: the id of Live Events (identify()). */
52
+ userId?: () => string;
53
+ /** Users needed in every variant before a verdict is given. Default 100. */
54
+ minSample?: number;
55
+ /** Confidence for the significance test. Default 0.95. */
56
+ confidence?: number;
57
+ /** Users kept per experiment. Beyond it users still get a variant but are not counted. Default 5000. */
58
+ maxUsers?: number;
59
+ onExposure?: (e: Experiment, variant: string, userId: string) => void;
60
+ onConversion?: (e: Experiment, variant: string, userId: string, value: number) => void;
61
+ onStatusChange?: (e: Experiment, status: ExperimentStatus) => void;
62
+ }
63
+ export type Outcome<T> = {
64
+ ok: true;
65
+ value: T;
66
+ } | {
67
+ ok: false;
68
+ error: string;
69
+ };
70
+ export declare const EXPERIMENT_KEY_RE: RegExp;
71
+ export declare const VARIANT_KEY_RE: RegExp;
72
+ export declare const useExperiments: () => {
73
+ experiments: Experiment[];
74
+ };
75
+ export declare const getExperiments: () => Experiment[];
76
+ export declare const getExperiment: (key: string) => Experiment | undefined;
77
+ export declare const configureExperiments: (c: ExperimentsConfig) => void;
78
+ /** A stable number in [0, 100) for this experiment, user and purpose. */
79
+ export declare const experimentBucket: (key: string, userId: string, salt: "traffic" | "variant") => number;
80
+ /** Which variant would this user get? Records nothing, safe to call while rendering. */
81
+ export declare const peekVariant: (key: string, userId?: string) => string | null;
82
+ /** The variant for this user. The first call per user also records the exposure. Returns null when the user is not in the experiment. */
83
+ export declare const getVariant: (key: string, userId?: string) => string | null;
84
+ /** React hook: the variant for the current user, recording the exposure after render. */
85
+ export declare const useVariant: (key: string, userId?: string) => string | null;
86
+ /** Count a conversion for a user who saw the experiment. A user converts once; later calls only add to the value (revenue). */
87
+ export declare const trackConversion: (key: string, value?: number, userId?: string) => boolean;
88
+ /** Turns events named like an experiment's goal into conversions. Call once at start-up. Returns a stop function. */
89
+ export declare const startLocalExperiments: () => (() => void);
90
+ export declare const createExperiment: (input: ExperimentInput) => Outcome<Experiment>;
91
+ export declare const startExperiment: (key: string) => boolean;
92
+ export declare const pauseExperiment: (key: string) => boolean;
93
+ /** Ends the experiment. With a winner, getVariant() returns that variant to everyone from now on (ship it). */
94
+ export declare const stopExperiment: (key: string, winner?: string) => boolean;
95
+ /** Forget every user and conversion. Only for a draft or paused experiment. */
96
+ export declare const resetExperimentResults: (key: string) => boolean;
97
+ export declare const deleteExperiment: (key: string) => void;
98
+ export declare const clearExperiments: () => void;
99
+ /** Two-sided p-value of "these two conversion rates are really different" (pooled two-proportion z-test). null when it cannot be computed. */
100
+ export declare const twoProportionP: (c1: number, n1: number, c2: number, n2: number) => number | null;
101
+ export interface VariantResult {
102
+ key: string;
103
+ name: string;
104
+ control: boolean;
105
+ weight: number;
106
+ exposures: number;
107
+ conversions: number;
108
+ value: number;
109
+ /** Conversions per exposed user, 0 to 1. null before the first exposure. */
110
+ rate: number | null;
111
+ /** Relative change of the rate against the control, 0.1 = 10 % better. null for the control or without data. */
112
+ lift: number | null;
113
+ pValue: number | null;
114
+ /** The difference to the control is real (p below 1 - confidence, corrected for the number of variants). */
115
+ significant: boolean;
116
+ }
117
+ export type Verdict = 'no_data' | 'collecting' | 'winner' | 'control_better' | 'inconclusive';
118
+ export interface ExperimentResults {
119
+ variants: VariantResult[];
120
+ exposures: number;
121
+ conversions: number;
122
+ verdict: Verdict;
123
+ /** The variant the data supports shipping, when the verdict is winner / control_better. */
124
+ suggested?: string;
125
+ message: string;
126
+ /** Users still missing in the smallest variant before a verdict. */
127
+ missing: number;
128
+ }
129
+ export declare const resultsOf: (e: Experiment) => ExperimentResults;
package/dist/index.d.ts CHANGED
@@ -10,6 +10,8 @@ export { getNetworkInfo, setNetworkName, refreshNetwork, setPublicLookup, isPubl
10
10
  export { HeatmapApp } from './heatmap/HeatmapApp';
11
11
  export { IngestionApp } from './events/IngestionApp';
12
12
  export { startEventCapture, trackEvent, ingestRemote, identify, getUserId, configureIngestion, useIngestion, getIngestionSnapshot, setPaused as setIngestionPaused, resetIngestion, } from './events/data';
13
+ export { startSnapshotReporting } from './events/snapshots';
14
+ export type { SnapshotOptions } from './events/snapshots';
13
15
  export type { IngestionConfig, CaptureOptions, RemoteEvent, WireEvent, IngestEvent, IngestStatus } from './events/data';
14
16
  export { FlagsApp } from './flags/FlagsApp';
15
17
  export type { FlagsAppProps } from './flags/FlagsApp';
@@ -55,6 +57,14 @@ export type { Mock, MockInput, MockHit, MockApiConfig, MockApiConnection, Method
55
57
  export { startHeatmapCapture, clearHeatmap, getHeatmapData } from './heatmap/capture';
56
58
  export { start as startSessionReplay, stop as stopSessionReplay, useRecorder } from './recorder/recorder';
57
59
  export type { RecMeta, RecNet, RecStore, RecForm, RecLog } from './recorder/recorder';
60
+ export { ExperimentsApp } from './experiments/ExperimentsApp';
61
+ export type { ExperimentsAppProps } from './experiments/ExperimentsApp';
62
+ export { configureExperiments, createExperiment, startExperiment, pauseExperiment, stopExperiment, resetExperimentResults, deleteExperiment, clearExperiments, getVariant, peekVariant, useVariant, trackConversion, useExperiments, getExperiments, getExperiment, resultsOf as experimentResults, twoProportionP, startLocalExperiments, } from './experiments/data';
63
+ export type { Experiment, ExperimentInput, ExperimentStatus, ExperimentsConfig, ExperimentResults, Variant as ExperimentVariant, VariantResult as ExperimentVariantResult, Verdict as ExperimentVerdict } from './experiments/data';
64
+ export { MonitoringApp } from './monitoring/MonitoringApp';
65
+ export type { MonitoringAppProps } from './monitoring/MonitoringApp';
66
+ export { configureMonitoring, addCheck, updateCheck, toggleCheck, removeCheck, clearCheckHistory, clearChecks, runCheck, runAllChecks, probe, useMonitoring, getChecks, getCheck, getIncidents, statusOf as checkStatus, statsOf as checkStats, startLocalMonitoring, } from './monitoring/data';
67
+ export type { Check, CheckInput, CheckResult, CheckStatus, CheckStats, Incident, MonitoringConfig, ProbeOptions } from './monitoring/data';
58
68
  export { RouteRecorderWatcher } from './recorder/RouteRecorderWatcher';
59
69
  export type { RouteRecorderWatcherProps } from './recorder/RouteRecorderWatcher';
60
70
  export type { AppProps } from './App';