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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/dist/browser.d.ts +119 -0
  3. package/dist/flowgrid.min.js +2 -0
  4. package/dist/flowgrid.min.js.map +1 -0
  5. package/dist/index.d.ts +44 -0
  6. package/dist/index.js +2 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/lib/client/enterprise-ftrpc.d.ts +51 -0
  9. package/dist/lib/client/ftrpc.d.ts +43 -0
  10. package/dist/lib/client/modules.d.ts +104 -0
  11. package/dist/lib/features/analytics/attribution.d.ts +257 -0
  12. package/dist/lib/features/analytics/events.d.ts +304 -0
  13. package/dist/lib/features/analytics/funnels.d.ts +291 -0
  14. package/dist/lib/features/analytics/heatmaps.d.ts +247 -0
  15. package/dist/lib/features/analytics/identify.d.ts +273 -0
  16. package/dist/lib/features/analytics/index.d.ts +22 -0
  17. package/dist/lib/features/analytics/page-views.d.ts +250 -0
  18. package/dist/lib/features/analytics/performance.d.ts +281 -0
  19. package/dist/lib/features/analytics/retention.d.ts +294 -0
  20. package/dist/lib/features/analytics/sessions.d.ts +277 -0
  21. package/dist/lib/features/core/activation.d.ts +239 -0
  22. package/dist/lib/features/core/experiment.d.ts +286 -0
  23. package/dist/lib/features/core/feature-flag.d.ts +264 -0
  24. package/dist/lib/features/core/index.d.ts +14 -0
  25. package/dist/lib/features/core/track-feature.d.ts +220 -0
  26. package/dist/lib/features/core/track-prompt.d.ts +247 -0
  27. package/dist/lib/features/ecommerce/cart.d.ts +298 -0
  28. package/dist/lib/features/ecommerce/checkout.d.ts +324 -0
  29. package/dist/lib/features/ecommerce/index.d.ts +26 -0
  30. package/dist/lib/features/ecommerce/inventory.d.ts +221 -0
  31. package/dist/lib/features/ecommerce/ltv.d.ts +258 -0
  32. package/dist/lib/features/ecommerce/products.d.ts +268 -0
  33. package/dist/lib/features/ecommerce/promotions.d.ts +266 -0
  34. package/dist/lib/features/ecommerce/purchases.d.ts +287 -0
  35. package/dist/lib/features/ecommerce/refunds.d.ts +232 -0
  36. package/dist/lib/features/ecommerce/search.d.ts +225 -0
  37. package/dist/lib/features/ecommerce/subscriptions.d.ts +281 -0
  38. package/dist/lib/features/ecommerce/wishlist.d.ts +236 -0
  39. package/dist/lib/features/enterprise/acquisition.d.ts +373 -0
  40. package/dist/lib/features/enterprise/alerts.d.ts +348 -0
  41. package/dist/lib/features/enterprise/churn.d.ts +288 -0
  42. package/dist/lib/features/enterprise/cohorts.d.ts +270 -0
  43. package/dist/lib/features/enterprise/engagement.d.ts +233 -0
  44. package/dist/lib/features/enterprise/forecasting.d.ts +351 -0
  45. package/dist/lib/features/enterprise/index.d.ts +20 -0
  46. package/dist/lib/features/enterprise/monetization.d.ts +356 -0
  47. package/dist/lib/features/enterprise/multi-path-funnels.d.ts +327 -0
  48. package/dist/lib/features/enterprise/paths.d.ts +332 -0
  49. package/dist/lib/features/enterprise/security.d.ts +387 -0
  50. package/dist/lib/features/enterprise/support.d.ts +329 -0
  51. package/dist/lib/frameworks/index.d.ts +9 -0
  52. package/dist/lib/frameworks/nextjs/client.d.ts +208 -0
  53. package/dist/lib/frameworks/nextjs/index.d.ts +29 -0
  54. package/dist/lib/frameworks/nextjs/server.d.ts +201 -0
  55. package/dist/lib/frameworks/node/index.d.ts +265 -0
  56. package/dist/lib/frameworks/nuxt/index.d.ts +190 -0
  57. package/dist/lib/frameworks/react/index.d.ts +245 -0
  58. package/dist/lib/frameworks/vue/index.d.ts +275 -0
  59. package/dist/lib/types/analytics.d.ts +365 -0
  60. package/dist/lib/types/common.d.ts +230 -0
  61. package/dist/lib/types/ecommerce.d.ts +309 -0
  62. package/dist/lib/types/index.d.ts +7 -0
  63. package/dist/lib/utils/functions.d.ts +1 -0
  64. package/package.json +139 -0
