flowgrid-sdk 1.2.1 → 1.3.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/README.md +224 -250
- package/dist/237.flowgrid.min.js +2 -0
- package/dist/237.flowgrid.min.js.map +1 -0
- package/dist/546.flowgrid.min.js +3 -0
- package/dist/546.flowgrid.min.js.LICENSE.txt +14 -0
- package/dist/546.flowgrid.min.js.map +1 -0
- package/dist/EXAMPLE.d.ts +1 -0
- package/dist/EXAMPLE.js +55 -0
- package/dist/EXAMPLE.js.map +1 -0
- package/dist/browser.d.ts +46 -103
- package/dist/browser.js +102 -0
- package/dist/browser.js.map +1 -0
- package/dist/flowgrid.min.js +1 -1
- package/dist/flowgrid.min.js.map +1 -1
- package/dist/index.d.ts +7 -8
- package/dist/index.js +64 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/client/transport.d.ts +14 -4
- package/dist/lib/client/transport.js +432 -0
- package/dist/lib/client/transport.js.map +1 -0
- package/dist/lib/consent/index.d.ts +0 -5
- package/dist/lib/consent/index.js +32 -0
- package/dist/lib/consent/index.js.map +1 -0
- package/dist/lib/consent/manager.js +336 -0
- package/dist/lib/consent/manager.js.map +1 -0
- package/dist/lib/consent/types.d.ts +3 -20
- package/dist/lib/consent/types.js +10 -0
- package/dist/lib/consent/types.js.map +1 -0
- package/dist/lib/features/analytics/attribution.d.ts +6 -47
- package/dist/lib/features/analytics/attribution.js +181 -0
- package/dist/lib/features/analytics/attribution.js.map +1 -0
- package/dist/lib/features/analytics/events.d.ts +1 -28
- package/dist/lib/features/analytics/events.js +256 -0
- package/dist/lib/features/analytics/events.js.map +1 -0
- package/dist/lib/features/analytics/funnels.js +260 -0
- package/dist/lib/features/analytics/funnels.js.map +1 -0
- package/dist/lib/features/analytics/heatmaps.d.ts +12 -19
- package/dist/lib/features/analytics/heatmaps.js +258 -0
- package/dist/lib/features/analytics/heatmaps.js.map +1 -0
- package/dist/lib/features/analytics/identify.d.ts +1 -21
- package/dist/lib/features/analytics/identify.js +213 -0
- package/dist/lib/features/analytics/identify.js.map +1 -0
- package/dist/lib/features/analytics/index.d.ts +2 -0
- package/dist/lib/features/analytics/index.js +15 -0
- package/dist/lib/features/analytics/index.js.map +1 -0
- package/dist/lib/features/analytics/page-views.d.ts +13 -30
- package/dist/lib/features/analytics/page-views.js +268 -0
- package/dist/lib/features/analytics/page-views.js.map +1 -0
- package/dist/lib/features/analytics/performance.d.ts +18 -24
- package/dist/lib/features/analytics/performance.js +232 -0
- package/dist/lib/features/analytics/performance.js.map +1 -0
- package/dist/lib/features/analytics/replay.d.ts +170 -0
- package/dist/lib/features/analytics/replay.js +381 -0
- package/dist/lib/features/analytics/replay.js.map +1 -0
- package/dist/lib/features/analytics/retention.d.ts +1 -76
- package/dist/lib/features/analytics/retention.js +135 -0
- package/dist/lib/features/analytics/retention.js.map +1 -0
- package/dist/lib/features/analytics/sessions.d.ts +12 -37
- package/dist/lib/features/analytics/sessions.js +213 -0
- package/dist/lib/features/analytics/sessions.js.map +1 -0
- package/dist/lib/features/core/activation.d.ts +1 -24
- package/dist/lib/features/core/activation.js +175 -0
- package/dist/lib/features/core/activation.js.map +1 -0
- package/dist/lib/features/core/experiment.d.ts +53 -21
- package/dist/lib/features/core/experiment.js +554 -0
- package/dist/lib/features/core/experiment.js.map +1 -0
- package/dist/lib/features/core/index.js +9 -0
- package/dist/lib/features/core/index.js.map +1 -0
- package/dist/lib/features/core/track-feature.d.ts +1 -8
- package/dist/lib/features/core/track-feature.js +119 -0
- package/dist/lib/features/core/track-feature.js.map +1 -0
- package/dist/lib/features/core/track-prompt.d.ts +5 -8
- package/dist/lib/features/core/track-prompt.js +181 -0
- package/dist/lib/features/core/track-prompt.js.map +1 -0
- package/dist/lib/features/ecommerce/cart.d.ts +1 -24
- package/dist/lib/features/ecommerce/cart.js +244 -0
- package/dist/lib/features/ecommerce/cart.js.map +1 -0
- package/dist/lib/features/ecommerce/checkout.d.ts +1 -28
- package/dist/lib/features/ecommerce/checkout.js +254 -0
- package/dist/lib/features/ecommerce/checkout.js.map +1 -0
- package/dist/lib/features/ecommerce/index.d.ts +0 -2
- package/dist/lib/features/ecommerce/index.js +15 -0
- package/dist/lib/features/ecommerce/index.js.map +1 -0
- package/dist/lib/features/ecommerce/ltv.d.ts +1 -69
- package/dist/lib/features/ecommerce/ltv.js +114 -0
- package/dist/lib/features/ecommerce/ltv.js.map +1 -0
- package/dist/lib/features/ecommerce/products.d.ts +1 -33
- package/dist/lib/features/ecommerce/products.js +223 -0
- package/dist/lib/features/ecommerce/products.js.map +1 -0
- package/dist/lib/features/ecommerce/promotions.d.ts +1 -30
- package/dist/lib/features/ecommerce/promotions.js +197 -0
- package/dist/lib/features/ecommerce/promotions.js.map +1 -0
- package/dist/lib/features/ecommerce/purchases.d.ts +1 -48
- package/dist/lib/features/ecommerce/purchases.js +193 -0
- package/dist/lib/features/ecommerce/purchases.js.map +1 -0
- package/dist/lib/features/ecommerce/refunds.d.ts +1 -27
- package/dist/lib/features/ecommerce/refunds.js +195 -0
- package/dist/lib/features/ecommerce/refunds.js.map +1 -0
- package/dist/lib/features/ecommerce/search.d.ts +1 -24
- package/dist/lib/features/ecommerce/search.js +156 -0
- package/dist/lib/features/ecommerce/search.js.map +1 -0
- package/dist/lib/features/ecommerce/subscriptions.d.ts +1 -28
- package/dist/lib/features/ecommerce/subscriptions.js +207 -0
- package/dist/lib/features/ecommerce/subscriptions.js.map +1 -0
- package/dist/lib/features/ecommerce/wishlist.d.ts +1 -28
- package/dist/lib/features/ecommerce/wishlist.js +186 -0
- package/dist/lib/features/ecommerce/wishlist.js.map +1 -0
- package/dist/lib/features/enterprise/acquisition.d.ts +2 -57
- package/dist/lib/features/enterprise/acquisition.js +166 -0
- package/dist/lib/features/enterprise/acquisition.js.map +1 -0
- package/dist/lib/features/enterprise/alerts.d.ts +1 -37
- package/dist/lib/features/enterprise/alerts.js +246 -0
- package/dist/lib/features/enterprise/alerts.js.map +1 -0
- package/dist/lib/features/enterprise/churn.d.ts +1 -42
- package/dist/lib/features/enterprise/churn.js +175 -0
- package/dist/lib/features/enterprise/churn.js.map +1 -0
- package/dist/lib/features/enterprise/cohorts.d.ts +1 -37
- package/dist/lib/features/enterprise/cohorts.js +201 -0
- package/dist/lib/features/enterprise/cohorts.js.map +1 -0
- package/dist/lib/features/enterprise/engagement.d.ts +40 -46
- package/dist/lib/features/enterprise/engagement.js +335 -0
- package/dist/lib/features/enterprise/engagement.js.map +1 -0
- package/dist/lib/features/enterprise/forecasting.d.ts +0 -50
- package/dist/lib/features/enterprise/forecasting.js +232 -0
- package/dist/lib/features/enterprise/forecasting.js.map +1 -0
- package/dist/lib/features/enterprise/index.d.ts +1 -1
- package/dist/lib/features/enterprise/index.js +76 -0
- package/dist/lib/features/enterprise/index.js.map +1 -0
- package/dist/lib/features/enterprise/monetization.d.ts +1 -60
- package/dist/lib/features/enterprise/monetization.js +146 -0
- package/dist/lib/features/enterprise/monetization.js.map +1 -0
- package/dist/lib/features/enterprise/multi-path-funnels.d.ts +1 -17
- package/dist/lib/features/enterprise/multi-path-funnels.js +205 -0
- package/dist/lib/features/enterprise/multi-path-funnels.js.map +1 -0
- package/dist/lib/features/enterprise/paths.d.ts +1 -56
- package/dist/lib/features/enterprise/paths.js +149 -0
- package/dist/lib/features/enterprise/paths.js.map +1 -0
- package/dist/lib/features/enterprise/security.d.ts +8 -57
- package/dist/lib/features/enterprise/security.js +202 -0
- package/dist/lib/features/enterprise/security.js.map +1 -0
- package/dist/lib/features/enterprise/support.d.ts +3 -42
- package/dist/lib/features/enterprise/support.js +162 -0
- package/dist/lib/features/enterprise/support.js.map +1 -0
- package/dist/lib/flowgrid.d.ts +278 -0
- package/dist/lib/flowgrid.js +323 -0
- package/dist/lib/flowgrid.js.map +1 -0
- package/dist/lib/frameworks/index.d.ts +13 -6
- package/dist/lib/frameworks/index.js +18 -0
- package/dist/lib/frameworks/index.js.map +1 -0
- package/dist/lib/frameworks/nextjs/client.js +355 -0
- package/dist/lib/frameworks/nextjs/client.js.map +1 -0
- package/dist/lib/frameworks/nextjs/index.js +31 -0
- package/dist/lib/frameworks/nextjs/index.js.map +1 -0
- package/dist/lib/frameworks/nextjs/server.js +259 -0
- package/dist/lib/frameworks/nextjs/server.js.map +1 -0
- package/dist/lib/frameworks/node/index.js +391 -0
- package/dist/lib/frameworks/node/index.js.map +1 -0
- package/dist/lib/frameworks/nuxt/index.js +288 -0
- package/dist/lib/frameworks/nuxt/index.js.map +1 -0
- package/dist/lib/frameworks/react/CookieBanner.js +166 -0
- package/dist/lib/frameworks/react/CookieBanner.js.map +1 -0
- package/dist/lib/frameworks/react/index.js +271 -0
- package/dist/lib/frameworks/react/index.js.map +1 -0
- package/dist/lib/frameworks/vue/CookieBanner.js +165 -0
- package/dist/lib/frameworks/vue/CookieBanner.js.map +1 -0
- package/dist/lib/frameworks/vue/index.js +390 -0
- package/dist/lib/frameworks/vue/index.js.map +1 -0
- package/dist/lib/tracking/analytics/attribution.d.ts +14 -0
- package/dist/lib/tracking/analytics/attribution.js +18 -0
- package/dist/lib/tracking/analytics/attribution.js.map +1 -0
- package/dist/lib/tracking/analytics/events.d.ts +26 -0
- package/dist/lib/tracking/analytics/events.js +30 -0
- package/dist/lib/tracking/analytics/events.js.map +1 -0
- package/dist/lib/tracking/analytics/funnels.d.ts +16 -0
- package/dist/lib/tracking/analytics/funnels.js +22 -0
- package/dist/lib/tracking/analytics/funnels.js.map +1 -0
- package/dist/lib/tracking/analytics/heatmaps.d.ts +27 -0
- package/dist/lib/tracking/analytics/heatmaps.js +22 -0
- package/dist/lib/tracking/analytics/heatmaps.js.map +1 -0
- package/dist/lib/tracking/analytics/identify.d.ts +16 -0
- package/dist/lib/tracking/analytics/identify.js +22 -0
- package/dist/lib/tracking/analytics/identify.js.map +1 -0
- package/dist/lib/tracking/analytics/index.d.ts +10 -0
- package/dist/lib/tracking/analytics/index.js +11 -0
- package/dist/lib/tracking/analytics/index.js.map +1 -0
- package/dist/lib/tracking/analytics/page-views.d.ts +29 -0
- package/dist/lib/tracking/analytics/page-views.js +50 -0
- package/dist/lib/tracking/analytics/page-views.js.map +1 -0
- package/dist/lib/tracking/analytics/performance.d.ts +22 -0
- package/dist/lib/tracking/analytics/performance.js +22 -0
- package/dist/lib/tracking/analytics/performance.js.map +1 -0
- package/dist/lib/tracking/analytics/replay.d.ts +34 -0
- package/dist/lib/tracking/analytics/replay.js +46 -0
- package/dist/lib/tracking/analytics/replay.js.map +1 -0
- package/dist/lib/tracking/analytics/retention.d.ts +10 -0
- package/dist/lib/tracking/analytics/retention.js +10 -0
- package/dist/lib/tracking/analytics/retention.js.map +1 -0
- package/dist/lib/tracking/analytics/sessions.d.ts +20 -0
- package/dist/lib/tracking/analytics/sessions.js +26 -0
- package/dist/lib/tracking/analytics/sessions.js.map +1 -0
- package/dist/lib/tracking/core/activation.d.ts +23 -0
- package/dist/lib/tracking/core/activation.js +33 -0
- package/dist/lib/tracking/core/activation.js.map +1 -0
- package/dist/lib/tracking/core/experiment.d.ts +122 -0
- package/dist/lib/tracking/core/experiment.js +150 -0
- package/dist/lib/tracking/core/experiment.js.map +1 -0
- package/dist/lib/tracking/core/feature.d.ts +13 -0
- package/dist/lib/tracking/core/feature.js +14 -0
- package/dist/lib/tracking/core/feature.js.map +1 -0
- package/dist/lib/tracking/core/index.d.ts +4 -0
- package/dist/lib/tracking/core/index.js +5 -0
- package/dist/lib/tracking/core/index.js.map +1 -0
- package/dist/lib/tracking/core/prompt.d.ts +18 -0
- package/dist/lib/tracking/core/prompt.js +26 -0
- package/dist/lib/tracking/core/prompt.js.map +1 -0
- package/dist/lib/tracking/ecommerce/cart.d.ts +17 -0
- package/dist/lib/tracking/ecommerce/cart.js +22 -0
- package/dist/lib/tracking/ecommerce/cart.js.map +1 -0
- package/dist/lib/tracking/ecommerce/checkout.d.ts +17 -0
- package/dist/lib/tracking/ecommerce/checkout.js +22 -0
- package/dist/lib/tracking/ecommerce/checkout.js.map +1 -0
- package/dist/lib/tracking/ecommerce/index.d.ts +10 -0
- package/dist/lib/tracking/ecommerce/index.js +11 -0
- package/dist/lib/tracking/ecommerce/index.js.map +1 -0
- package/dist/lib/tracking/ecommerce/ltv.d.ts +15 -0
- package/dist/lib/tracking/ecommerce/ltv.js +14 -0
- package/dist/lib/tracking/ecommerce/ltv.js.map +1 -0
- package/dist/lib/tracking/ecommerce/products.d.ts +15 -0
- package/dist/lib/tracking/ecommerce/products.js +18 -0
- package/dist/lib/tracking/ecommerce/products.js.map +1 -0
- package/dist/lib/tracking/ecommerce/promotions.d.ts +14 -0
- package/dist/lib/tracking/ecommerce/promotions.js +25 -0
- package/dist/lib/tracking/ecommerce/promotions.js.map +1 -0
- package/dist/lib/tracking/ecommerce/purchases.d.ts +11 -0
- package/dist/lib/tracking/ecommerce/purchases.js +10 -0
- package/dist/lib/tracking/ecommerce/purchases.js.map +1 -0
- package/dist/lib/tracking/ecommerce/refunds.d.ts +17 -0
- package/dist/lib/tracking/ecommerce/refunds.js +22 -0
- package/dist/lib/tracking/ecommerce/refunds.js.map +1 -0
- package/dist/lib/tracking/ecommerce/search.d.ts +24 -0
- package/dist/lib/tracking/ecommerce/search.js +22 -0
- package/dist/lib/tracking/ecommerce/search.js.map +1 -0
- package/dist/lib/tracking/ecommerce/subscriptions.d.ts +21 -0
- package/dist/lib/tracking/ecommerce/subscriptions.js +38 -0
- package/dist/lib/tracking/ecommerce/subscriptions.js.map +1 -0
- package/dist/lib/tracking/ecommerce/wishlist.d.ts +19 -0
- package/dist/lib/tracking/ecommerce/wishlist.js +26 -0
- package/dist/lib/tracking/ecommerce/wishlist.js.map +1 -0
- package/dist/lib/tracking/enterprise/acquisition.d.ts +25 -0
- package/dist/lib/tracking/enterprise/acquisition.js +22 -0
- package/dist/lib/tracking/enterprise/acquisition.js.map +1 -0
- package/dist/lib/tracking/enterprise/alerts.d.ts +32 -0
- package/dist/lib/tracking/enterprise/alerts.js +30 -0
- package/dist/lib/tracking/enterprise/alerts.js.map +1 -0
- package/dist/lib/tracking/enterprise/churn.d.ts +23 -0
- package/dist/lib/tracking/enterprise/churn.js +22 -0
- package/dist/lib/tracking/enterprise/churn.js.map +1 -0
- package/dist/lib/tracking/enterprise/cohorts.d.ts +18 -0
- package/dist/lib/tracking/enterprise/cohorts.js +18 -0
- package/dist/lib/tracking/enterprise/cohorts.js.map +1 -0
- package/dist/lib/tracking/enterprise/engagement.d.ts +31 -0
- package/dist/lib/tracking/enterprise/engagement.js +44 -0
- package/dist/lib/tracking/enterprise/engagement.js.map +1 -0
- package/dist/lib/tracking/enterprise/forecasting.d.ts +18 -0
- package/dist/lib/tracking/enterprise/forecasting.js +22 -0
- package/dist/lib/tracking/enterprise/forecasting.js.map +1 -0
- package/dist/lib/tracking/enterprise/index.d.ts +11 -0
- package/dist/lib/tracking/enterprise/index.js +12 -0
- package/dist/lib/tracking/enterprise/index.js.map +1 -0
- package/dist/lib/tracking/enterprise/monetization.d.ts +14 -0
- package/dist/lib/tracking/enterprise/monetization.js +10 -0
- package/dist/lib/tracking/enterprise/monetization.js.map +1 -0
- package/dist/lib/tracking/enterprise/multi-path-funnels.d.ts +20 -0
- package/dist/lib/tracking/enterprise/multi-path-funnels.js +18 -0
- package/dist/lib/tracking/enterprise/multi-path-funnels.js.map +1 -0
- package/dist/lib/tracking/enterprise/paths.d.ts +20 -0
- package/dist/lib/tracking/enterprise/paths.js +18 -0
- package/dist/lib/tracking/enterprise/paths.js.map +1 -0
- package/dist/lib/tracking/enterprise/security.d.ts +28 -0
- package/dist/lib/tracking/enterprise/security.js +26 -0
- package/dist/lib/tracking/enterprise/security.js.map +1 -0
- package/dist/lib/tracking/enterprise/support.d.ts +25 -0
- package/dist/lib/tracking/enterprise/support.js +22 -0
- package/dist/lib/tracking/enterprise/support.js.map +1 -0
- package/dist/lib/tracking/index.d.ts +4 -0
- package/dist/lib/tracking/index.js +5 -0
- package/dist/lib/tracking/index.js.map +1 -0
- package/dist/lib/types/analytics.d.ts +10 -2
- package/dist/lib/types/analytics.js +6 -0
- package/dist/lib/types/analytics.js.map +1 -0
- package/dist/lib/types/common.js +6 -0
- package/dist/lib/types/common.js.map +1 -0
- package/dist/lib/types/ecommerce.js +6 -0
- package/dist/lib/types/ecommerce.js.map +1 -0
- package/dist/lib/types/index.js +8 -0
- package/dist/lib/types/index.js.map +1 -0
- package/dist/lib/utils/browser.d.ts +16 -0
- package/dist/lib/utils/browser.js +32 -0
- package/dist/lib/utils/browser.js.map +1 -0
- package/dist/lib/utils/identity.js +346 -0
- package/dist/lib/utils/identity.js.map +1 -0
- package/dist/lib/utils/storage.js +105 -0
- package/dist/lib/utils/storage.js.map +1 -0
- package/dist/umd/237.index.js +2 -0
- package/dist/umd/237.index.js.map +1 -0
- package/dist/umd/546.index.js +3 -0
- package/dist/umd/546.index.js.LICENSE.txt +14 -0
- package/dist/umd/546.index.js.map +1 -0
- package/dist/umd/index.js +2 -0
- package/dist/umd/index.js.map +1 -0
- package/package.json +27 -80
- package/dist/lib/features/ecommerce/inventory.d.ts +0 -219
|
@@ -0,0 +1,391 @@
|
|
|
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, Events, Identify, Funnels, Purchases, Refunds, Subscriptions, CustomerLTV, Inventory } from '../../../index';
|
|
27
|
+
import { IdentityManager } from '../../utils/identity';
|
|
28
|
+
// ============================================================================
|
|
29
|
+
// MAIN CLASS
|
|
30
|
+
// ============================================================================
|
|
31
|
+
/**
|
|
32
|
+
* FlowGrid Node.js SDK.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { FlowGrid } from 'flowgrid-sdk/node';
|
|
37
|
+
*
|
|
38
|
+
* const flowgrid = new FlowGrid({
|
|
39
|
+
* webId: process.env.FLOWGRID_WEB_ID!,
|
|
40
|
+
* endpoint: process.env.FLOWGRID_ENDPOINT!,
|
|
41
|
+
* apiKey: process.env.FLOWGRID_API_KEY!,
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Track events
|
|
45
|
+
* await flowgrid.track('order_placed', {
|
|
46
|
+
* orderId: 'ORD-123',
|
|
47
|
+
* userId: 'user_456',
|
|
48
|
+
* value: 9999
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* // Identify users
|
|
52
|
+
* await flowgrid.identify('user_456', {
|
|
53
|
+
* email: 'user@example.com',
|
|
54
|
+
* plan: 'pro'
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* // Flush before shutdown
|
|
58
|
+
* await flowgrid.flush();
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export class FlowGrid {
|
|
62
|
+
constructor(config) {
|
|
63
|
+
this.eventQueue = [];
|
|
64
|
+
this.flushTimer = null;
|
|
65
|
+
this.config = {
|
|
66
|
+
batchEvents: true,
|
|
67
|
+
batchSize: 100,
|
|
68
|
+
flushInterval: 5000,
|
|
69
|
+
debug: false,
|
|
70
|
+
...config,
|
|
71
|
+
};
|
|
72
|
+
const { webId, endpoint, apiKey } = config;
|
|
73
|
+
// Create identity manager with memory storage (no cookies in Node)
|
|
74
|
+
const identity = new IdentityManager({
|
|
75
|
+
visitorId: config.visitorId,
|
|
76
|
+
storage: 'memory',
|
|
77
|
+
});
|
|
78
|
+
// Initialize SDK instances
|
|
79
|
+
this.activation = new Activation(webId, endpoint, apiKey, config.visitorId, identity);
|
|
80
|
+
this.trackFeature = new TrackFeature(webId, endpoint, apiKey, config.visitorId, identity);
|
|
81
|
+
this.trackPrompt = new TrackPrompt(webId, endpoint, apiKey, config.visitorId, identity);
|
|
82
|
+
this.experiment = new Experiment(webId, endpoint, apiKey, config.visitorId, identity);
|
|
83
|
+
this.events = new Events(webId, endpoint, apiKey, config.visitorId, identity);
|
|
84
|
+
this.identify = new Identify(webId, endpoint, apiKey, config.visitorId, identity);
|
|
85
|
+
this.funnels = new Funnels(webId, endpoint, apiKey, config.visitorId, identity);
|
|
86
|
+
this.purchases = new Purchases(webId, endpoint, apiKey, config.visitorId, identity);
|
|
87
|
+
this.refunds = new Refunds(webId, endpoint, apiKey, config.visitorId, identity);
|
|
88
|
+
this.subscriptions = new Subscriptions(webId, endpoint, apiKey, config.visitorId, identity);
|
|
89
|
+
this.customerLTV = new CustomerLTV(webId, endpoint, apiKey, config.visitorId, identity);
|
|
90
|
+
this.inventory = new Inventory(webId, endpoint, apiKey, config.visitorId, identity);
|
|
91
|
+
// Start flush timer if batching enabled
|
|
92
|
+
if (this.config.batchEvents) {
|
|
93
|
+
this.startFlushTimer();
|
|
94
|
+
}
|
|
95
|
+
this.log('FlowGrid initialized');
|
|
96
|
+
}
|
|
97
|
+
log(...args) {
|
|
98
|
+
if (this.config.debug) {
|
|
99
|
+
console.log('[FlowGrid]', ...args);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
startFlushTimer() {
|
|
103
|
+
this.flushTimer = setInterval(() => {
|
|
104
|
+
if (this.eventQueue.length > 0) {
|
|
105
|
+
this.flush();
|
|
106
|
+
}
|
|
107
|
+
}, this.config.flushInterval);
|
|
108
|
+
}
|
|
109
|
+
// ============================================================================
|
|
110
|
+
// CORE METHODS
|
|
111
|
+
// ============================================================================
|
|
112
|
+
/**
|
|
113
|
+
* Track an event.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* await flowgrid.track('button_clicked', {
|
|
118
|
+
* buttonId: 'cta',
|
|
119
|
+
* userId: 'user_123'
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
async track(eventName, properties) {
|
|
124
|
+
const event = {
|
|
125
|
+
name: eventName,
|
|
126
|
+
properties,
|
|
127
|
+
timestamp: new Date().toISOString(),
|
|
128
|
+
};
|
|
129
|
+
if (this.config.batchEvents) {
|
|
130
|
+
this.eventQueue.push(event);
|
|
131
|
+
this.log('Event queued:', eventName);
|
|
132
|
+
if (this.eventQueue.length >= (this.config.batchSize || 100)) {
|
|
133
|
+
await this.flush();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
await this.events.track({ eventName, properties: properties || {} });
|
|
138
|
+
this.log('Event sent:', eventName);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Identify a user with traits.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* await flowgrid.identifyUser('user_123', {
|
|
147
|
+
* email: 'user@example.com',
|
|
148
|
+
* plan: 'pro',
|
|
149
|
+
* company: 'Acme Inc'
|
|
150
|
+
* });
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
async identifyUser(userId, traits) {
|
|
154
|
+
await this.identify.user({ userId, traits: traits || {} });
|
|
155
|
+
this.log('User identified:', userId);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Alias one user ID to another.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* // After user logs in, link anonymous to known ID
|
|
163
|
+
* await flowgrid.alias('anon_abc123', 'user_456');
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
async alias(previousId, newId) {
|
|
167
|
+
await this.identify.alias({ previousId, userId: newId });
|
|
168
|
+
this.log('User aliased:', previousId, '->', newId);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Flush all queued events.
|
|
172
|
+
* Call before process exit.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* // Before shutdown
|
|
177
|
+
* await flowgrid.flush();
|
|
178
|
+
* process.exit(0);
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
async flush() {
|
|
182
|
+
if (this.eventQueue.length === 0)
|
|
183
|
+
return;
|
|
184
|
+
const eventsToSend = [...this.eventQueue];
|
|
185
|
+
this.eventQueue = [];
|
|
186
|
+
try {
|
|
187
|
+
await this.events.trackBatch({
|
|
188
|
+
events: eventsToSend.map(e => ({
|
|
189
|
+
eventName: e.name,
|
|
190
|
+
properties: e.properties || {},
|
|
191
|
+
timestamp: e.timestamp,
|
|
192
|
+
}))
|
|
193
|
+
});
|
|
194
|
+
this.log('Flushed', eventsToSend.length, 'events');
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
// Re-queue failed events
|
|
198
|
+
this.eventQueue.push(...eventsToSend);
|
|
199
|
+
this.log('Flush failed, re-queued events:', error);
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Shutdown the SDK gracefully.
|
|
205
|
+
* Flushes remaining events and clears timers.
|
|
206
|
+
*/
|
|
207
|
+
async shutdown() {
|
|
208
|
+
if (this.flushTimer) {
|
|
209
|
+
clearInterval(this.flushTimer);
|
|
210
|
+
this.flushTimer = null;
|
|
211
|
+
}
|
|
212
|
+
await this.flush();
|
|
213
|
+
this.log('Shutdown complete');
|
|
214
|
+
}
|
|
215
|
+
// ============================================================================
|
|
216
|
+
// ECOMMERCE METHODS
|
|
217
|
+
// ============================================================================
|
|
218
|
+
/**
|
|
219
|
+
* Track a purchase/order.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* await flowgrid.trackPurchase({
|
|
224
|
+
* orderId: 'ORD-12345',
|
|
225
|
+
* userId: 'user_123',
|
|
226
|
+
* revenue: 9999, // in cents
|
|
227
|
+
* currency: 'USD',
|
|
228
|
+
* items: [
|
|
229
|
+
* { id: 'prod_1', name: 'Widget', price: 4999, quantity: 2 }
|
|
230
|
+
* ]
|
|
231
|
+
* });
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
async trackPurchase(order) {
|
|
235
|
+
await this.purchases.track({
|
|
236
|
+
order: {
|
|
237
|
+
orderId: order.orderId,
|
|
238
|
+
items: order.items.map(i => ({
|
|
239
|
+
id: i.id,
|
|
240
|
+
productId: i.id,
|
|
241
|
+
name: i.name,
|
|
242
|
+
price: i.price,
|
|
243
|
+
quantity: i.quantity,
|
|
244
|
+
lineTotal: i.price * i.quantity,
|
|
245
|
+
currency: order.currency || 'USD',
|
|
246
|
+
})),
|
|
247
|
+
subtotal: order.revenue,
|
|
248
|
+
discountTotal: 0,
|
|
249
|
+
shippingTotal: 0,
|
|
250
|
+
taxTotal: 0,
|
|
251
|
+
total: order.revenue,
|
|
252
|
+
currency: order.currency || 'USD'
|
|
253
|
+
},
|
|
254
|
+
userId: order.userId,
|
|
255
|
+
});
|
|
256
|
+
this.log('Purchase tracked:', order.orderId);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Track a refund.
|
|
260
|
+
*/
|
|
261
|
+
async trackRefund(refund) {
|
|
262
|
+
await this.refunds.track({
|
|
263
|
+
refundId: refund.refundId,
|
|
264
|
+
orderId: refund.orderId,
|
|
265
|
+
amount: { amount: refund.amount, currency: refund.currency || 'USD' },
|
|
266
|
+
reason: refund.reason,
|
|
267
|
+
currency: refund.currency,
|
|
268
|
+
isFullRefund: false
|
|
269
|
+
});
|
|
270
|
+
this.log('Refund tracked:', refund.refundId);
|
|
271
|
+
}
|
|
272
|
+
// ============================================================================
|
|
273
|
+
// SUBSCRIPTION METHODS
|
|
274
|
+
// ============================================================================
|
|
275
|
+
/**
|
|
276
|
+
* Track a subscription start.
|
|
277
|
+
*/
|
|
278
|
+
async trackSubscriptionStart(sub) {
|
|
279
|
+
await this.subscriptions.start({
|
|
280
|
+
subscriptionId: sub.subscriptionId,
|
|
281
|
+
userId: sub.userId,
|
|
282
|
+
plan: sub.plan,
|
|
283
|
+
mrr: { amount: sub.mrr, currency: sub.currency || 'USD' },
|
|
284
|
+
billingCycle: sub.billingCycle || 'monthly',
|
|
285
|
+
});
|
|
286
|
+
this.log('Subscription started:', sub.subscriptionId);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Track a subscription cancellation.
|
|
290
|
+
*/
|
|
291
|
+
async trackSubscriptionCancel(sub) {
|
|
292
|
+
await this.subscriptions.cancel({
|
|
293
|
+
subscriptionId: sub.subscriptionId,
|
|
294
|
+
userId: sub.userId,
|
|
295
|
+
plan: sub.plan,
|
|
296
|
+
lostMrr: { amount: sub.lostMrr, currency: sub.currency || 'USD' },
|
|
297
|
+
reason: sub.reason,
|
|
298
|
+
immediate: false,
|
|
299
|
+
});
|
|
300
|
+
this.log('Subscription cancelled:', sub.subscriptionId);
|
|
301
|
+
}
|
|
302
|
+
// ============================================================================
|
|
303
|
+
// EXPERIMENT METHODS
|
|
304
|
+
// ============================================================================
|
|
305
|
+
/**
|
|
306
|
+
* Get experiment variant for a user.
|
|
307
|
+
*/
|
|
308
|
+
async getExperimentVariant(experimentId, userId) {
|
|
309
|
+
await this.experiment.trackExposure(experimentId, userId, 'control');
|
|
310
|
+
// In real implementation, this would return actual variant from API
|
|
311
|
+
return 'control';
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
// ============================================================================
|
|
315
|
+
// EXPRESS MIDDLEWARE
|
|
316
|
+
// ============================================================================
|
|
317
|
+
/**
|
|
318
|
+
* Express middleware for automatic request tracking.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```ts
|
|
322
|
+
* import express from 'express';
|
|
323
|
+
* import { FlowGrid, expressMiddleware } from 'flowgrid-sdk/node';
|
|
324
|
+
*
|
|
325
|
+
* const app = express();
|
|
326
|
+
* const flowgrid = new FlowGrid({ ... });
|
|
327
|
+
*
|
|
328
|
+
* app.use(expressMiddleware(flowgrid));
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
export function expressMiddleware(flowgrid) {
|
|
332
|
+
return async (req, res, next) => {
|
|
333
|
+
const startTime = Date.now();
|
|
334
|
+
res.on('finish', async () => {
|
|
335
|
+
await flowgrid.track('http_request', {
|
|
336
|
+
method: req.method,
|
|
337
|
+
path: req.path,
|
|
338
|
+
statusCode: res.statusCode,
|
|
339
|
+
duration: Date.now() - startTime,
|
|
340
|
+
userAgent: req.get('user-agent'),
|
|
341
|
+
userId: req.user?.id, // If using auth middleware
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
next();
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Graceful shutdown handler.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```ts
|
|
352
|
+
* import { FlowGrid, gracefulShutdown } from 'flowgrid-sdk/node';
|
|
353
|
+
*
|
|
354
|
+
* const flowgrid = new FlowGrid({ ... });
|
|
355
|
+
* gracefulShutdown(flowgrid);
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
export function gracefulShutdown(flowgrid) {
|
|
359
|
+
const shutdown = async () => {
|
|
360
|
+
console.log('[FlowGrid] Shutting down...');
|
|
361
|
+
await flowgrid.shutdown();
|
|
362
|
+
process.exit(0);
|
|
363
|
+
};
|
|
364
|
+
process.on('SIGTERM', shutdown);
|
|
365
|
+
process.on('SIGINT', shutdown);
|
|
366
|
+
}
|
|
367
|
+
// ============================================================================
|
|
368
|
+
// FACTORY FUNCTION
|
|
369
|
+
// ============================================================================
|
|
370
|
+
/**
|
|
371
|
+
* Create a FlowGrid instance.
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```ts
|
|
375
|
+
* import { createFlowGrid } from 'flowgrid-sdk/node';
|
|
376
|
+
*
|
|
377
|
+
* const flowgrid = createFlowGrid({
|
|
378
|
+
* webId: process.env.FLOWGRID_WEB_ID!,
|
|
379
|
+
* endpoint: process.env.FLOWGRID_ENDPOINT!,
|
|
380
|
+
* apiKey: process.env.FLOWGRID_API_KEY!,
|
|
381
|
+
* });
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
export function createFlowGrid(config) {
|
|
385
|
+
return new FlowGrid(config);
|
|
386
|
+
}
|
|
387
|
+
// ============================================================================
|
|
388
|
+
// EXPORTS
|
|
389
|
+
// ============================================================================
|
|
390
|
+
export default FlowGrid;
|
|
391
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/frameworks/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EACL,UAAU,EACV,YAAY,EACZ,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,OAAO,EACP,SAAS,EACT,OAAO,EACP,aAAa,EACb,WAAW,EACX,SAAS,EACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAmCvD,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,QAAQ;IAmBnB,YAAY,MAAsB;QAjB1B,eAAU,GAAgB,EAAE,CAAC;QAC7B,eAAU,GAA0B,IAA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AQ,EAAE,CAAC;QAC1B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC;IAEF,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACjC,CAAC;AAED,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,cAAc,CAAC,MAAsB;IACnD,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC;AAED,+EAA+E;AAC/E,UAAU;AACV,+EAA+E;AAE/E,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,288 @@
|
|
|
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
|
+
// Re-export Vue composables (work in Nuxt)
|
|
37
|
+
export * from '../vue/index';
|
|
38
|
+
import { ref, onMounted } from 'vue';
|
|
39
|
+
import { Activation, TrackFeature, TrackPrompt, Experiment, PageViews, Sessions, Events, Identify, Funnels, Products, CartTracking, Checkout, Purchases, Subscriptions, CustomerLTV } from '../../../index';
|
|
40
|
+
import { getVisitorId } from '../../utils/storage';
|
|
41
|
+
import { IdentityManager } from '../../utils/identity';
|
|
42
|
+
// ============================================================================
|
|
43
|
+
// NUXT PLUGIN FACTORY
|
|
44
|
+
// ============================================================================
|
|
45
|
+
/**
|
|
46
|
+
* Create FlowGrid Nuxt plugin.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* // plugins/flowgrid.client.ts
|
|
51
|
+
* import { createFlowGridPlugin } from 'flowgrid-sdk/nuxt';
|
|
52
|
+
*
|
|
53
|
+
* export default defineNuxtPlugin((nuxtApp) => {
|
|
54
|
+
* const config = useRuntimeConfig();
|
|
55
|
+
*
|
|
56
|
+
* const flowgrid = createFlowGridPlugin({
|
|
57
|
+
* webId: config.public.flowgridWebId,
|
|
58
|
+
* endpoint: config.public.flowgridEndpoint,
|
|
59
|
+
* apiKey: config.public.flowgridApiKey,
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* return {
|
|
63
|
+
* provide: {
|
|
64
|
+
* flowgrid
|
|
65
|
+
* }
|
|
66
|
+
* };
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export function createFlowGridPlugin(config) {
|
|
71
|
+
const { webId, endpoint, apiKey, debug = false } = config;
|
|
72
|
+
const isReady = ref(false);
|
|
73
|
+
const sessionId = ref(null);
|
|
74
|
+
// Create identity manager for visitor/session lifecycle
|
|
75
|
+
const identity = new IdentityManager({
|
|
76
|
+
visitorId: config.visitorId || getVisitorId() || undefined,
|
|
77
|
+
});
|
|
78
|
+
const resolvedVisitorId = identity.getVisitorId() || undefined;
|
|
79
|
+
const instance = {
|
|
80
|
+
activation: new Activation(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
81
|
+
trackFeature: new TrackFeature(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
82
|
+
trackPrompt: new TrackPrompt(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
83
|
+
experiment: new Experiment(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
84
|
+
pageViews: new PageViews(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
85
|
+
sessions: new Sessions(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
86
|
+
events: new Events(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
87
|
+
identify: new Identify(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
88
|
+
funnels: new Funnels(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
89
|
+
products: new Products(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
90
|
+
cart: new CartTracking(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
91
|
+
checkout: new Checkout(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
92
|
+
purchases: new Purchases(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
93
|
+
subscriptions: new Subscriptions(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
94
|
+
customerLTV: new CustomerLTV(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
95
|
+
isReady,
|
|
96
|
+
sessionId,
|
|
97
|
+
};
|
|
98
|
+
// Auto-start session on client
|
|
99
|
+
if (typeof window !== 'undefined' && config.autoTrackSessions !== false) {
|
|
100
|
+
instance.sessions.start({
|
|
101
|
+
referrer: document.referrer,
|
|
102
|
+
landingPage: window.location.pathname,
|
|
103
|
+
}).then((result) => {
|
|
104
|
+
sessionId.value = result.response?.sessionId || null;
|
|
105
|
+
isReady.value = true;
|
|
106
|
+
if (debug)
|
|
107
|
+
console.log('[FlowGrid] Session started:', sessionId.value);
|
|
108
|
+
});
|
|
109
|
+
window.addEventListener('beforeunload', () => {
|
|
110
|
+
if (sessionId.value) {
|
|
111
|
+
instance.sessions.end(sessionId.value);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
isReady.value = true;
|
|
117
|
+
}
|
|
118
|
+
// Helper methods
|
|
119
|
+
const trackEvent = async (name, properties) => {
|
|
120
|
+
if (debug)
|
|
121
|
+
console.log('[FlowGrid] Event:', name, properties);
|
|
122
|
+
await instance.events.track({ eventName: name, properties: properties || {} });
|
|
123
|
+
};
|
|
124
|
+
const identifyUser = async (userId, traits) => {
|
|
125
|
+
if (debug)
|
|
126
|
+
console.log('[FlowGrid] Identify:', userId, traits);
|
|
127
|
+
await instance.identify.user({ userId, traits: traits || {} });
|
|
128
|
+
};
|
|
129
|
+
return {
|
|
130
|
+
...instance,
|
|
131
|
+
trackEvent,
|
|
132
|
+
identifyUser,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
// ============================================================================
|
|
136
|
+
// NUXT COMPOSABLES
|
|
137
|
+
// ============================================================================
|
|
138
|
+
/**
|
|
139
|
+
* Composable for accessing FlowGrid in Nuxt.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```vue
|
|
143
|
+
* <script setup>
|
|
144
|
+
* const { $flowgrid } = useNuxtApp();
|
|
145
|
+
* // Or use the provided composable
|
|
146
|
+
* const flowgrid = useNuxtFlowGrid();
|
|
147
|
+
*
|
|
148
|
+
* const handleClick = () => {
|
|
149
|
+
* flowgrid.trackEvent('button_clicked');
|
|
150
|
+
* };
|
|
151
|
+
* </script>
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export function useNuxtFlowGrid() {
|
|
155
|
+
// This would use useNuxtApp() in actual Nuxt context
|
|
156
|
+
// For the SDK, we provide the factory function
|
|
157
|
+
const nuxtApp = globalThis.__nuxt_app__;
|
|
158
|
+
if (!nuxtApp?.$flowgrid) {
|
|
159
|
+
console.warn('[FlowGrid] Plugin not installed. Make sure to add the plugin.');
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
return nuxtApp.$flowgrid;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Composable for route-aware page view tracking.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```vue
|
|
169
|
+
* <script setup>
|
|
170
|
+
* // In your app.vue or layout
|
|
171
|
+
* useNuxtPageView();
|
|
172
|
+
* </script>
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
export function useNuxtPageView() {
|
|
176
|
+
// This would integrate with useRoute() in Nuxt
|
|
177
|
+
onMounted(() => {
|
|
178
|
+
const flowgrid = useNuxtFlowGrid();
|
|
179
|
+
if (!flowgrid)
|
|
180
|
+
return;
|
|
181
|
+
flowgrid.pageViews.track({
|
|
182
|
+
url: window.location.href,
|
|
183
|
+
path: window.location.pathname,
|
|
184
|
+
title: document.title,
|
|
185
|
+
referrer: document.referrer,
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
// ============================================================================
|
|
190
|
+
// SERVER UTILITIES
|
|
191
|
+
// ============================================================================
|
|
192
|
+
/**
|
|
193
|
+
* Server-side FlowGrid instance for Nuxt server routes.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* // server/utils/flowgrid.ts
|
|
198
|
+
* import { createServerFlowGrid } from 'flowgrid-sdk/nuxt';
|
|
199
|
+
*
|
|
200
|
+
* export const flowgrid = createServerFlowGrid({
|
|
201
|
+
* webId: process.env.FLOWGRID_WEB_ID!,
|
|
202
|
+
* endpoint: process.env.FLOWGRID_ENDPOINT!,
|
|
203
|
+
* apiKey: process.env.FLOWGRID_API_KEY!,
|
|
204
|
+
* });
|
|
205
|
+
*
|
|
206
|
+
* // server/api/track.post.ts
|
|
207
|
+
* export default defineEventHandler(async (event) => {
|
|
208
|
+
* const body = await readBody(event);
|
|
209
|
+
* await flowgrid.events.track({ name: body.event, properties: body.properties });
|
|
210
|
+
* return { success: true };
|
|
211
|
+
* });
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
export function createServerFlowGrid(config) {
|
|
215
|
+
const { webId, endpoint, apiKey, visitorId } = config;
|
|
216
|
+
const identity = new IdentityManager({
|
|
217
|
+
visitorId,
|
|
218
|
+
storage: 'memory',
|
|
219
|
+
serverCookies: config.cookies ? { get: (name) => config.cookies.get(name) ?? null } : undefined,
|
|
220
|
+
});
|
|
221
|
+
const resolvedVisitorId = identity.getVisitorId();
|
|
222
|
+
return {
|
|
223
|
+
activation: new Activation(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
224
|
+
trackFeature: new TrackFeature(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
225
|
+
trackPrompt: new TrackPrompt(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
226
|
+
experiment: new Experiment(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
227
|
+
events: new Events(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
228
|
+
identify: new Identify(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
229
|
+
funnels: new Funnels(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
230
|
+
purchases: new Purchases(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
231
|
+
subscriptions: new Subscriptions(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
232
|
+
customerLTV: new CustomerLTV(webId, endpoint, apiKey, resolvedVisitorId, identity),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Track event from Nuxt server route.
|
|
237
|
+
*/
|
|
238
|
+
export async function trackNuxtServerEvent(flowgrid, eventName, properties) {
|
|
239
|
+
await flowgrid.events.track({
|
|
240
|
+
eventName,
|
|
241
|
+
properties: { ...properties, _server: true },
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
// ============================================================================
|
|
245
|
+
// NITRO EVENT HANDLER WRAPPER
|
|
246
|
+
// ============================================================================
|
|
247
|
+
/**
|
|
248
|
+
* Wrap a Nuxt event handler with tracking.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* // server/api/checkout.post.ts
|
|
253
|
+
* import { withTracking } from 'flowgrid-sdk/nuxt';
|
|
254
|
+
*
|
|
255
|
+
* export default withTracking('checkout_api_called', async (event) => {
|
|
256
|
+
* const body = await readBody(event);
|
|
257
|
+
* // Your logic
|
|
258
|
+
* return { success: true };
|
|
259
|
+
* });
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
export function withTracking(eventName, handler) {
|
|
263
|
+
return async (event) => {
|
|
264
|
+
const startTime = Date.now();
|
|
265
|
+
try {
|
|
266
|
+
const result = await handler(event);
|
|
267
|
+
// Would track success here with server flowgrid instance
|
|
268
|
+
console.log(`[FlowGrid] ${eventName} succeeded in ${Date.now() - startTime}ms`);
|
|
269
|
+
return result;
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
console.log(`[FlowGrid] ${eventName} failed in ${Date.now() - startTime}ms`);
|
|
273
|
+
throw error;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
// ============================================================================
|
|
278
|
+
// EXPORTS
|
|
279
|
+
// ============================================================================
|
|
280
|
+
export default {
|
|
281
|
+
createFlowGridPlugin,
|
|
282
|
+
useNuxtFlowGrid,
|
|
283
|
+
useNuxtPageView,
|
|
284
|
+
createServerFlowGrid,
|
|
285
|
+
trackNuxtServerEvent,
|
|
286
|
+
withTracking,
|
|
287
|
+
};
|
|
288
|
+
//# sourceMappingURL=index.js.map
|