@funnelsgrove/runtime 0.1.33 → 0.1.34

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.
@@ -1,23 +1,48 @@
1
1
  import type { FunnelManifestExperiment } from './funnel.manifest.types.js';
2
- export type FunnelExperimentDefinition = {
2
+ export type FunnelExperimentStatus = 'draft' | 'running' | 'paused' | 'stopped';
3
+ export type FunnelRouteExperimentType = 'paywall' | 'step';
4
+ type FunnelExperimentBase = {
3
5
  id: string;
4
6
  name: string;
5
- type: 'paywall' | 'step';
6
- status?: 'running' | 'paused' | 'stopped';
7
+ status?: FunnelExperimentStatus;
7
8
  launchDate: string;
9
+ };
10
+ export type FunnelRouteExperimentDefinition = FunnelExperimentBase & {
11
+ type: FunnelRouteExperimentType;
12
+ stepId?: string;
8
13
  control: {
14
+ variantKey?: string;
9
15
  stepId: string;
10
16
  label?: string;
11
17
  trafficPercent: number;
12
18
  };
13
19
  variant: {
20
+ variantKey?: string;
14
21
  stepId: string;
15
22
  label?: string;
16
23
  trafficPercent: number;
17
24
  };
18
25
  };
19
- export type PaywallExperimentDefinition = FunnelExperimentDefinition & {
26
+ export type FunnelPricingExperimentDefinition = FunnelExperimentBase & {
27
+ type: 'pricing';
28
+ paywallStepId: string;
29
+ control: {
30
+ variantKey?: string;
31
+ offerSetKey: string;
32
+ label?: string;
33
+ trafficPercent: number;
34
+ };
35
+ variant: {
36
+ variantKey?: string;
37
+ offerSetKey: string;
38
+ label?: string;
39
+ trafficPercent: number;
40
+ };
41
+ };
42
+ export type FunnelExperimentDefinition = FunnelRouteExperimentDefinition | FunnelPricingExperimentDefinition;
43
+ export type PaywallExperimentDefinition = FunnelRouteExperimentDefinition & {
20
44
  type: 'paywall';
21
45
  };
22
46
  export declare const defineFunnelExperiments: <const T extends readonly FunnelExperimentDefinition[]>(experiments: T) => T;
23
47
  export declare const toManifestExperiments: (experiments: readonly FunnelExperimentDefinition[]) => FunnelManifestExperiment[];
48
+ export {};
@@ -11,9 +11,15 @@ export const toManifestExperiments = (experiments) => experiments
11
11
  .filter((experiment) => { var _a; return ((_a = experiment.status) !== null && _a !== void 0 ? _a : 'running') === 'running'; })
12
12
  .map((experiment) => ({
13
13
  experimentId: experiment.id,
14
- stepId: experiment.control.stepId,
14
+ stepId: experiment.type === 'pricing'
15
+ ? experiment.paywallStepId
16
+ : experiment.stepId || experiment.control.stepId,
15
17
  variants: [
16
- Object.assign(Object.assign({ variantKey: 'control' }, (experiment.control.label ? { label: experiment.control.label } : {})), { trafficPercent: experiment.control.trafficPercent, routeToStepId: experiment.control.stepId }),
17
- Object.assign(Object.assign({ variantKey: 'variant_b' }, (experiment.variant.label ? { label: experiment.variant.label } : {})), { trafficPercent: experiment.variant.trafficPercent, routeToStepId: experiment.variant.stepId }),
18
+ Object.assign(Object.assign({ variantKey: experiment.control.variantKey || 'control' }, (experiment.control.label ? { label: experiment.control.label } : {})), { trafficPercent: experiment.control.trafficPercent, routeToStepId: experiment.type === 'pricing'
19
+ ? experiment.paywallStepId
20
+ : experiment.control.stepId }),
21
+ Object.assign(Object.assign({ variantKey: experiment.variant.variantKey || 'variant_b' }, (experiment.variant.label ? { label: experiment.variant.label } : {})), { trafficPercent: experiment.variant.trafficPercent, routeToStepId: experiment.type === 'pricing'
22
+ ? experiment.paywallStepId
23
+ : experiment.variant.stepId }),
18
24
  ],
19
25
  }));
@@ -44,14 +44,15 @@ export const bootstrapPostHog = (config) => {
44
44
  bootstrap: { distinctID: config.distinctId },
45
45
  loaded: () => {
46
46
  const scopeProperties = buildFlagScopeProperties(config);
47
- if (Object.keys(scopeProperties).length > 0) {
48
- posthog.setPersonPropertiesForFlags(scopeProperties, false);
49
- }
50
47
  let unsubscribe = null;
51
48
  unsubscribe = posthog.onFeatureFlags(() => {
52
49
  unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe();
53
50
  markReady();
54
51
  });
52
+ if (Object.keys(scopeProperties).length > 0) {
53
+ posthog.setPersonPropertiesForFlags(scopeProperties, true);
54
+ return;
55
+ }
55
56
  posthog.reloadFeatureFlags();
56
57
  },
57
58
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/runtime",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",