flowgrid-sdk 1.2.0 → 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.d.ts +2 -2
- 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.d.ts +2 -2
- 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,336 @@
|
|
|
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
|
+
// ============================================================================
|
|
49
|
+
// DEFAULTS
|
|
50
|
+
// ============================================================================
|
|
51
|
+
const DEFAULT_COOKIE_NAME = 'fg_consent';
|
|
52
|
+
const DEFAULT_TRACKING_COOKIE_NAME = 'fg_tracking_consent';
|
|
53
|
+
const DEFAULT_COOKIE_DAYS = 365;
|
|
54
|
+
const DEFAULT_PREFERENCES = {
|
|
55
|
+
necessary: true,
|
|
56
|
+
analytics: false,
|
|
57
|
+
marketing: false,
|
|
58
|
+
preferences: true,
|
|
59
|
+
};
|
|
60
|
+
// ============================================================================
|
|
61
|
+
// CONSENT MANAGER
|
|
62
|
+
// ============================================================================
|
|
63
|
+
/**
|
|
64
|
+
* Manages cookie consent state for GDPR/CCPA compliance.
|
|
65
|
+
*
|
|
66
|
+
* Stores the user's per-category consent choices in a single cookie and
|
|
67
|
+
* provides methods to accept, reject, or customise preferences. Integrates
|
|
68
|
+
* with the FlowGrid transport layer via the `onChange` callback.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { ConsentManager, FlowGridTransport } from 'flowgrid-sdk';
|
|
73
|
+
*
|
|
74
|
+
* const consent = new ConsentManager({
|
|
75
|
+
* onChange: (prefs) => {
|
|
76
|
+
* FlowGridTransport.setConsent({
|
|
77
|
+
* analytics: prefs.analytics,
|
|
78
|
+
* marketing: prefs.marketing,
|
|
79
|
+
* });
|
|
80
|
+
* },
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* // In your cookie banner "Accept All" handler:
|
|
84
|
+
* consent.acceptAll();
|
|
85
|
+
*
|
|
86
|
+
* // In your "Reject All" handler:
|
|
87
|
+
* consent.rejectNonEssential();
|
|
88
|
+
*
|
|
89
|
+
* // In your "Save Preferences" handler:
|
|
90
|
+
* consent.update({ analytics: true, marketing: false, preferences: true });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export class ConsentManager {
|
|
94
|
+
/**
|
|
95
|
+
* Create a new ConsentManager.
|
|
96
|
+
*
|
|
97
|
+
* @param config - Consent configuration options.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* const consent = new ConsentManager({
|
|
102
|
+
* cookieName: 'my_app_consent',
|
|
103
|
+
* cookieDays: 180,
|
|
104
|
+
* respectDNT: true,
|
|
105
|
+
* requireExplicitConsent: true,
|
|
106
|
+
* onChange: (prefs) => {
|
|
107
|
+
* console.log('Consent changed:', prefs);
|
|
108
|
+
* },
|
|
109
|
+
* });
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
constructor(config) {
|
|
113
|
+
this.config = {
|
|
114
|
+
cookieName: config?.cookieName ?? DEFAULT_COOKIE_NAME,
|
|
115
|
+
cookieDays: config?.cookieDays ?? DEFAULT_COOKIE_DAYS,
|
|
116
|
+
cookieDomain: config?.cookieDomain,
|
|
117
|
+
respectDNT: config?.respectDNT ?? true,
|
|
118
|
+
requireExplicitConsent: config?.requireExplicitConsent ?? true,
|
|
119
|
+
onChange: config?.onChange,
|
|
120
|
+
defaultPreferences: {
|
|
121
|
+
...DEFAULT_PREFERENCES,
|
|
122
|
+
...config?.defaultPreferences,
|
|
123
|
+
necessary: true, // always true
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
// Load saved preferences or use defaults
|
|
127
|
+
const saved = this.loadFromCookie();
|
|
128
|
+
if (saved) {
|
|
129
|
+
this.preferences = saved;
|
|
130
|
+
}
|
|
131
|
+
else if (this.isDNTEnabled() && this.config.respectDNT) {
|
|
132
|
+
// DNT/GPC: default to rejecting non-essential
|
|
133
|
+
this.preferences = {
|
|
134
|
+
necessary: true,
|
|
135
|
+
analytics: false,
|
|
136
|
+
marketing: false,
|
|
137
|
+
preferences: false,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
else if (this.config.requireExplicitConsent) {
|
|
141
|
+
this.preferences = { ...this.config.defaultPreferences };
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
// Implied consent mode: all enabled by default
|
|
145
|
+
this.preferences = {
|
|
146
|
+
necessary: true,
|
|
147
|
+
analytics: true,
|
|
148
|
+
marketing: true,
|
|
149
|
+
preferences: true,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// ---------------------------------------------------------------------------
|
|
154
|
+
// PUBLIC API
|
|
155
|
+
// ---------------------------------------------------------------------------
|
|
156
|
+
/**
|
|
157
|
+
* Check if the user has previously given consent (cookie exists).
|
|
158
|
+
*
|
|
159
|
+
* @returns `true` if the consent cookie exists, `false` otherwise.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* if (!consent.hasConsented()) {
|
|
164
|
+
* showCookieBanner();
|
|
165
|
+
* }
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
hasConsented() {
|
|
169
|
+
return this.loadFromCookie() !== null;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get the current consent preferences.
|
|
173
|
+
*
|
|
174
|
+
* @returns A copy of the current {@link ConsentPreferences}.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* const prefs = consent.getPreferences();
|
|
179
|
+
* if (prefs.analytics) {
|
|
180
|
+
* initAnalytics();
|
|
181
|
+
* }
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
getPreferences() {
|
|
185
|
+
return { ...this.preferences };
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Check if a specific consent category is enabled.
|
|
189
|
+
*
|
|
190
|
+
* @param category - The category to check.
|
|
191
|
+
* @returns `true` if the category is consented to.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* if (consent.hasCategory('marketing')) {
|
|
196
|
+
* loadMarketingPixels();
|
|
197
|
+
* }
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
hasCategory(category) {
|
|
201
|
+
return this.preferences[category] ?? false;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Accept all consent categories.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* // "Accept All" button handler
|
|
209
|
+
* document.getElementById('accept-all')?.addEventListener('click', () => {
|
|
210
|
+
* consent.acceptAll();
|
|
211
|
+
* });
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
acceptAll() {
|
|
215
|
+
this.setPreferences({
|
|
216
|
+
necessary: true,
|
|
217
|
+
analytics: true,
|
|
218
|
+
marketing: true,
|
|
219
|
+
preferences: true,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Reject all non-essential categories.
|
|
224
|
+
* Only `necessary` remains enabled.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* // "Reject All" button handler
|
|
229
|
+
* consent.rejectNonEssential();
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
rejectNonEssential() {
|
|
233
|
+
this.setPreferences({
|
|
234
|
+
necessary: true,
|
|
235
|
+
analytics: false,
|
|
236
|
+
marketing: false,
|
|
237
|
+
preferences: false,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Update individual consent categories.
|
|
242
|
+
*
|
|
243
|
+
* @param updates - Partial preferences to merge.
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```ts
|
|
247
|
+
* // "Save Preferences" handler
|
|
248
|
+
* consent.update({
|
|
249
|
+
* analytics: true,
|
|
250
|
+
* marketing: false,
|
|
251
|
+
* preferences: true,
|
|
252
|
+
* });
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
update(updates) {
|
|
256
|
+
this.setPreferences({
|
|
257
|
+
...this.preferences,
|
|
258
|
+
...updates,
|
|
259
|
+
necessary: true,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Reset consent — removes the cookie and restores defaults.
|
|
264
|
+
* The cookie banner should be shown again after this.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```ts
|
|
268
|
+
* // "Reset Cookies" link
|
|
269
|
+
* consent.reset();
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
reset() {
|
|
273
|
+
this.deleteCookie();
|
|
274
|
+
this.preferences = { ...this.config.defaultPreferences };
|
|
275
|
+
}
|
|
276
|
+
// ---------------------------------------------------------------------------
|
|
277
|
+
// PRIVATE
|
|
278
|
+
// ---------------------------------------------------------------------------
|
|
279
|
+
setPreferences(prefs) {
|
|
280
|
+
const previous = { ...this.preferences };
|
|
281
|
+
this.preferences = { ...prefs, necessary: true };
|
|
282
|
+
this.saveToCookie();
|
|
283
|
+
if (this.config.onChange) {
|
|
284
|
+
this.config.onChange(this.preferences);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
isDNTEnabled() {
|
|
288
|
+
if (typeof navigator === 'undefined')
|
|
289
|
+
return false;
|
|
290
|
+
if (navigator.globalPrivacyControl)
|
|
291
|
+
return true;
|
|
292
|
+
if (navigator.doNotTrack === '1')
|
|
293
|
+
return true;
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
// ---------------------------------------------------------------------------
|
|
297
|
+
// COOKIE I/O
|
|
298
|
+
// ---------------------------------------------------------------------------
|
|
299
|
+
loadFromCookie() {
|
|
300
|
+
if (typeof document === 'undefined')
|
|
301
|
+
return null;
|
|
302
|
+
const match = document.cookie.match(new RegExp('(^| )' + this.config.cookieName + '=([^;]+)'));
|
|
303
|
+
if (!match)
|
|
304
|
+
return null;
|
|
305
|
+
try {
|
|
306
|
+
const parsed = JSON.parse(decodeURIComponent(match[2]));
|
|
307
|
+
if (typeof parsed === 'object' && parsed !== null && typeof parsed.necessary === 'boolean') {
|
|
308
|
+
return { ...DEFAULT_PREFERENCES, ...parsed, necessary: true };
|
|
309
|
+
}
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
catch {
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
saveToCookie() {
|
|
317
|
+
if (typeof document === 'undefined')
|
|
318
|
+
return;
|
|
319
|
+
const value = encodeURIComponent(JSON.stringify(this.preferences));
|
|
320
|
+
const maxAge = this.config.cookieDays * 24 * 60 * 60;
|
|
321
|
+
const domain = this.config.cookieDomain ? `; Domain=${this.config.cookieDomain}` : '';
|
|
322
|
+
const secure = typeof location !== 'undefined' && location.protocol === 'https:' ? '; Secure' : '';
|
|
323
|
+
document.cookie = `${this.config.cookieName}=${value}; Path=/; Max-Age=${maxAge}; SameSite=Lax${secure}${domain}`;
|
|
324
|
+
// Simple boolean cookie for track.js compatibility
|
|
325
|
+
const trackingAllowed = this.preferences.analytics ? 'true' : 'false';
|
|
326
|
+
document.cookie = `${DEFAULT_TRACKING_COOKIE_NAME}=${trackingAllowed}; Path=/; Max-Age=${maxAge}; SameSite=Lax${secure}${domain}`;
|
|
327
|
+
}
|
|
328
|
+
deleteCookie() {
|
|
329
|
+
if (typeof document === 'undefined')
|
|
330
|
+
return;
|
|
331
|
+
const domain = this.config.cookieDomain ? `; Domain=${this.config.cookieDomain}` : '';
|
|
332
|
+
document.cookie = `${this.config.cookieName}=; Path=/; Max-Age=0${domain}`;
|
|
333
|
+
document.cookie = `${DEFAULT_TRACKING_COOKIE_NAME}=; Path=/; Max-Age=0${domain}`;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../src/lib/consent/manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAOH,+EAA+E;AAC/E,WAAW;AACX,+EAA+E;AAE/E,MAAM,mBAAmB,GAAG,YAAY,CAAC;AACzC,MAAM,4BAA4B,GAAG,qBAAqB,CAAC;AAC3D,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC,MAAM,mBAAmB,GAAuB;IAC9C,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,KAAK;IAChB,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,cAAc;IAQzB;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG;YACZ,UAAU,EAAE,MAAM,EAAE,UAAU,IAAI,mBAAmB;YACrD,UAAU,EAAE,MAAM,EAAE,UAAU,IAAI,mBAAmB;YACrD,YAAY,EAAE,MAAM,EAAE,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*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
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
|
-
* ```
|
|
120
|
+
* Pass this to your own UI implementation — `ConsentManager` handles the
|
|
121
|
+
* persistence; rendering is left to consumer code so the SDK stays
|
|
122
|
+
* framework-agnostic.
|
|
140
123
|
*/
|
|
141
124
|
export interface CookieBannerConfig {
|
|
142
125
|
/** Banner title. Defaults to `"Cookie Preferences"`. */
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/consent/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -37,13 +37,10 @@
|
|
|
37
37
|
* campaign: 'brand_terms',
|
|
38
38
|
* medium: 'cpc'
|
|
39
39
|
* });
|
|
40
|
-
*
|
|
41
|
-
* // Get attribution report
|
|
42
|
-
* const report = await attribution.getReport({ range: 'last30days' });
|
|
43
40
|
* ```
|
|
44
41
|
*/
|
|
45
42
|
import { FlowGridTransport } from "../../client/transport";
|
|
46
|
-
import { MoneyValue
|
|
43
|
+
import { MoneyValue } from "../../types";
|
|
47
44
|
/**
|
|
48
45
|
* Attribution model types.
|
|
49
46
|
*/
|
|
@@ -85,6 +82,8 @@ export interface ConversionEvent {
|
|
|
85
82
|
value?: MoneyValue;
|
|
86
83
|
/** Conversion identifier (e.g., order ID) */
|
|
87
84
|
conversionId?: string;
|
|
85
|
+
/** Custom properties */
|
|
86
|
+
properties?: Record<string, unknown>;
|
|
88
87
|
}
|
|
89
88
|
/**
|
|
90
89
|
* Touchpoint response from API.
|
|
@@ -170,11 +169,6 @@ export interface AttributionReportData {
|
|
|
170
169
|
* value: { amount: 9999, currency: 'USD' },
|
|
171
170
|
* conversionId: 'ORD-12345'
|
|
172
171
|
* });
|
|
173
|
-
*
|
|
174
|
-
* // Get attribution report
|
|
175
|
-
* const report = await attribution.getReport({
|
|
176
|
-
* model: 'linear'
|
|
177
|
-
* });
|
|
178
172
|
* ```
|
|
179
173
|
*/
|
|
180
174
|
export declare class Attribution extends FlowGridTransport {
|
|
@@ -214,44 +208,9 @@ export declare class Attribution extends FlowGridTransport {
|
|
|
214
208
|
*/
|
|
215
209
|
recordConversion(event: ConversionEvent): Promise<TouchpointResponse>;
|
|
216
210
|
/**
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
* @param options - Report options
|
|
220
|
-
* @returns Promise resolving to attribution report
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* ```typescript
|
|
224
|
-
* const report = await attribution.getReport({
|
|
225
|
-
* model: 'position_based',
|
|
226
|
-
* filter: { range: 'last30days' }
|
|
227
|
-
* });
|
|
228
|
-
*
|
|
229
|
-
* // Bar chart - revenue by channel
|
|
230
|
-
* const channelChart = report.byChannel.map(c => ({
|
|
231
|
-
* name: c.channel,
|
|
232
|
-
* value: c.attributedRevenue.amount
|
|
233
|
-
* }));
|
|
234
|
-
*
|
|
235
|
-
* // Sankey - top conversion paths
|
|
236
|
-
* const pathData = report.topPaths;
|
|
237
|
-
* ```
|
|
211
|
+
* Auto-capture a touchpoint from `utm_*` query params and `document.referrer`.
|
|
212
|
+
* Browser-only; returns null on the server or when no UTM/referrer data is present.
|
|
238
213
|
*/
|
|
239
|
-
|
|
240
|
-
model?: AttributionModel;
|
|
241
|
-
filter?: DateRangeFilter;
|
|
242
|
-
}): Promise<AttributionReportData>;
|
|
243
|
-
/**
|
|
244
|
-
* Gets user journey/path for a specific user.
|
|
245
|
-
*
|
|
246
|
-
* @param userId - User identifier
|
|
247
|
-
* @returns Promise resolving to user journey data
|
|
248
|
-
*/
|
|
249
|
-
getUserJourney(userId: string): Promise<{
|
|
250
|
-
touchpoints: Array<TouchpointConfig & {
|
|
251
|
-
timestamp: string;
|
|
252
|
-
}>;
|
|
253
|
-
conversions: ConversionEvent[];
|
|
254
|
-
totalValue: MoneyValue;
|
|
255
|
-
}>;
|
|
214
|
+
captureFromUrl(userId: string): TouchpointConfig | null;
|
|
256
215
|
}
|
|
257
216
|
export default Attribution;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Product Analytics - Revenue Attribution
|
|
3
|
+
* @module features/analytics/attribution
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Multi-touch attribution modeling to understand which marketing
|
|
7
|
+
* channels and touchpoints drive conversions and revenue.
|
|
8
|
+
*
|
|
9
|
+
* @useCases
|
|
10
|
+
* - Track marketing touchpoints across customer journey
|
|
11
|
+
* - Calculate attribution for conversions
|
|
12
|
+
* - Compare attribution models (first-touch, last-touch, linear)
|
|
13
|
+
* - Optimize marketing spend allocation
|
|
14
|
+
* - Understand channel effectiveness
|
|
15
|
+
*
|
|
16
|
+
* @metrics
|
|
17
|
+
* - Attributed revenue by channel
|
|
18
|
+
* - Conversion paths
|
|
19
|
+
* - Assisted conversions
|
|
20
|
+
* - Time to conversion
|
|
21
|
+
* - Channel influence score
|
|
22
|
+
*
|
|
23
|
+
* @chartData
|
|
24
|
+
* - Sankey diagram: Customer journey paths
|
|
25
|
+
* - Bar chart: Revenue by channel
|
|
26
|
+
* - Table: Attribution comparison by model
|
|
27
|
+
* - Pie chart: Channel contribution
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const attribution = new Attribution(webId, endpoint, apiKey);
|
|
32
|
+
*
|
|
33
|
+
* // Track touchpoint
|
|
34
|
+
* await attribution.trackTouchpoint({
|
|
35
|
+
* userId: 'user_123',
|
|
36
|
+
* channel: 'google_ads',
|
|
37
|
+
* campaign: 'brand_terms',
|
|
38
|
+
* medium: 'cpc'
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
import { FlowGridTransport } from "../../client/transport";
|
|
43
|
+
import { getWindow, getDocument, isBrowser } from "../../utils/browser";
|
|
44
|
+
// ============================================================================
|
|
45
|
+
// ATTRIBUTION CLASS
|
|
46
|
+
// ============================================================================
|
|
47
|
+
/**
|
|
48
|
+
* Attribution - Multi-touch attribution tracking.
|
|
49
|
+
*
|
|
50
|
+
* @extends FlowGridTransport
|
|
51
|
+
*
|
|
52
|
+
* @description
|
|
53
|
+
* Provides attribution capabilities including:
|
|
54
|
+
* - Touchpoint tracking
|
|
55
|
+
* - Conversion attribution
|
|
56
|
+
* - Multiple attribution models
|
|
57
|
+
* - Path analysis
|
|
58
|
+
* - Channel effectiveness
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const attribution = new Attribution(webId, endpoint, apiKey);
|
|
63
|
+
*
|
|
64
|
+
* // Track touchpoints throughout customer journey
|
|
65
|
+
* await attribution.trackTouchpoint({
|
|
66
|
+
* userId: 'user_123',
|
|
67
|
+
* channel: 'email',
|
|
68
|
+
* campaign: 'welcome_series',
|
|
69
|
+
* medium: 'email'
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* // Record conversion
|
|
73
|
+
* await attribution.recordConversion({
|
|
74
|
+
* userId: 'user_123',
|
|
75
|
+
* conversionType: 'purchase',
|
|
76
|
+
* value: { amount: 9999, currency: 'USD' },
|
|
77
|
+
* conversionId: 'ORD-12345'
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export class Attribution extends FlowGridTransport {
|
|
82
|
+
/**
|
|
83
|
+
* Tracks a marketing touchpoint.
|
|
84
|
+
*
|
|
85
|
+
* @param config - Touchpoint configuration
|
|
86
|
+
* @returns Promise resolving to touchpoint response
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* await attribution.trackTouchpoint({
|
|
91
|
+
* userId: 'user_123',
|
|
92
|
+
* channel: 'facebook_ads',
|
|
93
|
+
* campaign: 'retargeting_cart',
|
|
94
|
+
* medium: 'paid_social',
|
|
95
|
+
* landingPage: '/products/special-offer'
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
async trackTouchpoint(config) {
|
|
100
|
+
return await this.init("attribution_touchpoint", {
|
|
101
|
+
type: "attribution_touchpoint",
|
|
102
|
+
userId: config.userId,
|
|
103
|
+
channel: config.channel,
|
|
104
|
+
campaign: config.campaign,
|
|
105
|
+
medium: config.medium,
|
|
106
|
+
source: config.source,
|
|
107
|
+
content: config.content,
|
|
108
|
+
term: config.term,
|
|
109
|
+
referrer: config.referrer,
|
|
110
|
+
landingPage: config.landingPage,
|
|
111
|
+
...config.properties,
|
|
112
|
+
timestamp: new Date().toISOString()
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Records a conversion for attribution.
|
|
117
|
+
*
|
|
118
|
+
* @param event - Conversion event
|
|
119
|
+
* @returns Promise resolving to conversion response
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* await attribution.recordConversion({
|
|
124
|
+
* userId: 'user_123',
|
|
125
|
+
* conversionType: 'purchase',
|
|
126
|
+
* value: { amount: 14999, currency: 'USD' },
|
|
127
|
+
* conversionId: 'ORD-98765'
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
async recordConversion(event) {
|
|
132
|
+
return await this.init("attribution_conversion", {
|
|
133
|
+
type: "attribution_conversion",
|
|
134
|
+
userId: event.userId,
|
|
135
|
+
conversionType: event.conversionType,
|
|
136
|
+
value: event.value,
|
|
137
|
+
conversionId: event.conversionId,
|
|
138
|
+
...event.properties,
|
|
139
|
+
timestamp: new Date().toISOString()
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Auto-capture a touchpoint from `utm_*` query params and `document.referrer`.
|
|
144
|
+
* Browser-only; returns null on the server or when no UTM/referrer data is present.
|
|
145
|
+
*/
|
|
146
|
+
captureFromUrl(userId) {
|
|
147
|
+
if (!isBrowser())
|
|
148
|
+
return null;
|
|
149
|
+
const win = getWindow();
|
|
150
|
+
const doc = getDocument();
|
|
151
|
+
if (!win || !doc)
|
|
152
|
+
return null;
|
|
153
|
+
const params = new URLSearchParams(win.location.search);
|
|
154
|
+
const utm = {
|
|
155
|
+
utmSource: params.get("utm_source") ?? undefined,
|
|
156
|
+
utmMedium: params.get("utm_medium") ?? undefined,
|
|
157
|
+
utmCampaign: params.get("utm_campaign") ?? undefined,
|
|
158
|
+
utmTerm: params.get("utm_term") ?? undefined,
|
|
159
|
+
utmContent: params.get("utm_content") ?? undefined,
|
|
160
|
+
};
|
|
161
|
+
const referrer = doc.referrer || undefined;
|
|
162
|
+
if (!utm.utmSource && !utm.utmMedium && !utm.utmCampaign && !referrer) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
const config = {
|
|
166
|
+
userId,
|
|
167
|
+
channel: utm.utmSource || (referrer ? "referral" : "direct"),
|
|
168
|
+
campaign: utm.utmCampaign,
|
|
169
|
+
medium: utm.utmMedium,
|
|
170
|
+
source: utm.utmSource,
|
|
171
|
+
content: utm.utmContent,
|
|
172
|
+
term: utm.utmTerm,
|
|
173
|
+
referrer,
|
|
174
|
+
landingPage: win.location.pathname,
|
|
175
|
+
};
|
|
176
|
+
void this.trackTouchpoint(config);
|
|
177
|
+
return config;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
export default Attribution;
|
|
181
|
+
//# sourceMappingURL=attribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribution.js","sourceRoot":"","sources":["../../../../src/lib/features/analytics/attribution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAO3D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAiHxE,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,OAAO,WAAY,SAAQ,iBAAiB;IAChD;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,eAAe,CAAC,MAAwB;QAC5C,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,wBAAwB,EAAE;YAC/C,IAAI,EAAE,wBAAwB;YAC9B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,QAAQ,EAA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