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,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Product Analytics - Retention Analysis
|
|
3
|
+
* @module features/analytics/retention
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Track and analyze user retention using cohort analysis,
|
|
7
|
+
* identify churn patterns, and measure user stickiness.
|
|
8
|
+
*
|
|
9
|
+
* @useCases
|
|
10
|
+
* - Measure week-over-week retention rates
|
|
11
|
+
* - Compare retention across user cohorts
|
|
12
|
+
* - Identify churn risk factors
|
|
13
|
+
* - Track feature adoption impact on retention
|
|
14
|
+
* - Calculate DAU/MAU ratios (stickiness)
|
|
15
|
+
*
|
|
16
|
+
* @metrics
|
|
17
|
+
* - Day 1, 7, 30 retention rates
|
|
18
|
+
* - Cohort retention curves
|
|
19
|
+
* - Churn rate by segment
|
|
20
|
+
* - User resurrection rate
|
|
21
|
+
* - DAU/WAU/MAU ratios
|
|
22
|
+
*
|
|
23
|
+
* @chartData
|
|
24
|
+
* - Retention curve: Line chart over time
|
|
25
|
+
* - Cohort matrix: Heatmap by cohort/period
|
|
26
|
+
* - Bar chart: Retention by segment
|
|
27
|
+
* - Trend line: Stickiness over time
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const retention = new Retention(webId, endpoint, apiKey);
|
|
32
|
+
*
|
|
33
|
+
* // Track user activity
|
|
34
|
+
* await retention.trackActivity({
|
|
35
|
+
* userId: 'user_123',
|
|
36
|
+
* action: 'feature_used'
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // Get cohort analysis
|
|
40
|
+
* const cohorts = await retention.getCohortAnalysis({
|
|
41
|
+
* range: 'last90days',
|
|
42
|
+
* granularity: 'week'
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
import { FTRPC } from "../../client/ftrpc";
|
|
47
|
+
import { RetentionCohort, UserLifecycleStage, LifecycleMetrics, DateRangeFilter, TimeGranularity, TimeSeriesData } from "../../types";
|
|
48
|
+
/**
|
|
49
|
+
* Configuration for tracking user activity.
|
|
50
|
+
*/
|
|
51
|
+
export interface ActivityConfig {
|
|
52
|
+
/** User identifier */
|
|
53
|
+
userId: string;
|
|
54
|
+
/** Activity type/action */
|
|
55
|
+
action?: string;
|
|
56
|
+
/** Session ID */
|
|
57
|
+
sessionId?: string;
|
|
58
|
+
/** Custom properties */
|
|
59
|
+
properties?: Record<string, unknown>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Configuration for cohort analysis.
|
|
63
|
+
*/
|
|
64
|
+
export interface CohortAnalysisConfig {
|
|
65
|
+
/** Date range for analysis */
|
|
66
|
+
filter?: DateRangeFilter;
|
|
67
|
+
/** Cohort granularity */
|
|
68
|
+
granularity?: TimeGranularity;
|
|
69
|
+
/** Segment by trait */
|
|
70
|
+
segmentBy?: string;
|
|
71
|
+
/** Number of periods to show */
|
|
72
|
+
periods?: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Activity tracking response.
|
|
76
|
+
*/
|
|
77
|
+
export interface ActivityResponse {
|
|
78
|
+
eventName: string;
|
|
79
|
+
properties: Record<string, unknown>;
|
|
80
|
+
response: {
|
|
81
|
+
userId: string;
|
|
82
|
+
tracked: boolean;
|
|
83
|
+
daysSinceFirstSeen: number;
|
|
84
|
+
isReturning: boolean;
|
|
85
|
+
};
|
|
86
|
+
timestamp: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Cohort analysis data for charts.
|
|
90
|
+
*/
|
|
91
|
+
export interface CohortAnalysisData {
|
|
92
|
+
/** Cohort data */
|
|
93
|
+
cohorts: RetentionCohort[];
|
|
94
|
+
/** Retention matrix for heatmap */
|
|
95
|
+
matrix: Array<{
|
|
96
|
+
cohort: string;
|
|
97
|
+
periods: Array<{
|
|
98
|
+
period: number;
|
|
99
|
+
retained: number;
|
|
100
|
+
retentionRate: number;
|
|
101
|
+
}>;
|
|
102
|
+
}>;
|
|
103
|
+
/** Summary metrics */
|
|
104
|
+
summary: {
|
|
105
|
+
avgDay1Retention: number;
|
|
106
|
+
avgDay7Retention: number;
|
|
107
|
+
avgDay30Retention: number;
|
|
108
|
+
overallRetentionTrend: 'improving' | 'declining' | 'stable';
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* User stickiness data.
|
|
113
|
+
*/
|
|
114
|
+
export interface StickinessData {
|
|
115
|
+
/** DAU - Daily Active Users */
|
|
116
|
+
dau: number;
|
|
117
|
+
/** WAU - Weekly Active Users */
|
|
118
|
+
wau: number;
|
|
119
|
+
/** MAU - Monthly Active Users */
|
|
120
|
+
mau: number;
|
|
121
|
+
/** DAU/MAU ratio (stickiness) */
|
|
122
|
+
dauMauRatio: number;
|
|
123
|
+
/** DAU/WAU ratio */
|
|
124
|
+
dauWauRatio: number;
|
|
125
|
+
/** Stickiness trend over time */
|
|
126
|
+
trendData: TimeSeriesData;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Churn analysis data.
|
|
130
|
+
*/
|
|
131
|
+
export interface ChurnAnalysisData {
|
|
132
|
+
/** Current churn rate */
|
|
133
|
+
churnRate: number;
|
|
134
|
+
/** Users at risk of churning */
|
|
135
|
+
atRiskUsers: number;
|
|
136
|
+
/** Users who churned this period */
|
|
137
|
+
churnedUsers: number;
|
|
138
|
+
/** Churn by segment */
|
|
139
|
+
bySegment: Array<{
|
|
140
|
+
segment: string;
|
|
141
|
+
churnRate: number;
|
|
142
|
+
count: number;
|
|
143
|
+
}>;
|
|
144
|
+
/** Common churn factors */
|
|
145
|
+
churnFactors: Array<{
|
|
146
|
+
factor: string;
|
|
147
|
+
correlation: number;
|
|
148
|
+
}>;
|
|
149
|
+
/** Churn trend */
|
|
150
|
+
trendData: TimeSeriesData;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Retention - Track and analyze user retention.
|
|
154
|
+
*
|
|
155
|
+
* @extends FTRPC
|
|
156
|
+
*
|
|
157
|
+
* @description
|
|
158
|
+
* Provides retention analysis capabilities including:
|
|
159
|
+
* - User activity tracking
|
|
160
|
+
* - Cohort-based retention analysis
|
|
161
|
+
* - Stickiness metrics (DAU/MAU)
|
|
162
|
+
* - Churn prediction and analysis
|
|
163
|
+
* - Lifecycle stage tracking
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const retention = new Retention(webId, endpoint, apiKey);
|
|
168
|
+
*
|
|
169
|
+
* // Track daily user activity
|
|
170
|
+
* await retention.trackActivity({
|
|
171
|
+
* userId: 'user_123',
|
|
172
|
+
* action: 'daily_login'
|
|
173
|
+
* });
|
|
174
|
+
*
|
|
175
|
+
* // Analyze cohort retention
|
|
176
|
+
* const analysis = await retention.getCohortAnalysis({
|
|
177
|
+
* granularity: 'week',
|
|
178
|
+
* periods: 12
|
|
179
|
+
* });
|
|
180
|
+
*
|
|
181
|
+
* // Cohort heatmap data
|
|
182
|
+
* const heatmapData = analysis.matrix;
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
export declare class Retention extends FTRPC {
|
|
186
|
+
/**
|
|
187
|
+
* Tracks user activity for retention calculation.
|
|
188
|
+
*
|
|
189
|
+
* @param config - Activity configuration
|
|
190
|
+
* @returns Promise resolving to activity response
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* // Track on app open
|
|
195
|
+
* await retention.trackActivity({
|
|
196
|
+
* userId: 'user_123',
|
|
197
|
+
* action: 'app_opened'
|
|
198
|
+
* });
|
|
199
|
+
*
|
|
200
|
+
* // Track specific feature usage
|
|
201
|
+
* await retention.trackActivity({
|
|
202
|
+
* userId: 'user_123',
|
|
203
|
+
* action: 'used_export',
|
|
204
|
+
* properties: { format: 'pdf' }
|
|
205
|
+
* });
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
trackActivity(config: ActivityConfig): Promise<ActivityResponse>;
|
|
209
|
+
/**
|
|
210
|
+
* Tracks user lifecycle stage change.
|
|
211
|
+
*
|
|
212
|
+
* @param userId - User identifier
|
|
213
|
+
* @param stage - New lifecycle stage
|
|
214
|
+
* @param previousStage - Previous stage (optional)
|
|
215
|
+
* @returns Promise resolving to stage change response
|
|
216
|
+
*/
|
|
217
|
+
trackLifecycleChange(userId: string, stage: UserLifecycleStage, previousStage?: UserLifecycleStage): Promise<ActivityResponse>;
|
|
218
|
+
/**
|
|
219
|
+
* Gets cohort-based retention analysis.
|
|
220
|
+
*
|
|
221
|
+
* @param config - Cohort analysis configuration
|
|
222
|
+
* @returns Promise resolving to cohort analysis data
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* const analysis = await retention.getCohortAnalysis({
|
|
227
|
+
* filter: { range: 'last90days' },
|
|
228
|
+
* granularity: 'week',
|
|
229
|
+
* periods: 12
|
|
230
|
+
* });
|
|
231
|
+
*
|
|
232
|
+
* // Heatmap visualization
|
|
233
|
+
* const heatmap = analysis.matrix.map(cohort => ({
|
|
234
|
+
* y: cohort.cohort,
|
|
235
|
+
* data: cohort.periods.map(p => ({
|
|
236
|
+
* x: `Period ${p.period}`,
|
|
237
|
+
* value: p.retentionRate
|
|
238
|
+
* }))
|
|
239
|
+
* }));
|
|
240
|
+
*
|
|
241
|
+
* // Retention curve (average across cohorts)
|
|
242
|
+
* const curve = [1, 7, 14, 30].map(day => ({
|
|
243
|
+
* x: `Day ${day}`,
|
|
244
|
+
* y: getAvgRetention(analysis.cohorts, day)
|
|
245
|
+
* }));
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
getCohortAnalysis(config?: CohortAnalysisConfig): Promise<CohortAnalysisData>;
|
|
249
|
+
/**
|
|
250
|
+
* Gets user stickiness metrics (DAU/MAU).
|
|
251
|
+
*
|
|
252
|
+
* @param filter - Date range filter
|
|
253
|
+
* @returns Promise resolving to stickiness data
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```typescript
|
|
257
|
+
* const stickiness = await retention.getStickiness({
|
|
258
|
+
* range: 'last30days'
|
|
259
|
+
* });
|
|
260
|
+
*
|
|
261
|
+
* console.log(`DAU/MAU: ${(stickiness.dauMauRatio * 100).toFixed(1)}%`);
|
|
262
|
+
*
|
|
263
|
+
* // Trend chart
|
|
264
|
+
* const trendData = stickiness.trendData.data;
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
getStickiness(filter?: DateRangeFilter): Promise<StickinessData>;
|
|
268
|
+
/**
|
|
269
|
+
* Gets churn analysis and at-risk users.
|
|
270
|
+
*
|
|
271
|
+
* @param filter - Date range filter
|
|
272
|
+
* @returns Promise resolving to churn analysis data
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```typescript
|
|
276
|
+
* const churn = await retention.getChurnAnalysis({
|
|
277
|
+
* range: 'thisMonth'
|
|
278
|
+
* });
|
|
279
|
+
*
|
|
280
|
+
* // Alert on high churn segments
|
|
281
|
+
* churn.bySegment
|
|
282
|
+
* .filter(s => s.churnRate > 0.1)
|
|
283
|
+
* .forEach(s => console.warn(`High churn in ${s.segment}`));
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
getChurnAnalysis(filter?: DateRangeFilter): Promise<ChurnAnalysisData>;
|
|
287
|
+
/**
|
|
288
|
+
* Gets user lifecycle distribution.
|
|
289
|
+
*
|
|
290
|
+
* @returns Promise resolving to lifecycle metrics
|
|
291
|
+
*/
|
|
292
|
+
getLifecycleMetrics(): Promise<LifecycleMetrics>;
|
|
293
|
+
}
|
|
294
|
+
export default Retention;
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Product Analytics - Session Tracking
|
|
3
|
+
* @module features/analytics/sessions
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Track user sessions with comprehensive context including device info,
|
|
7
|
+
* geographic location, traffic source, and engagement metrics.
|
|
8
|
+
*
|
|
9
|
+
* @useCases
|
|
10
|
+
* - Monitor active user sessions in real-time
|
|
11
|
+
* - Analyze session duration and depth
|
|
12
|
+
* - Track user journey across pages
|
|
13
|
+
* - Identify traffic sources and campaigns
|
|
14
|
+
* - Segment users by device and location
|
|
15
|
+
*
|
|
16
|
+
* @metrics
|
|
17
|
+
* - Total sessions
|
|
18
|
+
* - Unique visitors
|
|
19
|
+
* - Average session duration
|
|
20
|
+
* - Pages per session
|
|
21
|
+
* - Bounce rate
|
|
22
|
+
* - New vs returning visitors
|
|
23
|
+
*
|
|
24
|
+
* @chartData
|
|
25
|
+
* - Line chart: Sessions over time
|
|
26
|
+
* - Pie chart: Traffic source breakdown
|
|
27
|
+
* - Bar chart: Sessions by device type
|
|
28
|
+
* - Geo map: Sessions by country
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const sessions = new Sessions(webId, endpoint, apiKey);
|
|
33
|
+
*
|
|
34
|
+
* // Start a new session
|
|
35
|
+
* const session = await sessions.start({
|
|
36
|
+
* userId: 'user_123',
|
|
37
|
+
* device: { type: 'desktop', browser: 'Chrome' },
|
|
38
|
+
* source: 'google',
|
|
39
|
+
* medium: 'organic'
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* // End session
|
|
43
|
+
* await sessions.end(session.sessionId);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
import { FTRPC } from "../../client/ftrpc";
|
|
47
|
+
import { DeviceInfo, GeoLocation, UTMParams, TimeSeriesData, DateRangeFilter, PaginationParams, UserIdentity } from "../../types";
|
|
48
|
+
/**
|
|
49
|
+
* Configuration for starting a new session.
|
|
50
|
+
*/
|
|
51
|
+
export interface SessionStartConfig {
|
|
52
|
+
/** User identity */
|
|
53
|
+
user?: UserIdentity;
|
|
54
|
+
/** Device information */
|
|
55
|
+
device?: DeviceInfo;
|
|
56
|
+
/** Geographic location */
|
|
57
|
+
location?: GeoLocation;
|
|
58
|
+
/** Traffic source */
|
|
59
|
+
source?: string;
|
|
60
|
+
/** Traffic medium */
|
|
61
|
+
medium?: string;
|
|
62
|
+
/** Campaign name */
|
|
63
|
+
campaign?: string;
|
|
64
|
+
/** UTM parameters */
|
|
65
|
+
utm?: UTMParams;
|
|
66
|
+
/** Landing page URL */
|
|
67
|
+
landingPage?: string;
|
|
68
|
+
/** Referrer URL */
|
|
69
|
+
referrer?: string;
|
|
70
|
+
/** Custom properties */
|
|
71
|
+
properties?: Record<string, unknown>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Session response from API.
|
|
75
|
+
*/
|
|
76
|
+
export interface SessionResponse {
|
|
77
|
+
eventName: string;
|
|
78
|
+
properties: Record<string, unknown>;
|
|
79
|
+
response: {
|
|
80
|
+
sessionId: string;
|
|
81
|
+
started: boolean;
|
|
82
|
+
isNewVisitor: boolean;
|
|
83
|
+
};
|
|
84
|
+
timestamp: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Session end response.
|
|
88
|
+
*/
|
|
89
|
+
export interface SessionEndResponse {
|
|
90
|
+
eventName: string;
|
|
91
|
+
properties: Record<string, unknown>;
|
|
92
|
+
response: {
|
|
93
|
+
sessionId: string;
|
|
94
|
+
duration: number;
|
|
95
|
+
pageViews: number;
|
|
96
|
+
eventCount: number;
|
|
97
|
+
};
|
|
98
|
+
timestamp: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Session analytics data for charts.
|
|
102
|
+
*/
|
|
103
|
+
export interface SessionAnalyticsData {
|
|
104
|
+
/** Summary metrics */
|
|
105
|
+
summary: {
|
|
106
|
+
totalSessions: number;
|
|
107
|
+
uniqueVisitors: number;
|
|
108
|
+
newVisitors: number;
|
|
109
|
+
returningVisitors: number;
|
|
110
|
+
avgSessionDuration: number;
|
|
111
|
+
avgPagesPerSession: number;
|
|
112
|
+
bounceRate: number;
|
|
113
|
+
};
|
|
114
|
+
/** Sessions time series */
|
|
115
|
+
timeSeries: TimeSeriesData;
|
|
116
|
+
/** Sessions by source */
|
|
117
|
+
bySource: Array<{
|
|
118
|
+
source: string;
|
|
119
|
+
sessions: number;
|
|
120
|
+
percentage: number;
|
|
121
|
+
}>;
|
|
122
|
+
/** Sessions by device */
|
|
123
|
+
byDevice: Array<{
|
|
124
|
+
device: string;
|
|
125
|
+
sessions: number;
|
|
126
|
+
percentage: number;
|
|
127
|
+
}>;
|
|
128
|
+
/** Sessions by country */
|
|
129
|
+
byCountry: Array<{
|
|
130
|
+
country: string;
|
|
131
|
+
countryCode: string;
|
|
132
|
+
sessions: number;
|
|
133
|
+
}>;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Real-time session data.
|
|
137
|
+
*/
|
|
138
|
+
export interface RealTimeSessionData {
|
|
139
|
+
/** Currently active sessions */
|
|
140
|
+
activeSessions: number;
|
|
141
|
+
/** Active users in last 5 minutes */
|
|
142
|
+
activeUsers5min: number;
|
|
143
|
+
/** Active users in last 30 minutes */
|
|
144
|
+
activeUsers30min: number;
|
|
145
|
+
/** Sessions by page (real-time) */
|
|
146
|
+
sessionsByPage: Array<{
|
|
147
|
+
path: string;
|
|
148
|
+
count: number;
|
|
149
|
+
}>;
|
|
150
|
+
/** Sessions by country (real-time) */
|
|
151
|
+
sessionsByCountry: Array<{
|
|
152
|
+
country: string;
|
|
153
|
+
count: number;
|
|
154
|
+
}>;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Sessions - Track and analyze user sessions.
|
|
158
|
+
*
|
|
159
|
+
* @extends FTRPC
|
|
160
|
+
*
|
|
161
|
+
* @description
|
|
162
|
+
* Provides comprehensive session tracking including:
|
|
163
|
+
* - Session lifecycle (start, update, end)
|
|
164
|
+
* - Device and location tracking
|
|
165
|
+
* - Traffic source attribution
|
|
166
|
+
* - Real-time session monitoring
|
|
167
|
+
* - Session replay triggers
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* const sessions = new Sessions(webId, endpoint, apiKey);
|
|
172
|
+
*
|
|
173
|
+
* // Start session on page load
|
|
174
|
+
* const session = await sessions.start({
|
|
175
|
+
* user: { userId: 'user_123' },
|
|
176
|
+
* device: { type: 'mobile', os: 'iOS' },
|
|
177
|
+
* source: 'email',
|
|
178
|
+
* campaign: 'summer_sale'
|
|
179
|
+
* });
|
|
180
|
+
*
|
|
181
|
+
* // Get real-time data
|
|
182
|
+
* const realTime = await sessions.getRealTime();
|
|
183
|
+
* console.log(`${realTime.activeSessions} users online`);
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
export declare class Sessions extends FTRPC {
|
|
187
|
+
/**
|
|
188
|
+
* Starts a new user session.
|
|
189
|
+
*
|
|
190
|
+
* @param config - Session configuration
|
|
191
|
+
* @returns Promise resolving to session response with sessionId
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* const session = await sessions.start({
|
|
196
|
+
* user: { userId: 'user_123' },
|
|
197
|
+
* source: 'google',
|
|
198
|
+
* medium: 'cpc',
|
|
199
|
+
* campaign: 'brand_terms'
|
|
200
|
+
* });
|
|
201
|
+
* localStorage.setItem('sessionId', session.response.sessionId);
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
start(config?: SessionStartConfig): Promise<SessionResponse>;
|
|
205
|
+
/**
|
|
206
|
+
* Updates an existing session with new data.
|
|
207
|
+
*
|
|
208
|
+
* @param sessionId - Session identifier
|
|
209
|
+
* @param properties - Properties to update
|
|
210
|
+
* @returns Promise resolving to update response
|
|
211
|
+
*/
|
|
212
|
+
update(sessionId: string, properties: Record<string, unknown>): Promise<SessionResponse>;
|
|
213
|
+
/**
|
|
214
|
+
* Ends a user session.
|
|
215
|
+
*
|
|
216
|
+
* @param sessionId - Session identifier to end
|
|
217
|
+
* @returns Promise resolving to session end response with metrics
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* window.addEventListener('beforeunload', async () => {
|
|
222
|
+
* const sessionId = localStorage.getItem('sessionId');
|
|
223
|
+
* if (sessionId) {
|
|
224
|
+
* await sessions.end(sessionId);
|
|
225
|
+
* }
|
|
226
|
+
* });
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
end(sessionId: string): Promise<SessionEndResponse>;
|
|
230
|
+
/**
|
|
231
|
+
* Tracks a heartbeat to keep session alive.
|
|
232
|
+
*
|
|
233
|
+
* @param sessionId - Session identifier
|
|
234
|
+
* @returns Promise resolving to heartbeat response
|
|
235
|
+
*/
|
|
236
|
+
heartbeat(sessionId: string): Promise<SessionResponse>;
|
|
237
|
+
/**
|
|
238
|
+
* Retrieves session analytics data for dashboards and charts.
|
|
239
|
+
*
|
|
240
|
+
* @param filter - Date range filter
|
|
241
|
+
* @param pagination - Pagination options
|
|
242
|
+
* @returns Promise resolving to session analytics
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* const analytics = await sessions.getAnalytics({
|
|
247
|
+
* range: 'last7days'
|
|
248
|
+
* });
|
|
249
|
+
*
|
|
250
|
+
* // For pie chart - traffic sources
|
|
251
|
+
* const sourceData = analytics.bySource.map(s => ({
|
|
252
|
+
* name: s.source,
|
|
253
|
+
* value: s.sessions
|
|
254
|
+
* }));
|
|
255
|
+
*
|
|
256
|
+
* // For line chart - sessions over time
|
|
257
|
+
* const trendData = analytics.timeSeries.data;
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
getAnalytics(filter?: DateRangeFilter, pagination?: PaginationParams): Promise<SessionAnalyticsData>;
|
|
261
|
+
/**
|
|
262
|
+
* Gets real-time session data for live dashboards.
|
|
263
|
+
*
|
|
264
|
+
* @returns Promise resolving to real-time session data
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```typescript
|
|
268
|
+
* // Poll for real-time updates
|
|
269
|
+
* setInterval(async () => {
|
|
270
|
+
* const realTime = await sessions.getRealTime();
|
|
271
|
+
* updateDashboard(realTime.activeSessions);
|
|
272
|
+
* }, 10000);
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
getRealTime(): Promise<RealTimeSessionData>;
|
|
276
|
+
}
|
|
277
|
+
export default Sessions;
|