@contractspec/lib.analytics 1.57.0 → 1.58.0

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.
Files changed (89) hide show
  1. package/dist/browser/churn/index.js +77 -0
  2. package/dist/browser/churn/predictor.js +77 -0
  3. package/dist/browser/cohort/index.js +117 -0
  4. package/dist/browser/cohort/tracker.js +117 -0
  5. package/dist/browser/funnel/analyzer.js +68 -0
  6. package/dist/browser/funnel/index.js +68 -0
  7. package/dist/browser/growth/hypothesis-generator.js +46 -0
  8. package/dist/browser/growth/index.js +46 -0
  9. package/dist/browser/index.js +723 -0
  10. package/dist/browser/lifecycle/index.js +287 -0
  11. package/dist/browser/lifecycle/metric-collectors.js +58 -0
  12. package/dist/browser/lifecycle/posthog-bridge.js +79 -0
  13. package/dist/browser/lifecycle/posthog-metric-source.js +205 -0
  14. package/dist/browser/posthog/event-source.js +138 -0
  15. package/dist/browser/posthog/index.js +138 -0
  16. package/dist/browser/types.js +0 -0
  17. package/dist/churn/index.d.ts +2 -2
  18. package/dist/churn/index.d.ts.map +1 -0
  19. package/dist/churn/index.js +77 -2
  20. package/dist/churn/predictor.d.ts +15 -19
  21. package/dist/churn/predictor.d.ts.map +1 -1
  22. package/dist/churn/predictor.js +72 -68
  23. package/dist/cohort/index.d.ts +2 -2
  24. package/dist/cohort/index.d.ts.map +1 -0
  25. package/dist/cohort/index.js +117 -2
  26. package/dist/cohort/tracker.d.ts +3 -7
  27. package/dist/cohort/tracker.d.ts.map +1 -1
  28. package/dist/cohort/tracker.js +106 -87
  29. package/dist/funnel/analyzer.d.ts +4 -8
  30. package/dist/funnel/analyzer.d.ts.map +1 -1
  31. package/dist/funnel/analyzer.js +67 -62
  32. package/dist/funnel/index.d.ts +2 -2
  33. package/dist/funnel/index.d.ts.map +1 -0
  34. package/dist/funnel/index.js +69 -3
  35. package/dist/growth/hypothesis-generator.d.ts +11 -15
  36. package/dist/growth/hypothesis-generator.d.ts.map +1 -1
  37. package/dist/growth/hypothesis-generator.js +46 -39
  38. package/dist/growth/index.d.ts +2 -2
  39. package/dist/growth/index.d.ts.map +1 -0
  40. package/dist/growth/index.js +47 -3
  41. package/dist/index.d.ts +8 -10
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +724 -12
  44. package/dist/lifecycle/index.d.ts +4 -4
  45. package/dist/lifecycle/index.d.ts.map +1 -0
  46. package/dist/lifecycle/index.js +287 -4
  47. package/dist/lifecycle/metric-collectors.d.ts +22 -26
  48. package/dist/lifecycle/metric-collectors.d.ts.map +1 -1
  49. package/dist/lifecycle/metric-collectors.js +55 -44
  50. package/dist/lifecycle/posthog-bridge.d.ts +9 -13
  51. package/dist/lifecycle/posthog-bridge.d.ts.map +1 -1
  52. package/dist/lifecycle/posthog-bridge.js +77 -25
  53. package/dist/lifecycle/posthog-metric-source.d.ts +40 -44
  54. package/dist/lifecycle/posthog-metric-source.d.ts.map +1 -1
  55. package/dist/lifecycle/posthog-metric-source.js +200 -180
  56. package/dist/node/churn/index.js +77 -0
  57. package/dist/node/churn/predictor.js +77 -0
  58. package/dist/node/cohort/index.js +117 -0
  59. package/dist/node/cohort/tracker.js +117 -0
  60. package/dist/node/funnel/analyzer.js +68 -0
  61. package/dist/node/funnel/index.js +68 -0
  62. package/dist/node/growth/hypothesis-generator.js +46 -0
  63. package/dist/node/growth/index.js +46 -0
  64. package/dist/node/index.js +723 -0
  65. package/dist/node/lifecycle/index.js +287 -0
  66. package/dist/node/lifecycle/metric-collectors.js +58 -0
  67. package/dist/node/lifecycle/posthog-bridge.js +79 -0
  68. package/dist/node/lifecycle/posthog-metric-source.js +205 -0
  69. package/dist/node/posthog/event-source.js +138 -0
  70. package/dist/node/posthog/index.js +138 -0
  71. package/dist/node/types.js +0 -0
  72. package/dist/posthog/event-source.d.ts +18 -22
  73. package/dist/posthog/event-source.d.ts.map +1 -1
  74. package/dist/posthog/event-source.js +131 -111
  75. package/dist/posthog/index.d.ts +2 -2
  76. package/dist/posthog/index.d.ts.map +1 -0
  77. package/dist/posthog/index.js +139 -3
  78. package/dist/types.d.ts +52 -55
  79. package/dist/types.d.ts.map +1 -1
  80. package/dist/types.js +1 -0
  81. package/package.json +189 -46
  82. package/dist/churn/predictor.js.map +0 -1
  83. package/dist/cohort/tracker.js.map +0 -1
  84. package/dist/funnel/analyzer.js.map +0 -1
  85. package/dist/growth/hypothesis-generator.js.map +0 -1
  86. package/dist/lifecycle/metric-collectors.js.map +0 -1
  87. package/dist/lifecycle/posthog-bridge.js.map +0 -1
  88. package/dist/lifecycle/posthog-metric-source.js.map +0 -1
  89. package/dist/posthog/event-source.js.map +0 -1
