flowgrid-sdk 1.0.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.
- package/LICENSE +21 -0
- package/dist/browser.d.ts +119 -0
- package/dist/flowgrid.min.js +2 -0
- package/dist/flowgrid.min.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/client/enterprise-ftrpc.d.ts +51 -0
- package/dist/lib/client/ftrpc.d.ts +43 -0
- package/dist/lib/client/modules.d.ts +104 -0
- package/dist/lib/features/analytics/attribution.d.ts +257 -0
- package/dist/lib/features/analytics/events.d.ts +304 -0
- package/dist/lib/features/analytics/funnels.d.ts +291 -0
- package/dist/lib/features/analytics/heatmaps.d.ts +247 -0
- package/dist/lib/features/analytics/identify.d.ts +273 -0
- package/dist/lib/features/analytics/index.d.ts +22 -0
- package/dist/lib/features/analytics/page-views.d.ts +250 -0
- package/dist/lib/features/analytics/performance.d.ts +281 -0
- package/dist/lib/features/analytics/retention.d.ts +294 -0
- package/dist/lib/features/analytics/sessions.d.ts +277 -0
- package/dist/lib/features/core/activation.d.ts +239 -0
- package/dist/lib/features/core/experiment.d.ts +286 -0
- package/dist/lib/features/core/feature-flag.d.ts +264 -0
- package/dist/lib/features/core/index.d.ts +14 -0
- package/dist/lib/features/core/track-feature.d.ts +220 -0
- package/dist/lib/features/core/track-prompt.d.ts +247 -0
- package/dist/lib/features/ecommerce/cart.d.ts +298 -0
- package/dist/lib/features/ecommerce/checkout.d.ts +324 -0
- package/dist/lib/features/ecommerce/index.d.ts +26 -0
- package/dist/lib/features/ecommerce/inventory.d.ts +221 -0
- package/dist/lib/features/ecommerce/ltv.d.ts +258 -0
- package/dist/lib/features/ecommerce/products.d.ts +268 -0
- package/dist/lib/features/ecommerce/promotions.d.ts +266 -0
- package/dist/lib/features/ecommerce/purchases.d.ts +287 -0
- package/dist/lib/features/ecommerce/refunds.d.ts +232 -0
- package/dist/lib/features/ecommerce/search.d.ts +225 -0
- package/dist/lib/features/ecommerce/subscriptions.d.ts +281 -0
- package/dist/lib/features/ecommerce/wishlist.d.ts +236 -0
- package/dist/lib/features/enterprise/acquisition.d.ts +373 -0
- package/dist/lib/features/enterprise/alerts.d.ts +348 -0
- package/dist/lib/features/enterprise/churn.d.ts +288 -0
- package/dist/lib/features/enterprise/cohorts.d.ts +270 -0
- package/dist/lib/features/enterprise/engagement.d.ts +233 -0
- package/dist/lib/features/enterprise/forecasting.d.ts +351 -0
- package/dist/lib/features/enterprise/index.d.ts +20 -0
- package/dist/lib/features/enterprise/monetization.d.ts +356 -0
- package/dist/lib/features/enterprise/multi-path-funnels.d.ts +327 -0
- package/dist/lib/features/enterprise/paths.d.ts +332 -0
- package/dist/lib/features/enterprise/security.d.ts +387 -0
- package/dist/lib/features/enterprise/support.d.ts +329 -0
- package/dist/lib/frameworks/index.d.ts +9 -0
- package/dist/lib/frameworks/nextjs/client.d.ts +208 -0
- package/dist/lib/frameworks/nextjs/index.d.ts +29 -0
- package/dist/lib/frameworks/nextjs/server.d.ts +201 -0
- package/dist/lib/frameworks/node/index.d.ts +265 -0
- package/dist/lib/frameworks/nuxt/index.d.ts +190 -0
- package/dist/lib/frameworks/react/index.d.ts +245 -0
- package/dist/lib/frameworks/vue/index.d.ts +275 -0
- package/dist/lib/types/analytics.d.ts +365 -0
- package/dist/lib/types/common.d.ts +230 -0
- package/dist/lib/types/ecommerce.d.ts +309 -0
- package/dist/lib/types/index.d.ts +7 -0
- package/dist/lib/utils/functions.d.ts +1 -0
- package/package.json +139 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Enterprise - Churn & Predictive Analytics
|
|
3
|
+
* @module features/enterprise/churn
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Predict and measure churn proactively using usage patterns,
|
|
7
|
+
* engagement signals, and predictive scoring models.
|
|
8
|
+
*
|
|
9
|
+
* @useCases
|
|
10
|
+
* - Detect usage decay patterns
|
|
11
|
+
* - Identify at-risk users
|
|
12
|
+
* - Predict churn probability
|
|
13
|
+
* - Correlate NPS with churn
|
|
14
|
+
* - Track churn prevention success
|
|
15
|
+
*
|
|
16
|
+
* @metrics
|
|
17
|
+
* - Churn rate
|
|
18
|
+
* - Churn risk score
|
|
19
|
+
* - Days to churn prediction
|
|
20
|
+
* - At-risk user count
|
|
21
|
+
* - Prevention success rate
|
|
22
|
+
*
|
|
23
|
+
* @chartData
|
|
24
|
+
* - Line chart: Churn rate over time
|
|
25
|
+
* - Distribution: Risk score distribution
|
|
26
|
+
* - Bar chart: Churn by segment
|
|
27
|
+
* - Funnel: Churn prevention funnel
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const churn = new ChurnAnalytics(webId, endpoint, apiKey);
|
|
32
|
+
*
|
|
33
|
+
* // Get user churn risk
|
|
34
|
+
* const risk = await churn.getUserRiskScore('user_123');
|
|
35
|
+
*
|
|
36
|
+
* // Get at-risk users
|
|
37
|
+
* const atRisk = await churn.getAtRiskUsers({ minScore: 70 });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
import { EnterpriseFTRPC } from "../../client/enterprise-ftrpc";
|
|
41
|
+
import { DateRangeFilter, TimeSeriesData, TimeGranularity } from "../../types";
|
|
42
|
+
/**
|
|
43
|
+
* Churn risk factors.
|
|
44
|
+
*/
|
|
45
|
+
export interface ChurnRiskFactors {
|
|
46
|
+
/** Days since last activity */
|
|
47
|
+
daysSinceLastActivity: number;
|
|
48
|
+
/** Usage trend (negative = declining) */
|
|
49
|
+
usageTrend: number;
|
|
50
|
+
/** Session frequency change */
|
|
51
|
+
sessionFrequencyChange: number;
|
|
52
|
+
/** Feature usage breadth change */
|
|
53
|
+
featureUsageChange: number;
|
|
54
|
+
/** Support tickets opened */
|
|
55
|
+
supportTickets: number;
|
|
56
|
+
/** NPS score (if available) */
|
|
57
|
+
npsScore?: number;
|
|
58
|
+
/** Payment failures */
|
|
59
|
+
paymentFailures: number;
|
|
60
|
+
/** Contract/subscription end approaching */
|
|
61
|
+
daysUntilRenewal?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Churn risk score result.
|
|
65
|
+
*/
|
|
66
|
+
export interface ChurnRiskScore {
|
|
67
|
+
/** User ID */
|
|
68
|
+
userId: string;
|
|
69
|
+
/** Risk score (0-100, higher = more likely to churn) */
|
|
70
|
+
score: number;
|
|
71
|
+
/** Risk level classification */
|
|
72
|
+
riskLevel: 'low' | 'medium' | 'high' | 'critical';
|
|
73
|
+
/** Predicted days until churn */
|
|
74
|
+
predictedDaysToChurn?: number;
|
|
75
|
+
/** Top contributing factors */
|
|
76
|
+
topFactors: Array<{
|
|
77
|
+
factor: string;
|
|
78
|
+
contribution: number;
|
|
79
|
+
value: unknown;
|
|
80
|
+
}>;
|
|
81
|
+
/** Recommended actions */
|
|
82
|
+
recommendations: string[];
|
|
83
|
+
/** Last updated */
|
|
84
|
+
updatedAt: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Usage decay configuration.
|
|
88
|
+
*/
|
|
89
|
+
export interface UsageDecayConfig {
|
|
90
|
+
/** User ID */
|
|
91
|
+
userId: string;
|
|
92
|
+
/** Metric to track decay */
|
|
93
|
+
metric: 'sessions' | 'events' | 'features' | 'time_spent';
|
|
94
|
+
/** Comparison periods */
|
|
95
|
+
periods: {
|
|
96
|
+
current: DateRangeFilter;
|
|
97
|
+
previous: DateRangeFilter;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Usage decay result.
|
|
102
|
+
*/
|
|
103
|
+
export interface UsageDecay {
|
|
104
|
+
userId: string;
|
|
105
|
+
metric: string;
|
|
106
|
+
currentValue: number;
|
|
107
|
+
previousValue: number;
|
|
108
|
+
changePercent: number;
|
|
109
|
+
isDecaying: boolean;
|
|
110
|
+
decayRate: number;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* NPS tracking configuration.
|
|
114
|
+
*/
|
|
115
|
+
export interface NPSConfig {
|
|
116
|
+
/** User ID */
|
|
117
|
+
userId: string;
|
|
118
|
+
/** NPS score (0-10) */
|
|
119
|
+
score: number;
|
|
120
|
+
/** Feedback comment */
|
|
121
|
+
feedback?: string;
|
|
122
|
+
/** Survey context */
|
|
123
|
+
context?: string;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Churn event configuration.
|
|
127
|
+
*/
|
|
128
|
+
export interface ChurnEventConfig {
|
|
129
|
+
/** User ID */
|
|
130
|
+
userId: string;
|
|
131
|
+
/** Churn type */
|
|
132
|
+
churnType: 'voluntary' | 'involuntary' | 'downgrade';
|
|
133
|
+
/** Churn reason */
|
|
134
|
+
reason?: string;
|
|
135
|
+
/** Subscription/account value lost */
|
|
136
|
+
valueLost?: {
|
|
137
|
+
amount: number;
|
|
138
|
+
currency: string;
|
|
139
|
+
};
|
|
140
|
+
/** Win-back attempted */
|
|
141
|
+
winbackAttempted?: boolean;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Prevention action configuration.
|
|
145
|
+
*/
|
|
146
|
+
export interface PreventionActionConfig {
|
|
147
|
+
/** User ID */
|
|
148
|
+
userId: string;
|
|
149
|
+
/** Action type */
|
|
150
|
+
actionType: 'outreach' | 'discount' | 'feature_unlock' | 'support_call' | 'other';
|
|
151
|
+
/** Action details */
|
|
152
|
+
details?: Record<string, unknown>;
|
|
153
|
+
/** Outcome */
|
|
154
|
+
outcome?: 'success' | 'pending' | 'failed';
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* At-risk users filter.
|
|
158
|
+
*/
|
|
159
|
+
export interface AtRiskUsersFilter extends DateRangeFilter {
|
|
160
|
+
/** Minimum risk score */
|
|
161
|
+
minScore?: number;
|
|
162
|
+
/** Risk level filter */
|
|
163
|
+
riskLevel?: 'low' | 'medium' | 'high' | 'critical';
|
|
164
|
+
/** User segment */
|
|
165
|
+
segment?: string;
|
|
166
|
+
/** Limit results */
|
|
167
|
+
limit?: number;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Churn analytics result.
|
|
171
|
+
*/
|
|
172
|
+
export interface ChurnAnalyticsResult {
|
|
173
|
+
/** Total churn rate */
|
|
174
|
+
churnRate: number;
|
|
175
|
+
/** Voluntary churn rate */
|
|
176
|
+
voluntaryChurnRate: number;
|
|
177
|
+
/** Involuntary churn rate */
|
|
178
|
+
involuntaryChurnRate: number;
|
|
179
|
+
/** At-risk user count */
|
|
180
|
+
atRiskUserCount: number;
|
|
181
|
+
/** Revenue at risk */
|
|
182
|
+
revenueAtRisk: {
|
|
183
|
+
amount: number;
|
|
184
|
+
currency: string;
|
|
185
|
+
};
|
|
186
|
+
/** Prevention success rate */
|
|
187
|
+
preventionSuccessRate: number;
|
|
188
|
+
/** Average NPS of churned users */
|
|
189
|
+
avgChurnedNPS: number;
|
|
190
|
+
/** Top churn reasons */
|
|
191
|
+
topReasons: Array<{
|
|
192
|
+
reason: string;
|
|
193
|
+
count: number;
|
|
194
|
+
percentage: number;
|
|
195
|
+
}>;
|
|
196
|
+
/** Churn trend */
|
|
197
|
+
trend: TimeSeriesData;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Calculate churn risk score from factors.
|
|
201
|
+
*/
|
|
202
|
+
export declare function calculateChurnRiskScore(factors: ChurnRiskFactors): number;
|
|
203
|
+
/**
|
|
204
|
+
* Classify risk level from score.
|
|
205
|
+
*/
|
|
206
|
+
export declare function classifyRiskLevel(score: number): 'low' | 'medium' | 'high' | 'critical';
|
|
207
|
+
/**
|
|
208
|
+
* Generate churn prevention recommendations.
|
|
209
|
+
*/
|
|
210
|
+
export declare function generateRecommendations(riskFactors: Array<{
|
|
211
|
+
factor: string;
|
|
212
|
+
contribution: number;
|
|
213
|
+
}>): string[];
|
|
214
|
+
/**
|
|
215
|
+
* Churn and predictive analytics class.
|
|
216
|
+
*/
|
|
217
|
+
export declare class ChurnAnalytics extends EnterpriseFTRPC {
|
|
218
|
+
/**
|
|
219
|
+
* Get user churn risk score.
|
|
220
|
+
*/
|
|
221
|
+
getUserRiskScore(userId: string): Promise<ChurnRiskScore>;
|
|
222
|
+
/**
|
|
223
|
+
* Get multiple users' risk scores.
|
|
224
|
+
*/
|
|
225
|
+
getBulkRiskScores(userIds: string[]): Promise<ChurnRiskScore[]>;
|
|
226
|
+
/**
|
|
227
|
+
* Get at-risk users.
|
|
228
|
+
*/
|
|
229
|
+
getAtRiskUsers(filter?: AtRiskUsersFilter): Promise<ChurnRiskScore[]>;
|
|
230
|
+
/**
|
|
231
|
+
* Track usage decay.
|
|
232
|
+
*/
|
|
233
|
+
trackUsageDecay(config: UsageDecayConfig): Promise<UsageDecay>;
|
|
234
|
+
/**
|
|
235
|
+
* Track NPS score.
|
|
236
|
+
*/
|
|
237
|
+
trackNPS(config: NPSConfig): Promise<{
|
|
238
|
+
tracked: boolean;
|
|
239
|
+
}>;
|
|
240
|
+
/**
|
|
241
|
+
* Track churn event.
|
|
242
|
+
*/
|
|
243
|
+
trackChurn(config: ChurnEventConfig): Promise<{
|
|
244
|
+
tracked: boolean;
|
|
245
|
+
churnId: string;
|
|
246
|
+
}>;
|
|
247
|
+
/**
|
|
248
|
+
* Track churn prevention action.
|
|
249
|
+
*/
|
|
250
|
+
trackPreventionAction(config: PreventionActionConfig): Promise<{
|
|
251
|
+
tracked: boolean;
|
|
252
|
+
}>;
|
|
253
|
+
/**
|
|
254
|
+
* Update prevention action outcome.
|
|
255
|
+
*/
|
|
256
|
+
updatePreventionOutcome(userId: string, actionType: string, outcome: 'success' | 'failed'): Promise<{
|
|
257
|
+
updated: boolean;
|
|
258
|
+
}>;
|
|
259
|
+
/**
|
|
260
|
+
* Get churn analytics.
|
|
261
|
+
*/
|
|
262
|
+
getAnalytics(filter?: DateRangeFilter): Promise<ChurnAnalyticsResult>;
|
|
263
|
+
/**
|
|
264
|
+
* Get churn rate trend.
|
|
265
|
+
*/
|
|
266
|
+
getChurnTrend(filter?: DateRangeFilter, granularity?: TimeGranularity): Promise<TimeSeriesData>;
|
|
267
|
+
/**
|
|
268
|
+
* Get churn by segment.
|
|
269
|
+
*/
|
|
270
|
+
getChurnBySegment(segmentAttribute: string, filter?: DateRangeFilter): Promise<Array<{
|
|
271
|
+
segment: string;
|
|
272
|
+
churnRate: number;
|
|
273
|
+
count: number;
|
|
274
|
+
}>>;
|
|
275
|
+
/**
|
|
276
|
+
* Get NPS trend.
|
|
277
|
+
*/
|
|
278
|
+
getNPSTrend(filter?: DateRangeFilter, granularity?: TimeGranularity): Promise<TimeSeriesData>;
|
|
279
|
+
/**
|
|
280
|
+
* Get prevention effectiveness.
|
|
281
|
+
*/
|
|
282
|
+
getPreventionEffectiveness(filter?: DateRangeFilter): Promise<Array<{
|
|
283
|
+
actionType: string;
|
|
284
|
+
attempts: number;
|
|
285
|
+
successes: number;
|
|
286
|
+
rate: number;
|
|
287
|
+
}>>;
|
|
288
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Enterprise - Advanced Cohorts & Segmentation
|
|
3
|
+
* @module features/enterprise/cohorts
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Generate behavioral and acquisition cohorts for granular analysis.
|
|
7
|
+
* Segment users by behavior, acquisition source, and custom criteria.
|
|
8
|
+
*
|
|
9
|
+
* @useCases
|
|
10
|
+
* - Create behavior-based cohorts
|
|
11
|
+
* - Segment by acquisition source
|
|
12
|
+
* - Track paid vs free user cohorts
|
|
13
|
+
* - Dynamic segmentation rules
|
|
14
|
+
* - Cohort comparison analysis
|
|
15
|
+
*
|
|
16
|
+
* @metrics
|
|
17
|
+
* - Cohort size
|
|
18
|
+
* - Cohort retention
|
|
19
|
+
* - Cohort conversion
|
|
20
|
+
* - Segment growth rate
|
|
21
|
+
* - Cross-segment behavior
|
|
22
|
+
*
|
|
23
|
+
* @chartData
|
|
24
|
+
* - Bar chart: Cohort sizes
|
|
25
|
+
* - Line chart: Cohort trends
|
|
26
|
+
* - Heatmap: Cohort retention matrix
|
|
27
|
+
* - Comparison: Cohort A vs B
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const cohorts = new Cohorts(webId, endpoint, apiKey);
|
|
32
|
+
*
|
|
33
|
+
* // Create a behavioral cohort
|
|
34
|
+
* await cohorts.createCohort({
|
|
35
|
+
* name: 'Power Users',
|
|
36
|
+
* type: 'behavioral',
|
|
37
|
+
* rules: [{ attribute: 'sessions_per_week', operator: 'gte', value: 5 }]
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
import { EnterpriseFTRPC } from "../../client/enterprise-ftrpc";
|
|
42
|
+
import { DateRangeFilter, TimeSeriesData, TimeGranularity } from "../../types";
|
|
43
|
+
/**
|
|
44
|
+
* Cohort rule operators.
|
|
45
|
+
*/
|
|
46
|
+
export type CohortOperator = 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'not_in' | 'between' | 'exists' | 'not_exists';
|
|
47
|
+
/**
|
|
48
|
+
* Cohort rule definition.
|
|
49
|
+
*/
|
|
50
|
+
export interface CohortRule {
|
|
51
|
+
/** Attribute to evaluate */
|
|
52
|
+
attribute: string;
|
|
53
|
+
/** Comparison operator */
|
|
54
|
+
operator: CohortOperator;
|
|
55
|
+
/** Value to compare against */
|
|
56
|
+
value: unknown;
|
|
57
|
+
/** Logical operator for combining rules */
|
|
58
|
+
logicalOperator?: 'and' | 'or';
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Cohort type classification.
|
|
62
|
+
*/
|
|
63
|
+
export type CohortType = 'behavioral' | 'acquisition' | 'demographic' | 'lifecycle' | 'custom';
|
|
64
|
+
/**
|
|
65
|
+
* Cohort definition configuration.
|
|
66
|
+
*/
|
|
67
|
+
export interface CohortDefinition {
|
|
68
|
+
/** Unique cohort identifier */
|
|
69
|
+
cohortId?: string;
|
|
70
|
+
/** Cohort name */
|
|
71
|
+
name: string;
|
|
72
|
+
/** Cohort description */
|
|
73
|
+
description?: string;
|
|
74
|
+
/** Cohort type */
|
|
75
|
+
type: CohortType;
|
|
76
|
+
/** Rules for cohort membership */
|
|
77
|
+
rules: CohortRule[];
|
|
78
|
+
/** Whether cohort membership is dynamic */
|
|
79
|
+
dynamic?: boolean;
|
|
80
|
+
/** Time window for evaluation (for behavioral cohorts) */
|
|
81
|
+
timeWindow?: {
|
|
82
|
+
value: number;
|
|
83
|
+
unit: 'hours' | 'days' | 'weeks' | 'months';
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Segment definition configuration.
|
|
88
|
+
*/
|
|
89
|
+
export interface SegmentDefinition {
|
|
90
|
+
/** Segment identifier */
|
|
91
|
+
segmentId?: string;
|
|
92
|
+
/** Segment name */
|
|
93
|
+
name: string;
|
|
94
|
+
/** Segment description */
|
|
95
|
+
description?: string;
|
|
96
|
+
/** Segmentation attribute */
|
|
97
|
+
attribute: string;
|
|
98
|
+
/** Segment values/buckets */
|
|
99
|
+
buckets: Array<{
|
|
100
|
+
name: string;
|
|
101
|
+
rules: CohortRule[];
|
|
102
|
+
}>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* User cohort assignment.
|
|
106
|
+
*/
|
|
107
|
+
export interface CohortAssignment {
|
|
108
|
+
/** User ID */
|
|
109
|
+
userId: string;
|
|
110
|
+
/** Cohort ID */
|
|
111
|
+
cohortId: string;
|
|
112
|
+
/** Assignment timestamp */
|
|
113
|
+
assignedAt: string;
|
|
114
|
+
/** Whether user currently matches cohort rules */
|
|
115
|
+
isActive: boolean;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Cohort comparison configuration.
|
|
119
|
+
*/
|
|
120
|
+
export interface CohortComparisonConfig {
|
|
121
|
+
/** First cohort ID */
|
|
122
|
+
cohortA: string;
|
|
123
|
+
/** Second cohort ID */
|
|
124
|
+
cohortB: string;
|
|
125
|
+
/** Metrics to compare */
|
|
126
|
+
metrics: string[];
|
|
127
|
+
/** Date range for comparison */
|
|
128
|
+
filter?: DateRangeFilter;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Cohort analytics filter.
|
|
132
|
+
*/
|
|
133
|
+
export interface CohortAnalyticsFilter extends DateRangeFilter {
|
|
134
|
+
/** Filter by cohort type */
|
|
135
|
+
type?: CohortType;
|
|
136
|
+
/** Minimum cohort size */
|
|
137
|
+
minSize?: number;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Cohort response from API.
|
|
141
|
+
*/
|
|
142
|
+
export interface CohortResponse {
|
|
143
|
+
cohortId: string;
|
|
144
|
+
name: string;
|
|
145
|
+
type: CohortType;
|
|
146
|
+
size: number;
|
|
147
|
+
createdAt: string;
|
|
148
|
+
updatedAt: string;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Cohort member.
|
|
152
|
+
*/
|
|
153
|
+
export interface CohortMember {
|
|
154
|
+
userId: string;
|
|
155
|
+
joinedAt: string;
|
|
156
|
+
traits: Record<string, unknown>;
|
|
157
|
+
isActive: boolean;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Cohort analytics result.
|
|
161
|
+
*/
|
|
162
|
+
export interface CohortAnalytics {
|
|
163
|
+
cohortId: string;
|
|
164
|
+
name: string;
|
|
165
|
+
currentSize: number;
|
|
166
|
+
growthRate: number;
|
|
167
|
+
retention: {
|
|
168
|
+
day1: number;
|
|
169
|
+
day7: number;
|
|
170
|
+
day30: number;
|
|
171
|
+
};
|
|
172
|
+
conversion: number;
|
|
173
|
+
avgEngagementScore: number;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Cohort comparison result.
|
|
177
|
+
*/
|
|
178
|
+
export interface CohortComparison {
|
|
179
|
+
cohortA: CohortAnalytics;
|
|
180
|
+
cohortB: CohortAnalytics;
|
|
181
|
+
differences: Record<string, {
|
|
182
|
+
cohortAValue: number;
|
|
183
|
+
cohortBValue: number;
|
|
184
|
+
percentDiff: number;
|
|
185
|
+
significant: boolean;
|
|
186
|
+
}>;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Evaluate if a user matches cohort rules.
|
|
190
|
+
*/
|
|
191
|
+
export declare function evaluateCohortRules(userAttributes: Record<string, unknown>, rules: CohortRule[]): boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Generate cohort ID from name.
|
|
194
|
+
*/
|
|
195
|
+
export declare function generateCohortId(name: string): string;
|
|
196
|
+
/**
|
|
197
|
+
* Advanced cohorts and segmentation class.
|
|
198
|
+
*/
|
|
199
|
+
export declare class Cohorts extends EnterpriseFTRPC {
|
|
200
|
+
/**
|
|
201
|
+
* Create a new cohort.
|
|
202
|
+
*/
|
|
203
|
+
createCohort(definition: CohortDefinition): Promise<CohortResponse>;
|
|
204
|
+
/**
|
|
205
|
+
* Update an existing cohort.
|
|
206
|
+
*/
|
|
207
|
+
updateCohort(cohortId: string, updates: Partial<CohortDefinition>): Promise<CohortResponse>;
|
|
208
|
+
/**
|
|
209
|
+
* Delete a cohort.
|
|
210
|
+
*/
|
|
211
|
+
deleteCohort(cohortId: string): Promise<{
|
|
212
|
+
deleted: boolean;
|
|
213
|
+
}>;
|
|
214
|
+
/**
|
|
215
|
+
* Get cohort by ID.
|
|
216
|
+
*/
|
|
217
|
+
getCohort(cohortId: string): Promise<CohortResponse & {
|
|
218
|
+
rules: CohortRule[];
|
|
219
|
+
}>;
|
|
220
|
+
/**
|
|
221
|
+
* List all cohorts.
|
|
222
|
+
*/
|
|
223
|
+
listCohorts(filter?: CohortAnalyticsFilter): Promise<CohortResponse[]>;
|
|
224
|
+
/**
|
|
225
|
+
* Get cohort members.
|
|
226
|
+
*/
|
|
227
|
+
getCohortMembers(cohortId: string, options?: {
|
|
228
|
+
limit?: number;
|
|
229
|
+
offset?: number;
|
|
230
|
+
}): Promise<{
|
|
231
|
+
members: CohortMember[];
|
|
232
|
+
total: number;
|
|
233
|
+
}>;
|
|
234
|
+
/**
|
|
235
|
+
* Check if user belongs to cohort.
|
|
236
|
+
*/
|
|
237
|
+
isUserInCohort(userId: string, cohortId: string): Promise<{
|
|
238
|
+
isMember: boolean;
|
|
239
|
+
}>;
|
|
240
|
+
/**
|
|
241
|
+
* Get user's cohorts.
|
|
242
|
+
*/
|
|
243
|
+
getUserCohorts(userId: string): Promise<CohortAssignment[]>;
|
|
244
|
+
/**
|
|
245
|
+
* Create a segment.
|
|
246
|
+
*/
|
|
247
|
+
createSegment(definition: SegmentDefinition): Promise<{
|
|
248
|
+
segmentId: string;
|
|
249
|
+
}>;
|
|
250
|
+
/**
|
|
251
|
+
* Get segment distribution.
|
|
252
|
+
*/
|
|
253
|
+
getSegmentDistribution(segmentId: string, filter?: DateRangeFilter): Promise<Array<{
|
|
254
|
+
bucket: string;
|
|
255
|
+
count: number;
|
|
256
|
+
percentage: number;
|
|
257
|
+
}>>;
|
|
258
|
+
/**
|
|
259
|
+
* Compare two cohorts.
|
|
260
|
+
*/
|
|
261
|
+
compareCohorts(config: CohortComparisonConfig): Promise<CohortComparison>;
|
|
262
|
+
/**
|
|
263
|
+
* Get cohort analytics.
|
|
264
|
+
*/
|
|
265
|
+
getCohortAnalytics(cohortId: string, filter?: DateRangeFilter): Promise<CohortAnalytics>;
|
|
266
|
+
/**
|
|
267
|
+
* Get cohort growth trend.
|
|
268
|
+
*/
|
|
269
|
+
getCohortGrowth(cohortId: string, filter?: DateRangeFilter, granularity?: TimeGranularity): Promise<TimeSeriesData>;
|
|
270
|
+
}
|