@@ -0,0 +1,304 @@
1
+ /**
2
+ * @fileoverview Product Analytics - Custom Event Tracking
3
+ * @module features/analytics/events
4
+ *
5
+ * @description
6
+ * Track custom events with flexible properties for any user action
7
+ * or system event. Supports categorization, value tracking, and batching.
8
+ *
9
+ * @useCases
10
+ * - Track button clicks and CTA interactions
11
+ * - Monitor feature usage and engagement
12
+ * - Capture form submissions and errors
13
+ * - Log search queries and results
14
+ * - Record video/audio playback events
15
+ *
16
+ * @metrics
17
+ * - Event counts by type
18
+ * - Event trends over time
19
+ * - Unique users per event
20
+ * - Event value aggregations
21
+ * - Event-to-conversion correlation
22
+ *
23
+ * @chartData
24
+ * - Bar chart: Top events by count
25
+ * - Line chart: Event trends over time
26
+ * - Heatmap: Events by hour/day
27
+ * - Sankey: Event flow paths
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const events = new Events(webId, endpoint, apiKey);
32
+ *
33
+ * // Track a button click
34
+ * await events.track({
35
+ * eventName: 'cta_clicked',
36
+ * category: 'engagement',
37
+ * action: 'click',
38
+ * label: 'signup_hero'
39
+ * });
40
+ *
41
+ * // Track with value
42
+ * await events.track({
43
+ * eventName: 'video_watched',
44
+ * value: 120, // seconds
45
+ * properties: { videoId: 'intro-video' }
46
+ * });
47
+ * ```
48
+ */
49
+ import { FTRPC } from "../../client/ftrpc";
50
+ import { ClickEvent, FormEvent, SearchEvent, ErrorEvent, TimeSeriesData, DateRangeFilter, PaginationParams } from "../../types";
51
+ /**
52
+ * Configuration for tracking a custom event.
53
+ */
54
+ export interface EventTrackConfig {
55
+ /** Event name (required) */
56
+ eventName: string;
57
+ /** Event category for grouping */
58
+ category?: string;
59
+ /** Event action */
60
+ action?: string;
61
+ /** Event label for sub-categorization */
62
+ label?: string;
63
+ /** Numeric value associated with event */
64
+ value?: number;
65
+ /** Non-interactive event (won't affect bounce rate) */
66
+ nonInteraction?: boolean;
67
+ /** User ID */
68
+ userId?: string;
69
+ /** Session ID */
70
+ sessionId?: string;
71
+ /** Custom properties */
72
+ properties?: Record<string, unknown>;
73
+ }
74
+ /**
75
+ * Batch event tracking configuration.
76
+ */
77
+ export interface BatchEventConfig {
78
+ /** Array of events to track */
79
+ events: EventTrackConfig[];
80
+ }
81
+ /**
82
+ * Event response from API.
83
+ */
84
+ export interface EventResponse {
85
+ eventName: string;
86
+ properties: Record<string, unknown>;
87
+ response: {
88
+ eventId: string;
89
+ tracked: boolean;
90
+ };
91
+ timestamp: string;
92
+ }
93
+ /**
94
+ * Batch event response.
95
+ */
96
+ export interface BatchEventResponse {
97
+ eventName: string;
98
+ properties: Record<string, unknown>;
99
+ response: {
100
+ tracked: number;
101
+ failed: number;
102
+ eventIds: string[];
103
+ };
104
+ timestamp: string;
105
+ }
106
+ /**
107
+ * Event analytics data for charts.
108
+ */
109
+ export interface EventAnalyticsData {
110
+ /** Top events by count */
111
+ topEvents: Array<{
112
+ eventName: string;
113
+ category: string;
114
+ count: number;
115
+ uniqueUsers: number;
116
+ totalValue: number;
117
+ }>;
118
+ /** Events time series */
119
+ timeSeries: TimeSeriesData;
120
+ /** Events by category */
121
+ byCategory: Array<{
122
+ category: string;
123
+ count: number;
124
+ percentage: number;
125
+ }>;
126
+ /** Summary metrics */
127
+ summary: {
128
+ totalEvents: number;
129
+ uniqueEventTypes: number;
130
+ eventsPerUser: number;
131
+ totalValue: number;
132
+ };
133
+ }
134
+ /**
135
+ * Events - Track and analyze custom events.
136
+ *
137
+ * @extends FTRPC
138
+ *
139
+ * @description
140
+ * Provides flexible custom event tracking including:
141
+ * - Standard event tracking with categories
142
+ * - Click and interaction tracking
143
+ * - Form submission tracking
144
+ * - Search event tracking
145
+ * - Error and exception logging
146
+ * - Batch event submission
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * const events = new Events(webId, endpoint, apiKey);
151
+ *
152
+ * // Track feature usage
153
+ * await events.track({
154
+ * eventName: 'feature_used',
155
+ * category: 'features',
156
+ * action: 'use',
157
+ * label: 'export_pdf',
158
+ * properties: { format: 'A4', pages: 5 }
159
+ * });
160
+ *
161
+ * // Get event analytics
162
+ * const analytics = await events.getAnalytics({ range: 'last7days' });
163
+ * ```
164
+ */
165
+ export declare class Events extends FTRPC {
166
+ /**
167
+ * Tracks a custom event.
168
+ *
169
+ * @param config - Event configuration
170
+ * @returns Promise resolving to event response
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * await events.track({
175
+ * eventName: 'upgrade_clicked',
176
+ * category: 'monetization',
177
+ * action: 'click',
178
+ * label: 'pricing_page',
179
+ * value: 99.99
180
+ * });
181
+ * ```
182
+ */
183
+ track(config: EventTrackConfig): Promise<EventResponse>;
184
+ /**
185
+ * Tracks multiple events in a single request.
186
+ *
187
+ * @param config - Batch configuration with events array
188
+ * @returns Promise resolving to batch response
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * await events.trackBatch({
193
+ * events: [
194
+ * { eventName: 'step_1_complete', category: 'onboarding' },
195
+ * { eventName: 'step_2_complete', category: 'onboarding' },
196
+ * { eventName: 'step_3_complete', category: 'onboarding' }
197
+ * ]
198
+ * });
199
+ * ```
200
+ */
201
+ trackBatch(config: BatchEventConfig): Promise<BatchEventResponse>;
202
+ /**
203
+ * Tracks a click/interaction event.
204
+ *
205
+ * @param config - Click event configuration
206
+ * @returns Promise resolving to event response
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * document.addEventListener('click', (e) => {
211
+ * if (e.target.dataset.track) {
212
+ * events.trackClick({
213
+ * elementId: e.target.id,
214
+ * elementText: e.target.textContent,
215
+ * targetUrl: e.target.href
216
+ * });
217
+ * }
218
+ * });
219
+ * ```
220
+ */
221
+ trackClick(config: ClickEvent): Promise<EventResponse>;
222
+ /**
223
+ * Tracks a form submission event.
224
+ *
225
+ * @param config - Form event configuration
226
+ * @returns Promise resolving to event response
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * form.addEventListener('submit', async (e) => {
231
+ * await events.trackForm({
232
+ * formId: 'contact-form',
233
+ * formName: 'Contact Us',
234
+ * success: true,
235
+ * fields: ['name', 'email', 'message'],
236
+ * completionTime: 45
237
+ * });
238
+ * });
239
+ * ```
240
+ */
241
+ trackForm(config: FormEvent): Promise<EventResponse>;
242
+ /**
243
+ * Tracks a search event.
244
+ *
245
+ * @param config - Search event configuration
246
+ * @returns Promise resolving to event response
247
+ *
248
+ * @example
249
+ * ```typescript
250
+ * await events.trackSearch({
251
+ * query: 'wireless headphones',
252
+ * category: 'products',
253
+ * resultsCount: 42,
254
+ * filters: { brand: 'Sony', priceRange: '100-200' }
255
+ * });
256
+ * ```
257
+ */
258
+ trackSearch(config: SearchEvent): Promise<EventResponse>;
259
+ /**
260
+ * Tracks an error or exception.
261
+ *
262
+ * @param config - Error event configuration
263
+ * @returns Promise resolving to event response
264
+ *
265
+ * @example
266
+ * ```typescript
267
+ * window.onerror = (message, source, line, col, error) => {
268
+ * events.trackError({
269
+ * message: message.toString(),
270
+ * stack: error?.stack,
271
+ * type: error?.name,
272
+ * fatal: false,
273
+ * context: source
274
+ * });
275
+ * };
276
+ * ```
277
+ */
278
+ trackError(config: ErrorEvent): Promise<EventResponse>;
279
+ /**
280
+ * Retrieves event analytics data for dashboards and charts.
281
+ *
282
+ * @param filter - Date range filter
283
+ * @param pagination - Pagination options
284
+ * @returns Promise resolving to event analytics
285
+ *
286
+ * @example
287
+ * ```typescript
288
+ * const analytics = await events.getAnalytics({
289
+ * range: 'last7days'
290
+ * });
291
+ *
292
+ * // Bar chart data - top events
293
+ * const barData = analytics.topEvents.map(e => ({
294
+ * x: e.eventName,
295
+ * y: e.count
296
+ * }));
297
+ *
298
+ * // Line chart - events over time
299
+ * const lineData = analytics.timeSeries.data;
300
+ * ```
301
+ */
302
+ getAnalytics(filter?: DateRangeFilter, pagination?: PaginationParams): Promise<EventAnalyticsData>;
303
+ }
304
+ export default Events;
@@ -0,0 +1,291 @@
1
+ /**
2
+ * @fileoverview Product Analytics - Funnel Analysis
3
+ * @module features/analytics/funnels
4
+ *
5
+ * @description
6
+ * Define and analyze conversion funnels to understand user journeys,
7
+ * identify drop-off points, and optimize conversion rates.
8
+ *
9
+ * @useCases
10
+ * - Track signup/onboarding completion rates
11
+ * - Analyze checkout funnel performance
12
+ * - Identify where users drop off in key flows
13
+ * - Compare funnel performance across segments
14
+ * - A/B test different funnel variations
15
+ *
16
+ * @metrics
17
+ * - Step-by-step conversion rates
18
+ * - Drop-off rates at each step
19
+ * - Time to complete each step
20
+ * - Overall funnel conversion rate
21
+ * - Funnel completion time
22
+ *
23
+ * @chartData
24
+ * - Funnel chart: Step-by-step visualization
25
+ * - Bar chart: Conversion by step
26
+ * - Line chart: Funnel performance over time
27
+ * - Comparison: Funnel variants side-by-side
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const funnels = new Funnels(webId, endpoint, apiKey);
32
+ *
33
+ * // Track funnel step
34
+ * await funnels.trackStep({
35
+ * funnelId: 'checkout_funnel',
36
+ * step: 'add_payment',
37
+ * stepNumber: 3,
38
+ * userId: 'user_123'
39
+ * });
40
+ *
41
+ * // Get funnel analysis
42
+ * const analysis = await funnels.analyze('checkout_funnel');
43
+ * ```
44
+ */
45
+ import { FTRPC } from "../../client/ftrpc";
46
+ import { FunnelAnalysis, DateRangeFilter, TimeSeriesData } from "../../types";
47
+ /**
48
+ * Funnel definition configuration.
49
+ */
50
+ export interface FunnelDefinition {
51
+ /** Unique funnel identifier */
52
+ funnelId: string;
53
+ /** Funnel name for display */
54
+ name: string;
55
+ /** Funnel description */
56
+ description?: string;
57
+ /** Ordered list of step definitions */
58
+ steps: Array<{
59
+ /** Step name */
60
+ name: string;
61
+ /** Event(s) that trigger this step */
62
+ events: string[];
63
+ /** Step description */
64
+ description?: string;
65
+ /** Whether step is optional */
66
+ optional?: boolean;
67
+ }>;
68
+ }
69
+ /**
70
+ * Configuration for tracking a funnel step.
71
+ */
72
+ export interface FunnelStepConfig {
73
+ /** Funnel identifier */
74
+ funnelId: string;
75
+ /** Step name or event */
76
+ step: string;
77
+ /** Step number (1-indexed) */
78
+ stepNumber: number;
79
+ /** User ID */
80
+ userId?: string;
81
+ /** Session ID */
82
+ sessionId?: string;
83
+ /** Custom properties */
84
+ properties?: Record<string, unknown>;
85
+ }
86
+ /**
87
+ * Funnel step response from API.
88
+ */
89
+ export interface FunnelStepResponse {
90
+ eventName: string;
91
+ properties: Record<string, unknown>;
92
+ response: {
93
+ funnelId: string;
94
+ step: string;
95
+ tracked: boolean;
96
+ previousStep?: string;
97
+ timeFromPrevious?: number;
98
+ };
99
+ timestamp: string;
100
+ }
101
+ /**
102
+ * Funnel analytics data for charts.
103
+ */
104
+ export interface FunnelAnalyticsData {
105
+ /** Funnel definition */
106
+ funnel: FunnelDefinition;
107
+ /** Analysis results */
108
+ analysis: FunnelAnalysis;
109
+ /** Step-by-step data for visualization */
110
+ visualization: Array<{
111
+ step: string;
112
+ entered: number;
113
+ completed: number;
114
+ conversionRate: number;
115
+ dropOffRate: number;
116
+ avgTime: number;
117
+ }>;
118
+ /** Performance over time */
119
+ trendData: TimeSeriesData;
120
+ }
121
+ /**
122
+ * Funnel comparison data.
123
+ */
124
+ export interface FunnelComparisonData {
125
+ /** Base funnel data */
126
+ baseline: FunnelAnalyticsData;
127
+ /** Comparison funnel data */
128
+ comparison: FunnelAnalyticsData;
129
+ /** Step-by-step comparison */
130
+ stepComparison: Array<{
131
+ step: string;
132
+ baselineRate: number;
133
+ comparisonRate: number;
134
+ difference: number;
135
+ significant: boolean;
136
+ }>;
137
+ }
138
+ /**
139
+ * Funnels - Define and analyze conversion funnels.
140
+ *
141
+ * @extends FTRPC
142
+ *
143
+ * @description
144
+ * Provides funnel analysis capabilities including:
145
+ * - Funnel definition and management
146
+ * - Step-by-step event tracking
147
+ * - Conversion and drop-off analysis
148
+ * - Time-to-completion tracking
149
+ * - Segment-based funnel comparison
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * const funnels = new Funnels(webId, endpoint, apiKey);
154
+ *
155
+ * // Define a signup funnel
156
+ * await funnels.define({
157
+ * funnelId: 'signup_funnel',
158
+ * name: 'User Signup',
159
+ * steps: [
160
+ * { name: 'Visit Landing', events: ['page_view_landing'] },
161
+ * { name: 'Click Signup', events: ['signup_clicked'] },
162
+ * { name: 'Submit Form', events: ['signup_submitted'] },
163
+ * { name: 'Verify Email', events: ['email_verified'] }
164
+ * ]
165
+ * });
166
+ *
167
+ * // Analyze funnel performance
168
+ * const analysis = await funnels.analyze('signup_funnel', {
169
+ * range: 'last30days'
170
+ * });
171
+ * ```
172
+ */
173
+ export declare class Funnels extends FTRPC {
174
+ /**
175
+ * Defines a new funnel or updates existing.
176
+ *
177
+ * @param config - Funnel definition
178
+ * @returns Promise resolving to definition response
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * await funnels.define({
183
+ * funnelId: 'checkout_funnel',
184
+ * name: 'Checkout Flow',
185
+ * steps: [
186
+ * { name: 'View Cart', events: ['view_cart'] },
187
+ * { name: 'Begin Checkout', events: ['begin_checkout'] },
188
+ * { name: 'Add Shipping', events: ['add_shipping_info'] },
189
+ * { name: 'Add Payment', events: ['add_payment_info'] },
190
+ * { name: 'Purchase', events: ['purchase'] }
191
+ * ]
192
+ * });
193
+ * ```
194
+ */
195
+ define(config: FunnelDefinition): Promise<FunnelStepResponse>;
196
+ /**
197
+ * Tracks a funnel step completion.
198
+ *
199
+ * @param config - Funnel step configuration
200
+ * @returns Promise resolving to step response
201
+ *
202
+ * @example
203
+ * ```typescript
204
+ * // Track user progressing through checkout
205
+ * await funnels.trackStep({
206
+ * funnelId: 'checkout_funnel',
207
+ * step: 'add_shipping_info',
208
+ * stepNumber: 3,
209
+ * userId: 'user_123',
210
+ * properties: { shippingMethod: 'express' }
211
+ * });
212
+ * ```
213
+ */
214
+ trackStep(config: FunnelStepConfig): Promise<FunnelStepResponse>;
215
+ /**
216
+ * Tracks funnel completion.
217
+ *
218
+ * @param funnelId - Funnel identifier
219
+ * @param userId - User who completed
220
+ * @param properties - Completion properties
221
+ * @returns Promise resolving to completion response
222
+ */
223
+ trackComplete(funnelId: string, userId?: string, properties?: Record<string, unknown>): Promise<FunnelStepResponse>;
224
+ /**
225
+ * Tracks funnel abandonment.
226
+ *
227
+ * @param funnelId - Funnel identifier
228
+ * @param lastStep - Last completed step
229
+ * @param userId - User who abandoned
230
+ * @param reason - Optional abandonment reason
231
+ * @returns Promise resolving to abandonment response
232
+ */
233
+ trackAbandon(funnelId: string, lastStep: string, userId?: string, reason?: string): Promise<FunnelStepResponse>;
234
+ /**
235
+ * Analyzes funnel performance.
236
+ *
237
+ * @param funnelId - Funnel identifier
238
+ * @param filter - Date range filter
239
+ * @returns Promise resolving to funnel analytics
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * const analysis = await funnels.analyze('checkout_funnel', {
244
+ * range: 'last7days'
245
+ * });
246
+ *
247
+ * // Funnel visualization data
248
+ * const funnelData = analysis.visualization.map(step => ({
249
+ * name: step.step,
250
+ * value: step.entered,
251
+ * conversion: step.conversionRate
252
+ * }));
253
+ *
254
+ * // Overall conversion rate
255
+ * console.log(`Conversion: ${analysis.analysis.overallConversionRate}%`);
256
+ * ```
257
+ */
258
+ analyze(funnelId: string, filter?: DateRangeFilter): Promise<FunnelAnalyticsData>;
259
+ /**
260
+ * Compares two funnel periods or segments.
261
+ *
262
+ * @param funnelId - Funnel identifier
263
+ * @param baselineFilter - Baseline period filter
264
+ * @param comparisonFilter - Comparison period filter
265
+ * @returns Promise resolving to comparison data
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * const comparison = await funnels.compare(
270
+ * 'checkout_funnel',
271
+ * { range: 'last30days' },
272
+ * { range: 'last60days' }
273
+ * );
274
+ *
275
+ * // Side-by-side comparison chart
276
+ * const comparisonData = comparison.stepComparison.map(s => ({
277
+ * step: s.step,
278
+ * baseline: s.baselineRate,
279
+ * comparison: s.comparisonRate
280
+ * }));
281
+ * ```
282
+ */
283
+ compare(funnelId: string, baselineFilter: DateRangeFilter, comparisonFilter: DateRangeFilter): Promise<FunnelComparisonData>;
284
+ /**
285
+ * Lists all defined funnels.
286
+ *
287
+ * @returns Promise resolving to funnel list
288
+ */
289
+ list(): Promise<FunnelDefinition[]>;
290
+ }
291
+ export default Funnels;