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,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview FlowGrid SDK - Next.js Server Utilities
|
|
3
|
+
* @module frameworks/nextjs/server
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Server-side utilities for Next.js API Routes, Server Actions,
|
|
7
|
+
* and Server Components.
|
|
8
|
+
*
|
|
9
|
+
* ⚠️ IMPORTANT: Never expose your API key on the client.
|
|
10
|
+
* Use environment variables without NEXT_PUBLIC_ prefix for server-only keys.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // app/api/track/route.ts
|
|
15
|
+
* import { flowgrid } from 'flowgrid-sdk/nextjs/server';
|
|
16
|
+
*
|
|
17
|
+
* export async function POST(request: Request) {
|
|
18
|
+
* const { event, properties } = await request.json();
|
|
19
|
+
* await flowgrid.events.track({ name: event, properties });
|
|
20
|
+
* return Response.json({ success: true });
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
import { Activation, TrackFeature, TrackPrompt, Experiment, FeatureFlag, PageViews, Sessions, Events, Identify, Funnels, Purchases, Subscriptions, CustomerLTV } from '../../../index';
|
|
25
|
+
export interface ServerFlowGridConfig {
|
|
26
|
+
webId: string;
|
|
27
|
+
endpoint: string;
|
|
28
|
+
apiKey: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ServerFlowGridInstance {
|
|
31
|
+
activation: Activation;
|
|
32
|
+
trackFeature: TrackFeature;
|
|
33
|
+
trackPrompt: TrackPrompt;
|
|
34
|
+
experiment: Experiment;
|
|
35
|
+
featureFlag: FeatureFlag;
|
|
36
|
+
pageViews: PageViews;
|
|
37
|
+
sessions: Sessions;
|
|
38
|
+
events: Events;
|
|
39
|
+
identify: Identify;
|
|
40
|
+
funnels: Funnels;
|
|
41
|
+
purchases: Purchases;
|
|
42
|
+
subscriptions: Subscriptions;
|
|
43
|
+
customerLTV: CustomerLTV;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a server-side FlowGrid instance.
|
|
47
|
+
* Uses environment variables by default.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* // lib/flowgrid.ts
|
|
52
|
+
* import { createServerFlowGrid } from 'flowgrid-sdk/nextjs/server';
|
|
53
|
+
*
|
|
54
|
+
* export const flowgrid = createServerFlowGrid({
|
|
55
|
+
* webId: process.env.FLOWGRID_WEB_ID!,
|
|
56
|
+
* endpoint: process.env.FLOWGRID_ENDPOINT!,
|
|
57
|
+
* apiKey: process.env.FLOWGRID_API_KEY!, // Server-only!
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function createServerFlowGrid(config: ServerFlowGridConfig): ServerFlowGridInstance;
|
|
62
|
+
/**
|
|
63
|
+
* Get or create a singleton server instance.
|
|
64
|
+
* Uses environment variables.
|
|
65
|
+
*/
|
|
66
|
+
export declare function getServerFlowGrid(): ServerFlowGridInstance;
|
|
67
|
+
export declare const flowgrid: {
|
|
68
|
+
readonly events: Events;
|
|
69
|
+
readonly identify: Identify;
|
|
70
|
+
readonly purchases: Purchases;
|
|
71
|
+
readonly subscriptions: Subscriptions;
|
|
72
|
+
readonly experiment: Experiment;
|
|
73
|
+
readonly featureFlag: FeatureFlag;
|
|
74
|
+
readonly activation: Activation;
|
|
75
|
+
readonly trackFeature: TrackFeature;
|
|
76
|
+
readonly trackPrompt: TrackPrompt;
|
|
77
|
+
readonly funnels: Funnels;
|
|
78
|
+
readonly customerLTV: CustomerLTV;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Track an event from an API route.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* // app/api/track/route.ts
|
|
86
|
+
* import { trackServerEvent } from 'flowgrid-sdk/nextjs/server';
|
|
87
|
+
*
|
|
88
|
+
* export async function POST(request: Request) {
|
|
89
|
+
* const { event, properties, userId } = await request.json();
|
|
90
|
+
*
|
|
91
|
+
* await trackServerEvent(event, properties, userId);
|
|
92
|
+
*
|
|
93
|
+
* return Response.json({ success: true });
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function trackServerEvent(eventName: string, properties?: Record<string, unknown>, userId?: string): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Identify a user from server-side.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* // After user signs up
|
|
104
|
+
* await identifyServerUser(user.id, {
|
|
105
|
+
* email: user.email,
|
|
106
|
+
* plan: user.plan,
|
|
107
|
+
* signupDate: new Date().toISOString()
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export declare function identifyServerUser(userId: string, traits?: Record<string, unknown>): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Track a server-side purchase.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* // In your payment webhook handler
|
|
118
|
+
* await trackServerPurchase({
|
|
119
|
+
* orderId: 'ORD-123',
|
|
120
|
+
* userId: 'user_456',
|
|
121
|
+
* revenue: 9999,
|
|
122
|
+
* currency: 'USD',
|
|
123
|
+
* items: [{ id: 'prod_1', name: 'Widget', price: 4999, quantity: 2 }]
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function trackServerPurchase(order: {
|
|
128
|
+
orderId: string;
|
|
129
|
+
userId?: string;
|
|
130
|
+
revenue: number;
|
|
131
|
+
currency?: string;
|
|
132
|
+
items: Array<{
|
|
133
|
+
id: string;
|
|
134
|
+
name: string;
|
|
135
|
+
price: number;
|
|
136
|
+
quantity: number;
|
|
137
|
+
}>;
|
|
138
|
+
}): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Evaluate a feature flag server-side.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* // In a Server Component or API route
|
|
145
|
+
* const isEnabled = await evaluateServerFlag('new_feature', userId);
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export declare function evaluateServerFlag(flagKey: string, userId?: string, context?: Record<string, unknown>): Promise<boolean>;
|
|
149
|
+
/**
|
|
150
|
+
* Get experiment variant server-side.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* // In a Server Component
|
|
155
|
+
* const variant = await getServerExperimentVariant('checkout_v2', userId);
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare function getServerExperimentVariant(experimentId: string, userId: string): Promise<string>;
|
|
159
|
+
/**
|
|
160
|
+
* Create a tracked server action.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* // app/actions.ts
|
|
165
|
+
* 'use server';
|
|
166
|
+
* import { createTrackedAction } from 'flowgrid-sdk/nextjs/server';
|
|
167
|
+
*
|
|
168
|
+
* export const submitForm = createTrackedAction(
|
|
169
|
+
* 'form_submitted',
|
|
170
|
+
* async (formData: FormData) => {
|
|
171
|
+
* // Your action logic
|
|
172
|
+
* return { success: true };
|
|
173
|
+
* }
|
|
174
|
+
* );
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
export declare function createTrackedAction<T extends (...args: any[]) => Promise<any>>(eventName: string, action: T, getProperties?: (...args: Parameters<T>) => Record<string, unknown>): T;
|
|
178
|
+
declare const _default: {
|
|
179
|
+
createServerFlowGrid: typeof createServerFlowGrid;
|
|
180
|
+
getServerFlowGrid: typeof getServerFlowGrid;
|
|
181
|
+
flowgrid: {
|
|
182
|
+
readonly events: Events;
|
|
183
|
+
readonly identify: Identify;
|
|
184
|
+
readonly purchases: Purchases;
|
|
185
|
+
readonly subscriptions: Subscriptions;
|
|
186
|
+
readonly experiment: Experiment;
|
|
187
|
+
readonly featureFlag: FeatureFlag;
|
|
188
|
+
readonly activation: Activation;
|
|
189
|
+
readonly trackFeature: TrackFeature;
|
|
190
|
+
readonly trackPrompt: TrackPrompt;
|
|
191
|
+
readonly funnels: Funnels;
|
|
192
|
+
readonly customerLTV: CustomerLTV;
|
|
193
|
+
};
|
|
194
|
+
trackServerEvent: typeof trackServerEvent;
|
|
195
|
+
identifyServerUser: typeof identifyServerUser;
|
|
196
|
+
trackServerPurchase: typeof trackServerPurchase;
|
|
197
|
+
evaluateServerFlag: typeof evaluateServerFlag;
|
|
198
|
+
getServerExperimentVariant: typeof getServerExperimentVariant;
|
|
199
|
+
createTrackedAction: typeof createTrackedAction;
|
|
200
|
+
};
|
|
201
|
+
export default _default;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview FlowGrid SDK - Node.js Integration
|
|
3
|
+
* @module frameworks/node
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Node.js SDK for server-side event tracking.
|
|
7
|
+
* Use in Express, Fastify, Hono, or any Node.js backend.
|
|
8
|
+
*
|
|
9
|
+
* ⚠️ All operations are server-side. Never expose your API key.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Basic usage
|
|
14
|
+
* import { FlowGrid } from 'flowgrid-sdk/node';
|
|
15
|
+
*
|
|
16
|
+
* const flowgrid = new FlowGrid({
|
|
17
|
+
* webId: process.env.FLOWGRID_WEB_ID!,
|
|
18
|
+
* endpoint: process.env.FLOWGRID_ENDPOINT!,
|
|
19
|
+
* apiKey: process.env.FLOWGRID_API_KEY!,
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Track event
|
|
23
|
+
* await flowgrid.track('user_signed_up', { userId: 'user_123' });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
import { Activation, TrackFeature, TrackPrompt, Experiment, FeatureFlag, Events, Identify, Funnels, Purchases, Refunds, Subscriptions, CustomerLTV, Inventory } from '../../../index';
|
|
27
|
+
export interface FlowGridConfig {
|
|
28
|
+
webId: string;
|
|
29
|
+
endpoint: string;
|
|
30
|
+
apiKey: string;
|
|
31
|
+
/** Flush events in batches (default: true) */
|
|
32
|
+
batchEvents?: boolean;
|
|
33
|
+
/** Batch size before auto-flush (default: 100) */
|
|
34
|
+
batchSize?: number;
|
|
35
|
+
/** Flush interval in ms (default: 5000) */
|
|
36
|
+
flushInterval?: number;
|
|
37
|
+
/** Enable debug logging (default: false) */
|
|
38
|
+
debug?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface EventData {
|
|
41
|
+
name: string;
|
|
42
|
+
properties?: Record<string, unknown>;
|
|
43
|
+
userId?: string;
|
|
44
|
+
timestamp?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface UserTraits {
|
|
47
|
+
email?: string;
|
|
48
|
+
name?: string;
|
|
49
|
+
plan?: string;
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* FlowGrid Node.js SDK.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { FlowGrid } from 'flowgrid-sdk/node';
|
|
58
|
+
*
|
|
59
|
+
* const flowgrid = new FlowGrid({
|
|
60
|
+
* webId: process.env.FLOWGRID_WEB_ID!,
|
|
61
|
+
* endpoint: process.env.FLOWGRID_ENDPOINT!,
|
|
62
|
+
* apiKey: process.env.FLOWGRID_API_KEY!,
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // Track events
|
|
66
|
+
* await flowgrid.track('order_placed', {
|
|
67
|
+
* orderId: 'ORD-123',
|
|
68
|
+
* userId: 'user_456',
|
|
69
|
+
* value: 9999
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* // Identify users
|
|
73
|
+
* await flowgrid.identify('user_456', {
|
|
74
|
+
* email: 'user@example.com',
|
|
75
|
+
* plan: 'pro'
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* // Flush before shutdown
|
|
79
|
+
* await flowgrid.flush();
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare class FlowGrid {
|
|
83
|
+
private config;
|
|
84
|
+
private eventQueue;
|
|
85
|
+
private flushTimer;
|
|
86
|
+
readonly activation: Activation;
|
|
87
|
+
readonly trackFeature: TrackFeature;
|
|
88
|
+
readonly trackPrompt: TrackPrompt;
|
|
89
|
+
readonly experiment: Experiment;
|
|
90
|
+
readonly featureFlag: FeatureFlag;
|
|
91
|
+
readonly events: Events;
|
|
92
|
+
readonly identify: Identify;
|
|
93
|
+
readonly funnels: Funnels;
|
|
94
|
+
readonly purchases: Purchases;
|
|
95
|
+
readonly refunds: Refunds;
|
|
96
|
+
readonly subscriptions: Subscriptions;
|
|
97
|
+
readonly customerLTV: CustomerLTV;
|
|
98
|
+
readonly inventory: Inventory;
|
|
99
|
+
constructor(config: FlowGridConfig);
|
|
100
|
+
private log;
|
|
101
|
+
private startFlushTimer;
|
|
102
|
+
/**
|
|
103
|
+
* Track an event.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* await flowgrid.track('button_clicked', {
|
|
108
|
+
* buttonId: 'cta',
|
|
109
|
+
* userId: 'user_123'
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
track(eventName: string, properties?: Record<string, unknown>): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Identify a user with traits.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* await flowgrid.identifyUser('user_123', {
|
|
120
|
+
* email: 'user@example.com',
|
|
121
|
+
* plan: 'pro',
|
|
122
|
+
* company: 'Acme Inc'
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
identifyUser(userId: string, traits?: UserTraits): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Alias one user ID to another.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* // After user logs in, link anonymous to known ID
|
|
133
|
+
* await flowgrid.alias('anon_abc123', 'user_456');
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
alias(previousId: string, newId: string): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Flush all queued events.
|
|
139
|
+
* Call before process exit.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* // Before shutdown
|
|
144
|
+
* await flowgrid.flush();
|
|
145
|
+
* process.exit(0);
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
flush(): Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* Shutdown the SDK gracefully.
|
|
151
|
+
* Flushes remaining events and clears timers.
|
|
152
|
+
*/
|
|
153
|
+
shutdown(): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* Track a purchase/order.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* await flowgrid.trackPurchase({
|
|
160
|
+
* orderId: 'ORD-12345',
|
|
161
|
+
* userId: 'user_123',
|
|
162
|
+
* revenue: 9999, // in cents
|
|
163
|
+
* currency: 'USD',
|
|
164
|
+
* items: [
|
|
165
|
+
* { id: 'prod_1', name: 'Widget', price: 4999, quantity: 2 }
|
|
166
|
+
* ]
|
|
167
|
+
* });
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
trackPurchase(order: {
|
|
171
|
+
orderId: string;
|
|
172
|
+
userId?: string;
|
|
173
|
+
revenue: number;
|
|
174
|
+
currency?: string;
|
|
175
|
+
items: Array<{
|
|
176
|
+
id: string;
|
|
177
|
+
name: string;
|
|
178
|
+
price: number;
|
|
179
|
+
quantity: number;
|
|
180
|
+
}>;
|
|
181
|
+
}): Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Track a refund.
|
|
184
|
+
*/
|
|
185
|
+
trackRefund(refund: {
|
|
186
|
+
refundId: string;
|
|
187
|
+
orderId: string;
|
|
188
|
+
amount: number;
|
|
189
|
+
currency: string;
|
|
190
|
+
reason?: string;
|
|
191
|
+
}): Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Track a subscription start.
|
|
194
|
+
*/
|
|
195
|
+
trackSubscriptionStart(sub: {
|
|
196
|
+
subscriptionId: string;
|
|
197
|
+
userId: string;
|
|
198
|
+
plan: string;
|
|
199
|
+
mrr: number;
|
|
200
|
+
currency?: string;
|
|
201
|
+
billingCycle?: 'monthly' | 'quarterly' | 'yearly';
|
|
202
|
+
}): Promise<void>;
|
|
203
|
+
/**
|
|
204
|
+
* Track a subscription cancellation.
|
|
205
|
+
*/
|
|
206
|
+
trackSubscriptionCancel(sub: {
|
|
207
|
+
subscriptionId: string;
|
|
208
|
+
userId: string;
|
|
209
|
+
plan: string;
|
|
210
|
+
lostMrr: number;
|
|
211
|
+
currency?: string;
|
|
212
|
+
reason?: string;
|
|
213
|
+
}): Promise<void>;
|
|
214
|
+
/**
|
|
215
|
+
* Get experiment variant for a user.
|
|
216
|
+
*/
|
|
217
|
+
getExperimentVariant(experimentId: string, userId: string): Promise<string>;
|
|
218
|
+
/**
|
|
219
|
+
* Evaluate a feature flag.
|
|
220
|
+
*/
|
|
221
|
+
evaluateFlag(flagKey: string, userId?: string, defaultValue?: boolean): Promise<boolean>;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Express middleware for automatic request tracking.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* import express from 'express';
|
|
229
|
+
* import { FlowGrid, expressMiddleware } from 'flowgrid-sdk/node';
|
|
230
|
+
*
|
|
231
|
+
* const app = express();
|
|
232
|
+
* const flowgrid = new FlowGrid({ ... });
|
|
233
|
+
*
|
|
234
|
+
* app.use(expressMiddleware(flowgrid));
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
export declare function expressMiddleware(flowgrid: FlowGrid): (req: any, res: any, next: any) => Promise<void>;
|
|
238
|
+
/**
|
|
239
|
+
* Graceful shutdown handler.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* import { FlowGrid, gracefulShutdown } from 'flowgrid-sdk/node';
|
|
244
|
+
*
|
|
245
|
+
* const flowgrid = new FlowGrid({ ... });
|
|
246
|
+
* gracefulShutdown(flowgrid);
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
export declare function gracefulShutdown(flowgrid: FlowGrid): void;
|
|
250
|
+
/**
|
|
251
|
+
* Create a FlowGrid instance.
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* import { createFlowGrid } from 'flowgrid-sdk/node';
|
|
256
|
+
*
|
|
257
|
+
* const flowgrid = createFlowGrid({
|
|
258
|
+
* webId: process.env.FLOWGRID_WEB_ID!,
|
|
259
|
+
* endpoint: process.env.FLOWGRID_ENDPOINT!,
|
|
260
|
+
* apiKey: process.env.FLOWGRID_API_KEY!,
|
|
261
|
+
* });
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
export declare function createFlowGrid(config: FlowGridConfig): FlowGrid;
|
|
265
|
+
export default FlowGrid;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview FlowGrid SDK - Nuxt 3 Integration
|
|
3
|
+
* @module frameworks/nuxt
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Nuxt 3 plugin, composables, and server utilities for FlowGrid SDK.
|
|
7
|
+
* Supports both client-side and server-side tracking.
|
|
8
|
+
*
|
|
9
|
+
* ## File Structure
|
|
10
|
+
*
|
|
11
|
+
* ```
|
|
12
|
+
* your-nuxt-app/
|
|
13
|
+
* ├── plugins/
|
|
14
|
+
* │ └── flowgrid.client.ts # Client-only plugin
|
|
15
|
+
* ├── server/
|
|
16
|
+
* │ └── utils/
|
|
17
|
+
* │ └── flowgrid.ts # Server utilities
|
|
18
|
+
* └── composables/
|
|
19
|
+
* └── useFlowGrid.ts # Auto-imported composable
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* // plugins/flowgrid.client.ts
|
|
25
|
+
* import { FlowGridPlugin } from 'flowgrid-sdk/nuxt';
|
|
26
|
+
*
|
|
27
|
+
* export default defineNuxtPlugin((nuxtApp) => {
|
|
28
|
+
* nuxtApp.vueApp.use(FlowGridPlugin, {
|
|
29
|
+
* webId: useRuntimeConfig().public.flowgridWebId,
|
|
30
|
+
* endpoint: useRuntimeConfig().public.flowgridEndpoint,
|
|
31
|
+
* apiKey: useRuntimeConfig().public.flowgridApiKey,
|
|
32
|
+
* });
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export * from '../vue/index';
|
|
37
|
+
import { type Ref } from 'vue';
|
|
38
|
+
import { Activation, TrackFeature, TrackPrompt, Experiment, FeatureFlag, PageViews, Sessions, Events, Identify, Funnels, Products, CartTracking, Checkout, Purchases, Subscriptions, CustomerLTV } from '../../../index';
|
|
39
|
+
export interface NuxtFlowGridConfig {
|
|
40
|
+
webId: string;
|
|
41
|
+
endpoint: string;
|
|
42
|
+
apiKey: string;
|
|
43
|
+
autoTrackPageViews?: boolean;
|
|
44
|
+
autoTrackSessions?: boolean;
|
|
45
|
+
debug?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create FlowGrid Nuxt plugin.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* // plugins/flowgrid.client.ts
|
|
53
|
+
* import { createFlowGridPlugin } from 'flowgrid-sdk/nuxt';
|
|
54
|
+
*
|
|
55
|
+
* export default defineNuxtPlugin((nuxtApp) => {
|
|
56
|
+
* const config = useRuntimeConfig();
|
|
57
|
+
*
|
|
58
|
+
* const flowgrid = createFlowGridPlugin({
|
|
59
|
+
* webId: config.public.flowgridWebId,
|
|
60
|
+
* endpoint: config.public.flowgridEndpoint,
|
|
61
|
+
* apiKey: config.public.flowgridApiKey,
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* return {
|
|
65
|
+
* provide: {
|
|
66
|
+
* flowgrid
|
|
67
|
+
* }
|
|
68
|
+
* };
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function createFlowGridPlugin(config: NuxtFlowGridConfig): {
|
|
73
|
+
trackEvent: (name: string, properties?: Record<string, unknown>) => Promise<void>;
|
|
74
|
+
identifyUser: (userId: string, traits?: Record<string, unknown>) => Promise<void>;
|
|
75
|
+
activation: Activation;
|
|
76
|
+
trackFeature: TrackFeature;
|
|
77
|
+
trackPrompt: TrackPrompt;
|
|
78
|
+
experiment: Experiment;
|
|
79
|
+
featureFlag: FeatureFlag;
|
|
80
|
+
pageViews: PageViews;
|
|
81
|
+
sessions: Sessions;
|
|
82
|
+
events: Events;
|
|
83
|
+
identify: Identify;
|
|
84
|
+
funnels: Funnels;
|
|
85
|
+
products: Products;
|
|
86
|
+
cart: CartTracking;
|
|
87
|
+
checkout: Checkout;
|
|
88
|
+
purchases: Purchases;
|
|
89
|
+
subscriptions: Subscriptions;
|
|
90
|
+
customerLTV: CustomerLTV;
|
|
91
|
+
isReady: Ref<boolean, boolean>;
|
|
92
|
+
sessionId: Ref<string | null, string | null>;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Composable for accessing FlowGrid in Nuxt.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```vue
|
|
99
|
+
* <script setup>
|
|
100
|
+
* const { $flowgrid } = useNuxtApp();
|
|
101
|
+
* // Or use the provided composable
|
|
102
|
+
* const flowgrid = useNuxtFlowGrid();
|
|
103
|
+
*
|
|
104
|
+
* const handleClick = () => {
|
|
105
|
+
* flowgrid.trackEvent('button_clicked');
|
|
106
|
+
* };
|
|
107
|
+
* </script>
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export declare function useNuxtFlowGrid(): any;
|
|
111
|
+
/**
|
|
112
|
+
* Composable for route-aware page view tracking.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```vue
|
|
116
|
+
* <script setup>
|
|
117
|
+
* // In your app.vue or layout
|
|
118
|
+
* useNuxtPageView();
|
|
119
|
+
* </script>
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare function useNuxtPageView(): void;
|
|
123
|
+
/**
|
|
124
|
+
* Server-side FlowGrid instance for Nuxt server routes.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* // server/utils/flowgrid.ts
|
|
129
|
+
* import { createServerFlowGrid } from 'flowgrid-sdk/nuxt';
|
|
130
|
+
*
|
|
131
|
+
* export const flowgrid = createServerFlowGrid({
|
|
132
|
+
* webId: process.env.FLOWGRID_WEB_ID!,
|
|
133
|
+
* endpoint: process.env.FLOWGRID_ENDPOINT!,
|
|
134
|
+
* apiKey: process.env.FLOWGRID_API_KEY!,
|
|
135
|
+
* });
|
|
136
|
+
*
|
|
137
|
+
* // server/api/track.post.ts
|
|
138
|
+
* export default defineEventHandler(async (event) => {
|
|
139
|
+
* const body = await readBody(event);
|
|
140
|
+
* await flowgrid.events.track({ name: body.event, properties: body.properties });
|
|
141
|
+
* return { success: true };
|
|
142
|
+
* });
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export declare function createServerFlowGrid(config: {
|
|
146
|
+
webId: string;
|
|
147
|
+
endpoint: string;
|
|
148
|
+
apiKey: string;
|
|
149
|
+
}): {
|
|
150
|
+
activation: Activation;
|
|
151
|
+
trackFeature: TrackFeature;
|
|
152
|
+
trackPrompt: TrackPrompt;
|
|
153
|
+
experiment: Experiment;
|
|
154
|
+
featureFlag: FeatureFlag;
|
|
155
|
+
events: Events;
|
|
156
|
+
identify: Identify;
|
|
157
|
+
funnels: Funnels;
|
|
158
|
+
purchases: Purchases;
|
|
159
|
+
subscriptions: Subscriptions;
|
|
160
|
+
customerLTV: CustomerLTV;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Track event from Nuxt server route.
|
|
164
|
+
*/
|
|
165
|
+
export declare function trackNuxtServerEvent(flowgrid: ReturnType<typeof createServerFlowGrid>, eventName: string, properties?: Record<string, unknown>): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* Wrap a Nuxt event handler with tracking.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* // server/api/checkout.post.ts
|
|
172
|
+
* import { withTracking } from 'flowgrid-sdk/nuxt';
|
|
173
|
+
*
|
|
174
|
+
* export default withTracking('checkout_api_called', async (event) => {
|
|
175
|
+
* const body = await readBody(event);
|
|
176
|
+
* // Your logic
|
|
177
|
+
* return { success: true };
|
|
178
|
+
* });
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
export declare function withTracking<T>(eventName: string, handler: (event: any) => Promise<T>): (event: any) => Promise<T>;
|
|
182
|
+
declare const _default: {
|
|
183
|
+
createFlowGridPlugin: typeof createFlowGridPlugin;
|
|
184
|
+
useNuxtFlowGrid: typeof useNuxtFlowGrid;
|
|
185
|
+
useNuxtPageView: typeof useNuxtPageView;
|
|
186
|
+
createServerFlowGrid: typeof createServerFlowGrid;
|
|
187
|
+
trackNuxtServerEvent: typeof trackNuxtServerEvent;
|
|
188
|
+
withTracking: typeof withTracking;
|
|
189
|
+
};
|
|
190
|
+
export default _default;
|