flowgrid-sdk 1.1.0 → 1.2.1
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 +320 -8
- package/dist/browser.d.ts +6 -7
- package/dist/flowgrid.min.js +1 -1
- package/dist/flowgrid.min.js.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/client/transport.d.ts +175 -0
- package/dist/lib/consent/index.d.ts +37 -0
- package/dist/lib/consent/manager.d.ts +197 -0
- package/dist/lib/consent/types.d.ts +162 -0
- package/dist/lib/features/analytics/attribution.d.ts +3 -3
- package/dist/lib/features/analytics/events.d.ts +3 -3
- package/dist/lib/features/analytics/funnels.d.ts +3 -3
- package/dist/lib/features/analytics/heatmaps.d.ts +9 -3
- package/dist/lib/features/analytics/identify.d.ts +3 -3
- package/dist/lib/features/analytics/page-views.d.ts +3 -3
- package/dist/lib/features/analytics/performance.d.ts +3 -3
- package/dist/lib/features/analytics/retention.d.ts +3 -3
- package/dist/lib/features/analytics/sessions.d.ts +3 -3
- package/dist/lib/features/core/activation.d.ts +3 -3
- package/dist/lib/features/core/experiment.d.ts +86 -70
- package/dist/lib/features/core/index.d.ts +1 -3
- package/dist/lib/features/core/track-feature.d.ts +3 -3
- package/dist/lib/features/core/track-prompt.d.ts +3 -3
- package/dist/lib/features/ecommerce/cart.d.ts +3 -3
- package/dist/lib/features/ecommerce/checkout.d.ts +3 -3
- package/dist/lib/features/ecommerce/inventory.d.ts +3 -3
- package/dist/lib/features/ecommerce/ltv.d.ts +3 -3
- package/dist/lib/features/ecommerce/products.d.ts +3 -3
- package/dist/lib/features/ecommerce/promotions.d.ts +3 -3
- package/dist/lib/features/ecommerce/purchases.d.ts +3 -3
- package/dist/lib/features/ecommerce/refunds.d.ts +3 -3
- package/dist/lib/features/ecommerce/search.d.ts +3 -3
- package/dist/lib/features/ecommerce/subscriptions.d.ts +3 -3
- package/dist/lib/features/ecommerce/wishlist.d.ts +3 -3
- package/dist/lib/features/enterprise/acquisition.d.ts +2 -2
- package/dist/lib/features/enterprise/alerts.d.ts +2 -2
- package/dist/lib/features/enterprise/churn.d.ts +2 -2
- package/dist/lib/features/enterprise/cohorts.d.ts +2 -2
- package/dist/lib/features/enterprise/engagement.d.ts +24 -3
- package/dist/lib/features/enterprise/forecasting.d.ts +2 -2
- package/dist/lib/features/enterprise/monetization.d.ts +2 -2
- package/dist/lib/features/enterprise/multi-path-funnels.d.ts +2 -2
- package/dist/lib/features/enterprise/paths.d.ts +2 -2
- package/dist/lib/features/enterprise/security.d.ts +2 -2
- package/dist/lib/features/enterprise/support.d.ts +2 -2
- package/dist/lib/frameworks/nextjs/client.d.ts +7 -13
- package/dist/lib/frameworks/nextjs/server.d.ts +5 -15
- package/dist/lib/frameworks/node/index.d.ts +2 -6
- package/dist/lib/frameworks/nuxt/index.d.ts +7 -3
- package/dist/lib/frameworks/react/CookieBanner.d.ts +91 -0
- package/dist/lib/frameworks/react/index.d.ts +98 -136
- package/dist/lib/frameworks/vue/CookieBanner.d.ts +82 -0
- package/dist/lib/frameworks/vue/index.d.ts +30 -27
- package/dist/lib/types/analytics.d.ts +62 -0
- package/dist/lib/types/common.d.ts +2 -0
- package/dist/lib/utils/identity.d.ts +93 -0
- package/dist/lib/utils/storage.d.ts +69 -0
- package/package.json +13 -2
- package/dist/lib/client/enterprise-ftrpc.d.ts +0 -51
- package/dist/lib/client/ftrpc.d.ts +0 -132
- package/dist/lib/client/modules.d.ts +0 -104
- package/dist/lib/features/core/feature-flag.d.ts +0 -249
- package/dist/lib/utils/functions.d.ts +0 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { IdentityManager } from '../utils/identity';
|
|
2
|
+
export type ConsentCategory = 'analytics' | 'marketing';
|
|
3
|
+
export type BotDetectionMode = 'block' | 'tag' | 'disabled';
|
|
4
|
+
export interface FlowGridTransportConfig {
|
|
5
|
+
/** Bot detection mode: 'block' skips events, 'tag' adds _bot flag, 'disabled' sends all */
|
|
6
|
+
botDetection?: BotDetectionMode;
|
|
7
|
+
/** Respect navigator.doNotTrack / globalPrivacyControl (default true) */
|
|
8
|
+
respectDNT?: boolean;
|
|
9
|
+
/** Global sampling rate 0.0–1.0 (default 1.0 = send everything) */
|
|
10
|
+
sampleRate?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* SDK Feature Types
|
|
14
|
+
*/
|
|
15
|
+
export type FeatureType = "engagement" | "cohorts" | "churn" | "monetization" | "multi_path_funnels" | "support" | "acquisition" | "paths" | "alerts" | "security" | "forecasting";
|
|
16
|
+
/**
|
|
17
|
+
* FlowGridTransport — Unified transport layer for Flowgrid SDK.
|
|
18
|
+
*
|
|
19
|
+
* @description
|
|
20
|
+
* Provides a secure, validated RPC-style transport layer used by all SDK modules.
|
|
21
|
+
* Handles:
|
|
22
|
+
* - Input validation
|
|
23
|
+
* - Payload size enforcement
|
|
24
|
+
* - Timeout handling
|
|
25
|
+
* - Retry logic (network failures only)
|
|
26
|
+
* - Authorization headers
|
|
27
|
+
* - Feature-scoped endpoint routing
|
|
28
|
+
*
|
|
29
|
+
* This class is designed to be extended by higher-level modules
|
|
30
|
+
* (e.g., Analytics, Experiments, Engagement, Cohorts).
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const client = new FlowGridTransport("web_123", "api.flowgrid.com", "sk_live_xxx");
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class FlowGridTransport {
|
|
38
|
+
/**
|
|
39
|
+
* Unique Web ID identifying the site or application.
|
|
40
|
+
* Used by the backend to associate incoming events.
|
|
41
|
+
*/
|
|
42
|
+
protected webId: string;
|
|
43
|
+
/**
|
|
44
|
+
* Base API endpoint.
|
|
45
|
+
* Example values:
|
|
46
|
+
* - "api.flowgrid.com"
|
|
47
|
+
* - "https://api.flowgrid.com"
|
|
48
|
+
*
|
|
49
|
+
* Protocol is normalized automatically.
|
|
50
|
+
*/
|
|
51
|
+
protected endpoint: string;
|
|
52
|
+
/**
|
|
53
|
+
* Private API key used for authenticating requests.
|
|
54
|
+
* Sent as a Bearer token in the Authorization header.
|
|
55
|
+
*/
|
|
56
|
+
private apiKey;
|
|
57
|
+
/**
|
|
58
|
+
* Visitor ID for cross-session visitor tracking.
|
|
59
|
+
* Persisted per-visitor (cookie/localStorage) and sent with every event.
|
|
60
|
+
*/
|
|
61
|
+
protected visitorId: string;
|
|
62
|
+
/**
|
|
63
|
+
* Optional identity manager that owns the visitor/session lifecycle.
|
|
64
|
+
* When provided, visitor_id is resolved at call time (not construction time).
|
|
65
|
+
*/
|
|
66
|
+
protected identityManager?: IdentityManager;
|
|
67
|
+
/**
|
|
68
|
+
* Maximum allowed payload size (in bytes).
|
|
69
|
+
* Prevents oversized event submissions.
|
|
70
|
+
*/
|
|
71
|
+
private static readonly MAX_PAYLOAD_SIZE;
|
|
72
|
+
/**
|
|
73
|
+
* Maximum time (ms) before request is aborted.
|
|
74
|
+
*/
|
|
75
|
+
private static readonly TIMEOUT_MS;
|
|
76
|
+
/**
|
|
77
|
+
* Maximum retry attempts for network-level failures and 5xx server errors.
|
|
78
|
+
*/
|
|
79
|
+
private static readonly MAX_RETRIES;
|
|
80
|
+
/** Max events to persist in localStorage buffer */
|
|
81
|
+
private static readonly MAX_BUFFER_EVENTS;
|
|
82
|
+
/** Max buffer size in bytes */
|
|
83
|
+
private static readonly MAX_BUFFER_SIZE;
|
|
84
|
+
/** localStorage key for failed event buffer */
|
|
85
|
+
private static readonly EVENT_BUFFER_KEY;
|
|
86
|
+
/** Consent state */
|
|
87
|
+
private static consent;
|
|
88
|
+
/** Transport config */
|
|
89
|
+
protected transportConfig: FlowGridTransportConfig;
|
|
90
|
+
/**
|
|
91
|
+
* Creates a new FlowGridTransport instance.
|
|
92
|
+
*
|
|
93
|
+
* @param webId - Unique identifier for the web property.
|
|
94
|
+
* @param endpoint - API base endpoint.
|
|
95
|
+
* @param apiKey - Private API key for authentication.
|
|
96
|
+
* @param visitorId - Optional visitor ID for cross-session tracking.
|
|
97
|
+
*
|
|
98
|
+
* @throws {Error} If required parameters are missing.
|
|
99
|
+
*/
|
|
100
|
+
constructor(webId: string, endpoint: string, apiKey: string, visitorId?: string, identityManager?: IdentityManager, config?: FlowGridTransportConfig);
|
|
101
|
+
static setConsent(consent: Partial<Record<ConsentCategory, boolean>>): void;
|
|
102
|
+
static hasConsent(category: ConsentCategory): boolean;
|
|
103
|
+
private static isLikelyBot;
|
|
104
|
+
private isDNTEnabled;
|
|
105
|
+
private static getDeviceContext;
|
|
106
|
+
/**
|
|
107
|
+
* Fire-and-forget event via sendBeacon. Used for page unload events.
|
|
108
|
+
*/
|
|
109
|
+
sendViaBeacon(eventName: string, properties?: Record<string, any>): boolean;
|
|
110
|
+
private bufferEvent;
|
|
111
|
+
private drainEventBuffer;
|
|
112
|
+
/**
|
|
113
|
+
* Core RPC transport method for standard SDK calls.
|
|
114
|
+
*
|
|
115
|
+
* @template T Expected JSON response type.
|
|
116
|
+
*
|
|
117
|
+
* @param eventName - Logical event or function name.
|
|
118
|
+
* @param properties - Arbitrary event payload properties.
|
|
119
|
+
* @param method - HTTP method ("GET", "POST", "PATCH").
|
|
120
|
+
*
|
|
121
|
+
* @returns Promise resolving to typed response.
|
|
122
|
+
*/
|
|
123
|
+
protected init<T>(eventName: string, properties?: Record<string, any>, method?: "GET" | "POST" | "PATCH"): Promise<T>;
|
|
124
|
+
/**
|
|
125
|
+
* Feature-scoped RPC transport method.
|
|
126
|
+
* Routes to the SDK API endpoint with a feature type qualifier.
|
|
127
|
+
*
|
|
128
|
+
* @param eventName - Name of the event to track.
|
|
129
|
+
* @param properties - Additional properties to send (must include type).
|
|
130
|
+
*/
|
|
131
|
+
protected initFeature<T>(eventName: string, properties: Record<string, any> & {
|
|
132
|
+
type: FeatureType;
|
|
133
|
+
}): Promise<T>;
|
|
134
|
+
/**
|
|
135
|
+
* Executes HTTP request with timeout and retry handling.
|
|
136
|
+
*
|
|
137
|
+
* @template T Expected response type.
|
|
138
|
+
*
|
|
139
|
+
* @param url - Fully constructed request URL.
|
|
140
|
+
* @param method - HTTP method.
|
|
141
|
+
* @param body - Optional JSON body (POST/PATCH only).
|
|
142
|
+
* @param extraHeaders - Additional headers to include.
|
|
143
|
+
*
|
|
144
|
+
* @throws {Error} On timeout, network failure, or non-OK HTTP status.
|
|
145
|
+
*/
|
|
146
|
+
private executeRequest;
|
|
147
|
+
/**
|
|
148
|
+
* Exponential backoff: 1s, 2s, 4s ...
|
|
149
|
+
*/
|
|
150
|
+
private backoff;
|
|
151
|
+
/**
|
|
152
|
+
* Validates event name and payload.
|
|
153
|
+
*
|
|
154
|
+
* @param eventName - Event identifier.
|
|
155
|
+
* @param properties - Associated event properties.
|
|
156
|
+
*
|
|
157
|
+
* @throws {Error} If validation fails.
|
|
158
|
+
*/
|
|
159
|
+
private validateInput;
|
|
160
|
+
/**
|
|
161
|
+
* Normalizes endpoint input.
|
|
162
|
+
* Ensures protocol is present and removes trailing slashes.
|
|
163
|
+
*
|
|
164
|
+
* @param endpoint - Raw endpoint string.
|
|
165
|
+
* @returns Normalized endpoint URL.
|
|
166
|
+
*/
|
|
167
|
+
private normalizeEndpoint;
|
|
168
|
+
/**
|
|
169
|
+
* Safely reads response text without throwing.
|
|
170
|
+
*
|
|
171
|
+
* @param res - Fetch Response object.
|
|
172
|
+
* @returns Response text or empty string.
|
|
173
|
+
*/
|
|
174
|
+
private safeRead;
|
|
175
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview FlowGrid Consent Management Module
|
|
3
|
+
* @module consent
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Cookie consent management for GDPR, CCPA, and ePrivacy compliance.
|
|
7
|
+
* Provides a framework-agnostic {@link ConsentManager} and types for
|
|
8
|
+
* building customisable cookie banner components.
|
|
9
|
+
*
|
|
10
|
+
* ## Quick Start
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { ConsentManager, FlowGridTransport } from 'flowgrid-sdk';
|
|
14
|
+
*
|
|
15
|
+
* const consent = new ConsentManager({
|
|
16
|
+
* onChange: (prefs) => {
|
|
17
|
+
* FlowGridTransport.setConsent({
|
|
18
|
+
* analytics: prefs.analytics,
|
|
19
|
+
* marketing: prefs.marketing,
|
|
20
|
+
* });
|
|
21
|
+
* },
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* if (!consent.hasConsented()) {
|
|
25
|
+
* // Show your cookie banner
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* ## Framework Components
|
|
30
|
+
*
|
|
31
|
+
* - **React / Next.js**: `import { CookieBanner } from 'flowgrid-sdk/react'`
|
|
32
|
+
* - **Vue / Nuxt**: `import { CookieBanner } from 'flowgrid-sdk/vue'`
|
|
33
|
+
*
|
|
34
|
+
* @see {@link ConsentManager} for the core API.
|
|
35
|
+
*/
|
|
36
|
+
export { ConsentManager } from './manager';
|
|
37
|
+
export type { ConsentCategory, ConsentPreferences, ConsentConfig, ConsentChangeEvent, CookieBannerConfig, CookieBannerTheme, } from './types';
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview FlowGrid Consent Manager
|
|
3
|
+
* @module consent/manager
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Framework-agnostic consent manager that stores user cookie preferences,
|
|
7
|
+
* integrates with the FlowGrid transport layer's consent gates, and
|
|
8
|
+
* respects DNT / GPC signals.
|
|
9
|
+
*
|
|
10
|
+
* The consent manager uses a single cookie (`fg_consent` by default) to
|
|
11
|
+
* persist the user's per-category choices. It exposes a simple API that
|
|
12
|
+
* framework-specific cookie banner components can wrap.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { ConsentManager } from 'flowgrid-sdk';
|
|
17
|
+
* import { FlowGridTransport } from 'flowgrid-sdk';
|
|
18
|
+
*
|
|
19
|
+
* const consent = new ConsentManager({
|
|
20
|
+
* onChange: (prefs) => {
|
|
21
|
+
* // Sync with FlowGrid transport consent gates
|
|
22
|
+
* FlowGridTransport.setConsent({
|
|
23
|
+
* analytics: prefs.analytics,
|
|
24
|
+
* marketing: prefs.marketing,
|
|
25
|
+
* });
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Check if user has already consented
|
|
30
|
+
* if (!consent.hasConsented()) {
|
|
31
|
+
* showCookieBanner();
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* // Accept all
|
|
35
|
+
* consent.acceptAll();
|
|
36
|
+
*
|
|
37
|
+
* // Or reject non-essential
|
|
38
|
+
* consent.rejectNonEssential();
|
|
39
|
+
*
|
|
40
|
+
* // Or update individual categories
|
|
41
|
+
* consent.update({ analytics: true, marketing: false, preferences: true });
|
|
42
|
+
*
|
|
43
|
+
* // Read current state
|
|
44
|
+
* const prefs = consent.getPreferences();
|
|
45
|
+
* console.log(prefs.analytics); // true
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
import type { ConsentConfig, ConsentPreferences } from './types';
|
|
49
|
+
/**
|
|
50
|
+
* Manages cookie consent state for GDPR/CCPA compliance.
|
|
51
|
+
*
|
|
52
|
+
* Stores the user's per-category consent choices in a single cookie and
|
|
53
|
+
* provides methods to accept, reject, or customise preferences. Integrates
|
|
54
|
+
* with the FlowGrid transport layer via the `onChange` callback.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { ConsentManager, FlowGridTransport } from 'flowgrid-sdk';
|
|
59
|
+
*
|
|
60
|
+
* const consent = new ConsentManager({
|
|
61
|
+
* onChange: (prefs) => {
|
|
62
|
+
* FlowGridTransport.setConsent({
|
|
63
|
+
* analytics: prefs.analytics,
|
|
64
|
+
* marketing: prefs.marketing,
|
|
65
|
+
* });
|
|
66
|
+
* },
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* // In your cookie banner "Accept All" handler:
|
|
70
|
+
* consent.acceptAll();
|
|
71
|
+
*
|
|
72
|
+
* // In your "Reject All" handler:
|
|
73
|
+
* consent.rejectNonEssential();
|
|
74
|
+
*
|
|
75
|
+
* // In your "Save Preferences" handler:
|
|
76
|
+
* consent.update({ analytics: true, marketing: false, preferences: true });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare class ConsentManager {
|
|
80
|
+
private config;
|
|
81
|
+
private preferences;
|
|
82
|
+
/**
|
|
83
|
+
* Create a new ConsentManager.
|
|
84
|
+
*
|
|
85
|
+
* @param config - Consent configuration options.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const consent = new ConsentManager({
|
|
90
|
+
* cookieName: 'my_app_consent',
|
|
91
|
+
* cookieDays: 180,
|
|
92
|
+
* respectDNT: true,
|
|
93
|
+
* requireExplicitConsent: true,
|
|
94
|
+
* onChange: (prefs) => {
|
|
95
|
+
* console.log('Consent changed:', prefs);
|
|
96
|
+
* },
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
constructor(config?: ConsentConfig);
|
|
101
|
+
/**
|
|
102
|
+
* Check if the user has previously given consent (cookie exists).
|
|
103
|
+
*
|
|
104
|
+
* @returns `true` if the consent cookie exists, `false` otherwise.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* if (!consent.hasConsented()) {
|
|
109
|
+
* showCookieBanner();
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
hasConsented(): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Get the current consent preferences.
|
|
116
|
+
*
|
|
117
|
+
* @returns A copy of the current {@link ConsentPreferences}.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* const prefs = consent.getPreferences();
|
|
122
|
+
* if (prefs.analytics) {
|
|
123
|
+
* initAnalytics();
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
getPreferences(): ConsentPreferences;
|
|
128
|
+
/**
|
|
129
|
+
* Check if a specific consent category is enabled.
|
|
130
|
+
*
|
|
131
|
+
* @param category - The category to check.
|
|
132
|
+
* @returns `true` if the category is consented to.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* if (consent.hasCategory('marketing')) {
|
|
137
|
+
* loadMarketingPixels();
|
|
138
|
+
* }
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
hasCategory(category: keyof ConsentPreferences): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Accept all consent categories.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* // "Accept All" button handler
|
|
148
|
+
* document.getElementById('accept-all')?.addEventListener('click', () => {
|
|
149
|
+
* consent.acceptAll();
|
|
150
|
+
* });
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
acceptAll(): void;
|
|
154
|
+
/**
|
|
155
|
+
* Reject all non-essential categories.
|
|
156
|
+
* Only `necessary` remains enabled.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* // "Reject All" button handler
|
|
161
|
+
* consent.rejectNonEssential();
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
rejectNonEssential(): void;
|
|
165
|
+
/**
|
|
166
|
+
* Update individual consent categories.
|
|
167
|
+
*
|
|
168
|
+
* @param updates - Partial preferences to merge.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* // "Save Preferences" handler
|
|
173
|
+
* consent.update({
|
|
174
|
+
* analytics: true,
|
|
175
|
+
* marketing: false,
|
|
176
|
+
* preferences: true,
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
update(updates: Partial<Omit<ConsentPreferences, 'necessary'>>): void;
|
|
181
|
+
/**
|
|
182
|
+
* Reset consent — removes the cookie and restores defaults.
|
|
183
|
+
* The cookie banner should be shown again after this.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* // "Reset Cookies" link
|
|
188
|
+
* consent.reset();
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
reset(): void;
|
|
192
|
+
private setPreferences;
|
|
193
|
+
private isDNTEnabled;
|
|
194
|
+
private loadFromCookie;
|
|
195
|
+
private saveToCookie;
|
|
196
|
+
private deleteCookie;
|
|
197
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview FlowGrid Consent Management — Types
|
|
3
|
+
* @module consent/types
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Types for cookie consent management, GDPR/CCPA compliance,
|
|
7
|
+
* and customizable cookie banner configuration.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Consent categories that can be individually toggled.
|
|
11
|
+
*
|
|
12
|
+
* - `necessary` — Always enabled; cannot be declined (session, security).
|
|
13
|
+
* - `analytics` — Page views, sessions, funnels, heatmaps.
|
|
14
|
+
* - `marketing` — UTM tracking, attribution, retargeting pixels.
|
|
15
|
+
* - `preferences` — UI preferences, locale, theme stored in cookies.
|
|
16
|
+
*/
|
|
17
|
+
export type ConsentCategory = 'necessary' | 'analytics' | 'marketing' | 'preferences';
|
|
18
|
+
/**
|
|
19
|
+
* User's consent choices per category.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const prefs: ConsentPreferences = {
|
|
24
|
+
* necessary: true, // always true
|
|
25
|
+
* analytics: true,
|
|
26
|
+
* marketing: false,
|
|
27
|
+
* preferences: true,
|
|
28
|
+
* };
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export interface ConsentPreferences {
|
|
32
|
+
necessary: true;
|
|
33
|
+
analytics: boolean;
|
|
34
|
+
marketing: boolean;
|
|
35
|
+
preferences: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Configuration for the {@link ConsentManager}.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { ConsentManager } from 'flowgrid-sdk';
|
|
43
|
+
*
|
|
44
|
+
* const consent = new ConsentManager({
|
|
45
|
+
* cookieName: 'fg_consent',
|
|
46
|
+
* cookieDays: 365,
|
|
47
|
+
* defaultPreferences: {
|
|
48
|
+
* necessary: true,
|
|
49
|
+
* analytics: false,
|
|
50
|
+
* marketing: false,
|
|
51
|
+
* preferences: true,
|
|
52
|
+
* },
|
|
53
|
+
* onChange: (prefs) => {
|
|
54
|
+
* console.log('Consent updated:', prefs);
|
|
55
|
+
* },
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export interface ConsentConfig {
|
|
60
|
+
/** Cookie name to store consent state. Defaults to `"fg_consent"`. */
|
|
61
|
+
cookieName?: string;
|
|
62
|
+
/** Days until the consent cookie expires. Defaults to `365`. */
|
|
63
|
+
cookieDays?: number;
|
|
64
|
+
/** Cookie domain (e.g. `.example.com`). Defaults to current domain. */
|
|
65
|
+
cookieDomain?: string;
|
|
66
|
+
/** Default consent state before the user makes a choice. */
|
|
67
|
+
defaultPreferences?: Partial<ConsentPreferences>;
|
|
68
|
+
/** Called whenever consent preferences change. */
|
|
69
|
+
onChange?: (preferences: ConsentPreferences) => void;
|
|
70
|
+
/** Respect `navigator.doNotTrack` / `globalPrivacyControl`. Defaults to `true`. */
|
|
71
|
+
respectDNT?: boolean;
|
|
72
|
+
/** Auto-block analytics/marketing before consent is given. Defaults to `true`. */
|
|
73
|
+
requireExplicitConsent?: boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Event emitted when consent changes.
|
|
77
|
+
*/
|
|
78
|
+
export interface ConsentChangeEvent {
|
|
79
|
+
/** Previous consent state (null if first interaction). */
|
|
80
|
+
previous: ConsentPreferences | null;
|
|
81
|
+
/** New consent state. */
|
|
82
|
+
current: ConsentPreferences;
|
|
83
|
+
/** Timestamp of the change. */
|
|
84
|
+
timestamp: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Theme / appearance configuration for the cookie banner component.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* const theme: CookieBannerTheme = {
|
|
92
|
+
* position: 'bottom',
|
|
93
|
+
* primaryColor: '#4F46E5',
|
|
94
|
+
* backgroundColor: '#FFFFFF',
|
|
95
|
+
* textColor: '#1F2937',
|
|
96
|
+
* borderRadius: '8px',
|
|
97
|
+
* fontFamily: 'Inter, system-ui, sans-serif',
|
|
98
|
+
* };
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export interface CookieBannerTheme {
|
|
102
|
+
/** Banner position. Defaults to `'bottom'`. */
|
|
103
|
+
position?: 'top' | 'bottom' | 'bottom-left' | 'bottom-right' | 'center';
|
|
104
|
+
/** Primary/accent color (buttons). Defaults to `'#4F46E5'`. */
|
|
105
|
+
primaryColor?: string;
|
|
106
|
+
/** Banner background color. Defaults to `'#FFFFFF'`. */
|
|
107
|
+
backgroundColor?: string;
|
|
108
|
+
/** Text color. Defaults to `'#1F2937'`. */
|
|
109
|
+
textColor?: string;
|
|
110
|
+
/** Border radius for the banner container. Defaults to `'8px'`. */
|
|
111
|
+
borderRadius?: string;
|
|
112
|
+
/** Font family. Defaults to `'system-ui, sans-serif'`. */
|
|
113
|
+
fontFamily?: string;
|
|
114
|
+
/** Z-index for the banner. Defaults to `9999`. */
|
|
115
|
+
zIndex?: number;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Full configuration for a cookie banner component.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```tsx
|
|
122
|
+
* // React
|
|
123
|
+
* import { CookieBanner } from 'flowgrid-sdk/react';
|
|
124
|
+
*
|
|
125
|
+
* <CookieBanner
|
|
126
|
+
* config={{
|
|
127
|
+
* title: 'We use cookies',
|
|
128
|
+
* description: 'We use cookies to improve your experience.',
|
|
129
|
+
* acceptAllLabel: 'Accept All',
|
|
130
|
+
* rejectAllLabel: 'Reject All',
|
|
131
|
+
* customizeLabel: 'Customize',
|
|
132
|
+
* privacyPolicyUrl: '/privacy',
|
|
133
|
+
* theme: { position: 'bottom', primaryColor: '#4F46E5' },
|
|
134
|
+
* }}
|
|
135
|
+
* onAcceptAll={() => consent.acceptAll()}
|
|
136
|
+
* onRejectAll={() => consent.rejectNonEssential()}
|
|
137
|
+
* onCustomize={(prefs) => consent.update(prefs)}
|
|
138
|
+
* />
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export interface CookieBannerConfig {
|
|
142
|
+
/** Banner title. Defaults to `"Cookie Preferences"`. */
|
|
143
|
+
title?: string;
|
|
144
|
+
/** Banner description text. */
|
|
145
|
+
description?: string;
|
|
146
|
+
/** "Accept All" button label. Defaults to `"Accept All"`. */
|
|
147
|
+
acceptAllLabel?: string;
|
|
148
|
+
/** "Reject All" button label. Defaults to `"Reject All"`. */
|
|
149
|
+
rejectAllLabel?: string;
|
|
150
|
+
/** "Customize" / "Manage" button label. Defaults to `"Customize"`. */
|
|
151
|
+
customizeLabel?: string;
|
|
152
|
+
/** "Save Preferences" button label (in detail view). Defaults to `"Save Preferences"`. */
|
|
153
|
+
saveLabel?: string;
|
|
154
|
+
/** Link to privacy policy page. */
|
|
155
|
+
privacyPolicyUrl?: string;
|
|
156
|
+
/** Theme / appearance settings. */
|
|
157
|
+
theme?: CookieBannerTheme;
|
|
158
|
+
/** Category descriptions shown in the customization panel. */
|
|
159
|
+
categoryDescriptions?: Partial<Record<ConsentCategory, string>>;
|
|
160
|
+
/** Show the banner even if consent was already given (e.g. for a "manage cookies" link). */
|
|
161
|
+
forceShow?: boolean;
|
|
162
|
+
}
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
* const report = await attribution.getReport({ range: 'last30days' });
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
45
|
-
import {
|
|
45
|
+
import { FlowGridTransport } from "../../client/transport";
|
|
46
46
|
import { MoneyValue, DateRangeFilter } from "../../types";
|
|
47
47
|
/**
|
|
48
48
|
* Attribution model types.
|
|
@@ -141,7 +141,7 @@ export interface AttributionReportData {
|
|
|
141
141
|
/**
|
|
142
142
|
* Attribution - Multi-touch attribution tracking.
|
|
143
143
|
*
|
|
144
|
-
* @extends
|
|
144
|
+
* @extends FlowGridTransport
|
|
145
145
|
*
|
|
146
146
|
* @description
|
|
147
147
|
* Provides attribution capabilities including:
|
|
@@ -177,7 +177,7 @@ export interface AttributionReportData {
|
|
|
177
177
|
* });
|
|
178
178
|
* ```
|
|
179
179
|
*/
|
|
180
|
-
export declare class Attribution extends
|
|
180
|
+
export declare class Attribution extends FlowGridTransport {
|
|
181
181
|
/**
|
|
182
182
|
* Tracks a marketing touchpoint.
|
|
183
183
|
*
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
* });
|
|
47
47
|
* ```
|
|
48
48
|
*/
|
|
49
|
-
import {
|
|
49
|
+
import { FlowGridTransport } from "../../client/transport";
|
|
50
50
|
import { ClickEvent, FormEvent, SearchEvent, ErrorEvent, TimeSeriesData, DateRangeFilter, PaginationParams } from "../../types";
|
|
51
51
|
/**
|
|
52
52
|
* Configuration for tracking a custom event.
|
|
@@ -134,7 +134,7 @@ export interface EventAnalyticsData {
|
|
|
134
134
|
/**
|
|
135
135
|
* Events - Track and analyze custom events.
|
|
136
136
|
*
|
|
137
|
-
* @extends
|
|
137
|
+
* @extends FlowGridTransport
|
|
138
138
|
*
|
|
139
139
|
* @description
|
|
140
140
|
* Provides flexible custom event tracking including:
|
|
@@ -162,7 +162,7 @@ export interface EventAnalyticsData {
|
|
|
162
162
|
* const analytics = await events.getAnalytics({ range: 'last7days' });
|
|
163
163
|
* ```
|
|
164
164
|
*/
|
|
165
|
-
export declare class Events extends
|
|
165
|
+
export declare class Events extends FlowGridTransport {
|
|
166
166
|
/**
|
|
167
167
|
* Tracks a custom event.
|
|
168
168
|
*
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
* const analysis = await funnels.analyze('checkout_funnel');
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
45
|
-
import {
|
|
45
|
+
import { FlowGridTransport } from "../../client/transport";
|
|
46
46
|
import { FunnelAnalysis, DateRangeFilter, TimeSeriesData } from "../../types";
|
|
47
47
|
/**
|
|
48
48
|
* Funnel definition configuration.
|
|
@@ -138,7 +138,7 @@ export interface FunnelComparisonData {
|
|
|
138
138
|
/**
|
|
139
139
|
* Funnels - Define and analyze conversion funnels.
|
|
140
140
|
*
|
|
141
|
-
* @extends
|
|
141
|
+
* @extends FlowGridTransport
|
|
142
142
|
*
|
|
143
143
|
* @description
|
|
144
144
|
* Provides funnel analysis capabilities including:
|
|
@@ -170,7 +170,7 @@ export interface FunnelComparisonData {
|
|
|
170
170
|
* });
|
|
171
171
|
* ```
|
|
172
172
|
*/
|
|
173
|
-
export declare class Funnels extends
|
|
173
|
+
export declare class Funnels extends FlowGridTransport {
|
|
174
174
|
/**
|
|
175
175
|
* Defines a new funnel or updates existing.
|
|
176
176
|
*
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
* });
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
|
-
import {
|
|
43
|
+
import { FlowGridTransport } from "../../client/transport";
|
|
44
44
|
import { DateRangeFilter } from "../../types";
|
|
45
45
|
/**
|
|
46
46
|
* Click interaction data.
|
|
@@ -160,7 +160,7 @@ export interface HeatmapData {
|
|
|
160
160
|
/**
|
|
161
161
|
* Heatmaps - Track user interactions for heatmap visualization.
|
|
162
162
|
*
|
|
163
|
-
* @extends
|
|
163
|
+
* @extends FlowGridTransport
|
|
164
164
|
*
|
|
165
165
|
* @description
|
|
166
166
|
* Provides heatmap data collection including:
|
|
@@ -190,7 +190,13 @@ export interface HeatmapData {
|
|
|
190
190
|
* const data = await heatmaps.getData('/pricing', { range: 'last7days' });
|
|
191
191
|
* ```
|
|
192
192
|
*/
|
|
193
|
-
export declare class Heatmaps extends
|
|
193
|
+
export declare class Heatmaps extends FlowGridTransport {
|
|
194
|
+
/** Throttle timestamps */
|
|
195
|
+
private lastMovementTime;
|
|
196
|
+
private lastScrollTime;
|
|
197
|
+
/** Throttle intervals (ms) */
|
|
198
|
+
private static readonly MOVEMENT_THROTTLE_MS;
|
|
199
|
+
private static readonly SCROLL_THROTTLE_MS;
|
|
194
200
|
/**
|
|
195
201
|
* Tracks a click interaction.
|
|
196
202
|
*
|