@@ -1,40 +1,47 @@
1
- //#region src/growth/hypothesis-generator.ts
2
- var GrowthHypothesisGenerator = class {
3
- minDelta;
4
- constructor(options) {
5
- this.minDelta = options?.minDelta ?? .05;
6
- }
7
- generate(metrics) {
8
- return metrics.map((metric) => this.fromMetric(metric)).filter((hypothesis) => Boolean(hypothesis));
9
- }
10
- fromMetric(metric) {
11
- const change = this.delta(metric);
12
- if (Math.abs(change) < this.minDelta) return null;
13
- const direction = change > 0 ? "rising" : "declining";
14
- return {
15
- statement: this.statement(metric, change, direction),
16
- metric: metric.name,
17
- confidence: Math.abs(change) > .2 ? "high" : "medium",
18
- impact: this.impact(metric)
19
- };
20
- }
21
- delta(metric) {
22
- if (metric.previous == null) return 0;
23
- const prev = metric.previous || 1;
24
- return (metric.current - prev) / Math.abs(prev);
25
- }
26
- impact(metric) {
27
- if (metric.target && metric.current < metric.target * .8) return "high";
28
- if (metric.target && metric.current < metric.target) return "medium";
29
- return "low";
30
- }
31
- statement(metric, change, direction) {
32
- const percent = Math.abs(parseFloat((change * 100).toFixed(1)));
33
- if (direction === "declining") return `${metric.name} is down ${percent}% vs last period; test new onboarding prompts to recover activation.`;
34
- return `${metric.name} grew ${percent}% period-over-period; double down with expanded experiment or pricing test.`;
35
- }
1
+ // @bun
2
+ // src/growth/hypothesis-generator.ts
3
+ class GrowthHypothesisGenerator {
4
+ minDelta;
5
+ constructor(options) {
6
+ this.minDelta = options?.minDelta ?? 0.05;
7
+ }
8
+ generate(metrics) {
9
+ return metrics.map((metric) => this.fromMetric(metric)).filter((hypothesis) => Boolean(hypothesis));
10
+ }
11
+ fromMetric(metric) {
12
+ const change = this.delta(metric);
13
+ if (Math.abs(change) < this.minDelta)
14
+ return null;
15
+ const direction = change > 0 ? "rising" : "declining";
16
+ const statement = this.statement(metric, change, direction);
17
+ return {
18
+ statement,
19
+ metric: metric.name,
20
+ confidence: Math.abs(change) > 0.2 ? "high" : "medium",
21
+ impact: this.impact(metric)
22
+ };
23
+ }
24
+ delta(metric) {
25
+ if (metric.previous == null)
26
+ return 0;
27
+ const prev = metric.previous || 1;
28
+ return (metric.current - prev) / Math.abs(prev);
29
+ }
30
+ impact(metric) {
31
+ if (metric.target && metric.current < metric.target * 0.8)
32
+ return "high";
33
+ if (metric.target && metric.current < metric.target)
34
+ return "medium";
35
+ return "low";
36
+ }
37
+ statement(metric, change, direction) {
38
+ const percent = Math.abs(parseFloat((change * 100).toFixed(1)));
39
+ if (direction === "declining") {
40
+ return `${metric.name} is down ${percent}% vs last period; test new onboarding prompts to recover activation.`;
41
+ }
42
+ return `${metric.name} grew ${percent}% period-over-period; double down with expanded experiment or pricing test.`;
43
+ }
44
+ }
45
+ export {
46
+ GrowthHypothesisGenerator
36
47
  };
37
-
38
- //#endregion
39
- export { GrowthHypothesisGenerator };
40
- //# sourceMappingURL=hypothesis-generator.js.map
@@ -1,2 +1,2 @@
1
- import { GrowthHypothesisGenerator, HypothesisGeneratorOptions } from "./hypothesis-generator.js";
2
- export { GrowthHypothesisGenerator, HypothesisGeneratorOptions };
1
+ export * from './hypothesis-generator';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/growth/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
@@ -1,3 +1,47 @@
1
- import { GrowthHypothesisGenerator } from "./hypothesis-generator.js";
2
-
3
- export { GrowthHypothesisGenerator };
1
+ // @bun
2
+ // src/growth/hypothesis-generator.ts
3
+ class GrowthHypothesisGenerator {
4
+ minDelta;
5
+ constructor(options) {
6
+ this.minDelta = options?.minDelta ?? 0.05;
7
+ }
8
+ generate(metrics) {
9
+ return metrics.map((metric) => this.fromMetric(metric)).filter((hypothesis) => Boolean(hypothesis));
10
+ }
11
+ fromMetric(metric) {
12
+ const change = this.delta(metric);
13
+ if (Math.abs(change) < this.minDelta)
14
+ return null;
15
+ const direction = change > 0 ? "rising" : "declining";
16
+ const statement = this.statement(metric, change, direction);
17
+ return {
18
+ statement,
19
+ metric: metric.name,
20
+ confidence: Math.abs(change) > 0.2 ? "high" : "medium",
21
+ impact: this.impact(metric)
22
+ };
23
+ }
24
+ delta(metric) {
25
+ if (metric.previous == null)
26
+ return 0;
27
+ const prev = metric.previous || 1;
28
+ return (metric.current - prev) / Math.abs(prev);
29
+ }
30
+ impact(metric) {
31
+ if (metric.target && metric.current < metric.target * 0.8)
32
+ return "high";
33
+ if (metric.target && metric.current < metric.target)
34
+ return "medium";
35
+ return "low";
36
+ }
37
+ statement(metric, change, direction) {
38
+ const percent = Math.abs(parseFloat((change * 100).toFixed(1)));
39
+ if (direction === "declining") {
40
+ return `${metric.name} is down ${percent}% vs last period; test new onboarding prompts to recover activation.`;
41
+ }
42
+ return `${metric.name} grew ${percent}% period-over-period; double down with expanded experiment or pricing test.`;
43
+ }
44
+ }
45
+ export {
46
+ GrowthHypothesisGenerator
47
+ };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,8 @@
1
- import { AnalyticsEvent, ChurnSignal, CohortAnalysis, CohortDefinition, CohortEvent, CohortStats, FunnelAnalysis, FunnelDefinition, FunnelStep, FunnelStepResult, GrowthHypothesis, GrowthMetric } from "./types.js";
2
- import { ChurnPredictor, ChurnPredictorOptions } from "./churn/predictor.js";
3
- import { CohortTracker } from "./cohort/tracker.js";
4
- import { FunnelAnalyzer } from "./funnel/analyzer.js";
5
- import { GrowthHypothesisGenerator, HypothesisGeneratorOptions } from "./growth/hypothesis-generator.js";
6
- import { LifecycleMetricSource, LifecycleStageChangePayload, collectLifecycleMetrics, createStageChangeEvent, lifecycleEventNames, metricsToSignals } from "./lifecycle/metric-collectors.js";
7
- import { PostHogLikeClient, trackLifecycleAssessment, trackLifecycleStageChange } from "./lifecycle/posthog-bridge.js";
8
- import { PosthogLifecycleMetricSource, PosthogLifecycleMetricSourceOptions } from "./lifecycle/posthog-metric-source.js";
9
- import { PosthogAnalyticsEventSource, PosthogAnalyticsEventSourceOptions } from "./posthog/event-source.js";
10
- export { AnalyticsEvent, ChurnPredictor, ChurnPredictorOptions, ChurnSignal, CohortAnalysis, CohortDefinition, CohortEvent, CohortStats, CohortTracker, FunnelAnalysis, FunnelAnalyzer, FunnelDefinition, FunnelStep, FunnelStepResult, GrowthHypothesis, GrowthHypothesisGenerator, GrowthMetric, HypothesisGeneratorOptions, LifecycleMetricSource, LifecycleStageChangePayload, PostHogLikeClient, PosthogAnalyticsEventSource, PosthogAnalyticsEventSourceOptions, PosthogLifecycleMetricSource, PosthogLifecycleMetricSourceOptions, collectLifecycleMetrics, createStageChangeEvent, lifecycleEventNames, metricsToSignals, trackLifecycleAssessment, trackLifecycleStageChange };
1
+ export * from './types';
2
+ export * from './funnel';
3
+ export * from './cohort';
4
+ export * from './churn';
5
+ export * from './growth';
6
+ export * from './lifecycle';
7
+ export * from './posthog';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}