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,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Product Analytics - Heatmaps & Click Tracking
|
|
3
|
+
* @module features/analytics/heatmaps
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Track user interactions for heatmap visualization including
|
|
7
|
+
* clicks, mouse movements, and scroll behavior.
|
|
8
|
+
*
|
|
9
|
+
* @useCases
|
|
10
|
+
* - Visualize click patterns on pages
|
|
11
|
+
* - Identify dead zones and ignored elements
|
|
12
|
+
* - Analyze scroll depth and attention
|
|
13
|
+
* - Optimize CTA placement
|
|
14
|
+
* - Improve page layout based on behavior
|
|
15
|
+
*
|
|
16
|
+
* @metrics
|
|
17
|
+
* - Click coordinates and density
|
|
18
|
+
* - Scroll depth distribution
|
|
19
|
+
* - Attention time by viewport
|
|
20
|
+
* - Element interaction rates
|
|
21
|
+
* - Rage clicks detection
|
|
22
|
+
*
|
|
23
|
+
* @chartData
|
|
24
|
+
* - Heatmap: Click density overlay
|
|
25
|
+
* - Scroll map: Attention by page section
|
|
26
|
+
* - Element report: Interaction by element
|
|
27
|
+
* - Rage click detection
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const heatmaps = new Heatmaps(webId, endpoint, apiKey);
|
|
32
|
+
*
|
|
33
|
+
* // Track click
|
|
34
|
+
* await heatmaps.trackClick({
|
|
35
|
+
* pageUrl: '/pricing',
|
|
36
|
+
* x: 450,
|
|
37
|
+
* y: 320,
|
|
38
|
+
* viewportWidth: 1920,
|
|
39
|
+
* viewportHeight: 1080
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
import { FlowGridTransport } from "../../client/transport";
|
|
44
|
+
import { getWindow, getDocument, isBrowser, combineTeardowns } from "../../utils/browser";
|
|
45
|
+
// ============================================================================
|
|
46
|
+
// HEATMAPS CLASS
|
|
47
|
+
// ============================================================================
|
|
48
|
+
/**
|
|
49
|
+
* Heatmaps - Track user interactions for heatmap visualization.
|
|
50
|
+
*
|
|
51
|
+
* @extends FlowGridTransport
|
|
52
|
+
*
|
|
53
|
+
* @description
|
|
54
|
+
* Provides heatmap data collection including:
|
|
55
|
+
* - Click tracking with coordinates
|
|
56
|
+
* - Mouse movement tracking
|
|
57
|
+
* - Scroll depth tracking
|
|
58
|
+
* - Element interaction tracking
|
|
59
|
+
* - Rage click detection
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const heatmaps = new Heatmaps(webId, endpoint, apiKey);
|
|
64
|
+
*
|
|
65
|
+
* // Track clicks
|
|
66
|
+
* document.addEventListener('click', (e) => {
|
|
67
|
+
* heatmaps.trackClick({
|
|
68
|
+
* pageUrl: window.location.pathname,
|
|
69
|
+
* x: e.clientX,
|
|
70
|
+
* y: e.clientY + window.scrollY,
|
|
71
|
+
* viewportWidth: window.innerWidth,
|
|
72
|
+
* viewportHeight: window.innerHeight,
|
|
73
|
+
* elementSelector: getSelector(e.target)
|
|
74
|
+
* });
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* // Get heatmap data for visualization
|
|
78
|
+
* const data = await heatmaps.getData('/pricing', { range: 'last7days' });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export class Heatmaps extends FlowGridTransport {
|
|
82
|
+
constructor() {
|
|
83
|
+
super(...arguments);
|
|
84
|
+
/** Throttle timestamps */
|
|
85
|
+
this.lastMovementTime = 0;
|
|
86
|
+
this.lastScrollTime = 0;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Tracks a click interaction.
|
|
90
|
+
*
|
|
91
|
+
* @param data - Click data
|
|
92
|
+
* @returns Promise resolving to heatmap response
|
|
93
|
+
*/
|
|
94
|
+
async trackClick(data) {
|
|
95
|
+
return await this.init("heatmap_click", {
|
|
96
|
+
type: "heatmap_click",
|
|
97
|
+
pageUrl: data.pageUrl,
|
|
98
|
+
x: data.x,
|
|
99
|
+
y: data.y,
|
|
100
|
+
normalizedX: data.x / data.viewportWidth,
|
|
101
|
+
normalizedY: data.y / data.viewportHeight,
|
|
102
|
+
viewportWidth: data.viewportWidth,
|
|
103
|
+
viewportHeight: data.viewportHeight,
|
|
104
|
+
elementSelector: data.elementSelector,
|
|
105
|
+
elementText: data.elementText?.substring(0, 50),
|
|
106
|
+
userId: data.userId,
|
|
107
|
+
sessionId: data.sessionId,
|
|
108
|
+
timestamp: new Date().toISOString()
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Tracks mouse movement path.
|
|
113
|
+
*
|
|
114
|
+
* @param data - Movement data
|
|
115
|
+
* @returns Promise resolving to heatmap response
|
|
116
|
+
*/
|
|
117
|
+
async trackMovement(data) {
|
|
118
|
+
const now = Date.now();
|
|
119
|
+
if (now - this.lastMovementTime < Heatmaps.MOVEMENT_THROTTLE_MS) {
|
|
120
|
+
return { eventName: 'heatmap_movement', properties: {}, response: { recorded: false, interactionId: '' }, timestamp: new Date().toISOString() };
|
|
121
|
+
}
|
|
122
|
+
this.lastMovementTime = now;
|
|
123
|
+
return await this.init("heatmap_movement", {
|
|
124
|
+
type: "heatmap_movement",
|
|
125
|
+
pageUrl: data.pageUrl,
|
|
126
|
+
path: data.path,
|
|
127
|
+
viewport: data.viewport,
|
|
128
|
+
sessionId: data.sessionId,
|
|
129
|
+
timestamp: new Date().toISOString()
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Tracks scroll behavior.
|
|
134
|
+
*
|
|
135
|
+
* @param data - Scroll data
|
|
136
|
+
* @returns Promise resolving to heatmap response
|
|
137
|
+
*/
|
|
138
|
+
async trackScroll(data) {
|
|
139
|
+
const now = Date.now();
|
|
140
|
+
if (now - this.lastScrollTime < Heatmaps.SCROLL_THROTTLE_MS) {
|
|
141
|
+
return { eventName: 'heatmap_scroll', properties: {}, response: { recorded: false, interactionId: '' }, timestamp: new Date().toISOString() };
|
|
142
|
+
}
|
|
143
|
+
this.lastScrollTime = now;
|
|
144
|
+
return await this.init("heatmap_scroll", {
|
|
145
|
+
type: "heatmap_scroll",
|
|
146
|
+
pageUrl: data.pageUrl,
|
|
147
|
+
maxScrollDepth: data.maxScrollDepth,
|
|
148
|
+
pageHeight: data.pageHeight,
|
|
149
|
+
viewportHeight: data.viewportHeight,
|
|
150
|
+
timeAtDepths: data.timeAtDepths,
|
|
151
|
+
sessionId: data.sessionId,
|
|
152
|
+
timestamp: new Date().toISOString()
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Tracks rage clicks (repeated clicks in frustration).
|
|
157
|
+
*
|
|
158
|
+
* @param pageUrl - Page URL
|
|
159
|
+
* @param x - X coordinate
|
|
160
|
+
* @param y - Y coordinate
|
|
161
|
+
* @param clickCount - Number of rapid clicks
|
|
162
|
+
* @returns Promise resolving to heatmap response
|
|
163
|
+
*/
|
|
164
|
+
async trackRageClick(pageUrl, x, y, clickCount) {
|
|
165
|
+
return await this.init("heatmap_rage_click", {
|
|
166
|
+
type: "heatmap_rage_click",
|
|
167
|
+
pageUrl,
|
|
168
|
+
x,
|
|
169
|
+
y,
|
|
170
|
+
clickCount,
|
|
171
|
+
timestamp: new Date().toISOString()
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Auto-collect heatmap interactions: clicks (with element selector + text)
|
|
176
|
+
* and scroll depth on the current page. Mouse-move tracking is opt-in
|
|
177
|
+
* because the volume can be very high.
|
|
178
|
+
*
|
|
179
|
+
* @param options.movement Subscribe to throttled mousemove sampling.
|
|
180
|
+
* @param options.userId Attached to every event.
|
|
181
|
+
* @returns Teardown function detaching all listeners.
|
|
182
|
+
*/
|
|
183
|
+
autoTrack(options = {}) {
|
|
184
|
+
if (!isBrowser())
|
|
185
|
+
return () => { };
|
|
186
|
+
const win = getWindow();
|
|
187
|
+
const doc = getDocument();
|
|
188
|
+
const selectorOf = (el) => {
|
|
189
|
+
if (!el)
|
|
190
|
+
return "";
|
|
191
|
+
if (el.id)
|
|
192
|
+
return `#${el.id}`;
|
|
193
|
+
const tag = el.tagName.toLowerCase();
|
|
194
|
+
const cls = (el.className && typeof el.className === "string")
|
|
195
|
+
? "." + el.className.trim().split(/\s+/).slice(0, 2).join(".")
|
|
196
|
+
: "";
|
|
197
|
+
return `${tag}${cls}`;
|
|
198
|
+
};
|
|
199
|
+
const onClick = (e) => {
|
|
200
|
+
const target = e.target;
|
|
201
|
+
void this.trackClick({
|
|
202
|
+
pageUrl: win.location.pathname,
|
|
203
|
+
x: e.clientX,
|
|
204
|
+
y: e.clientY + win.scrollY,
|
|
205
|
+
viewportWidth: win.innerWidth,
|
|
206
|
+
viewportHeight: win.innerHeight,
|
|
207
|
+
elementSelector: selectorOf(target),
|
|
208
|
+
elementText: (target?.textContent || "").trim().slice(0, 50),
|
|
209
|
+
userId: options.userId,
|
|
210
|
+
sessionId: options.sessionId,
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
doc.addEventListener("click", onClick, { capture: true, passive: true });
|
|
214
|
+
let maxDepth = 0;
|
|
215
|
+
const onScroll = () => {
|
|
216
|
+
const docEl = doc.documentElement;
|
|
217
|
+
const top = win.scrollY || docEl.scrollTop;
|
|
218
|
+
const height = Math.max(1, docEl.scrollHeight - win.innerHeight);
|
|
219
|
+
const depth = Math.min(100, Math.round((top / height) * 100));
|
|
220
|
+
if (depth > maxDepth)
|
|
221
|
+
maxDepth = depth;
|
|
222
|
+
void this.trackScroll({
|
|
223
|
+
pageUrl: win.location.pathname,
|
|
224
|
+
maxScrollDepth: maxDepth,
|
|
225
|
+
pageHeight: docEl.scrollHeight,
|
|
226
|
+
viewportHeight: win.innerHeight,
|
|
227
|
+
sessionId: options.sessionId,
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
win.addEventListener("scroll", onScroll, { passive: true });
|
|
231
|
+
let moveTeardown;
|
|
232
|
+
if (options.movement) {
|
|
233
|
+
let buffer = [];
|
|
234
|
+
const start = Date.now();
|
|
235
|
+
const onMove = (e) => {
|
|
236
|
+
buffer.push({ x: e.clientX, y: e.clientY, t: Date.now() - start });
|
|
237
|
+
if (buffer.length >= 50) {
|
|
238
|
+
const path = buffer;
|
|
239
|
+
buffer = [];
|
|
240
|
+
void this.trackMovement({
|
|
241
|
+
pageUrl: win.location.pathname,
|
|
242
|
+
path,
|
|
243
|
+
viewport: { width: win.innerWidth, height: win.innerHeight },
|
|
244
|
+
sessionId: options.sessionId,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
doc.addEventListener("mousemove", onMove, { passive: true });
|
|
249
|
+
moveTeardown = () => doc.removeEventListener("mousemove", onMove);
|
|
250
|
+
}
|
|
251
|
+
return combineTeardowns(() => doc.removeEventListener("click", onClick, { capture: true }), () => win.removeEventListener("scroll", onScroll), moveTeardown);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/** Throttle intervals (ms) */
|
|
255
|
+
Heatmaps.MOVEMENT_THROTTLE_MS = 100;
|
|
256
|
+
Heatmaps.SCROLL_THROTTLE_MS = 500;
|
|
257
|
+
export default Heatmaps;
|
|
258
|
+
//# sourceMappingURL=heatmaps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heatmaps.js","sourceRoot":"","sources":["../../../../src/lib/features/analytics/heatmaps.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,gBAAgB,EAAY,MAAM,qBAAqB,CAAC;AAuHpG,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,OAAO,QAAS,SAAQ,iBAAiB;IAA/C;;QAEE,0BAA0B;QAClB,qBAAgB,GAAG,CAAC,CAAC;QACrB,mBAAc,GAAG,CAAC,CAAC;IA0L7B,CAAC;IApLC;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CAAC,IAAe;QAC9B,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACtC,IAAI,EAAE,eAAe;YACrB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,CAAC,EAAE,IAAI,CAAC,CAAC;YACT,CAAC,EAAE,IAAI,CAAC,CAAC;YACT,WAAW,EAAE,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,aAAa;YACxC,WAAW,EAAE,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,cAAc;YACzC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,eA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imeSeriesData } from "../../types";
|
|
47
47
|
/**
|
|
48
48
|
* Configuration for identifying a user.
|
|
49
49
|
*/
|
|
@@ -249,25 +249,5 @@ export declare class Identify extends FlowGridTransport {
|
|
|
249
249
|
* @returns Promise resolving to reset response
|
|
250
250
|
*/
|
|
251
251
|
reset(userId: string): Promise<IdentifyResponse>;
|
|
252
|
-
/**
|
|
253
|
-
* Retrieves user analytics data for dashboards and charts.
|
|
254
|
-
*
|
|
255
|
-
* @param filter - Date range filter
|
|
256
|
-
* @returns Promise resolving to user analytics
|
|
257
|
-
*
|
|
258
|
-
* @example
|
|
259
|
-
* ```typescript
|
|
260
|
-
* const analytics = await identify.getAnalytics({
|
|
261
|
-
* range: 'last30days'
|
|
262
|
-
* });
|
|
263
|
-
*
|
|
264
|
-
* // Pie chart - users by plan
|
|
265
|
-
* const planData = analytics.byPlan.map(p => ({
|
|
266
|
-
* name: p.plan,
|
|
267
|
-
* value: p.count
|
|
268
|
-
* }));
|
|
269
|
-
* ```
|
|
270
|
-
*/
|
|
271
|
-
getAnalytics(filter?: DateRangeFilter): Promise<UserAnalyticsData>;
|
|
272
252
|
}
|
|
273
253
|
export default Identify;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Product Analytics - User Identification & Traits
|
|
3
|
+
* @module features/analytics/identify
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Identify users and track their traits for personalization,
|
|
7
|
+
* segmentation, and cohort analysis.
|
|
8
|
+
*
|
|
9
|
+
* @useCases
|
|
10
|
+
* - Link anonymous sessions to authenticated users
|
|
11
|
+
* - Store user profile data for segmentation
|
|
12
|
+
* - Track user lifecycle changes (signup, upgrade, churn)
|
|
13
|
+
* - Enable personalized experiences
|
|
14
|
+
* - Build user cohorts for analysis
|
|
15
|
+
*
|
|
16
|
+
* @metrics
|
|
17
|
+
* - Total identified users
|
|
18
|
+
* - Anonymous to identified conversion rate
|
|
19
|
+
* - Users by plan/segment
|
|
20
|
+
* - User lifetime value distribution
|
|
21
|
+
* - Trait distribution
|
|
22
|
+
*
|
|
23
|
+
* @chartData
|
|
24
|
+
* - Pie chart: Users by plan
|
|
25
|
+
* - Bar chart: Users by trait value
|
|
26
|
+
* - Line chart: New identifications over time
|
|
27
|
+
* - Table: User segments
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const identify = new Identify(webId, endpoint, apiKey);
|
|
32
|
+
*
|
|
33
|
+
* // Identify user on login
|
|
34
|
+
* await identify.user({
|
|
35
|
+
* userId: 'user_123',
|
|
36
|
+
* traits: {
|
|
37
|
+
* email: 'user@example.com',
|
|
38
|
+
* name: 'John Doe',
|
|
39
|
+
* plan: 'premium',
|
|
40
|
+
* createdAt: '2025-01-15'
|
|
41
|
+
* }
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
import { FlowGridTransport } from "../../client/transport";
|
|
46
|
+
// ============================================================================
|
|
47
|
+
// IDENTIFY CLASS
|
|
48
|
+
// ============================================================================
|
|
49
|
+
/**
|
|
50
|
+
* Identify - User identification and trait management.
|
|
51
|
+
*
|
|
52
|
+
* @extends FlowGridTransport
|
|
53
|
+
*
|
|
54
|
+
* @description
|
|
55
|
+
* Provides user identification capabilities including:
|
|
56
|
+
* - User identification on login/signup
|
|
57
|
+
* - Anonymous to identified user linking
|
|
58
|
+
* - User trait/property storage
|
|
59
|
+
* - User aliasing for ID changes
|
|
60
|
+
* - Group/company association
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const identify = new Identify(webId, endpoint, apiKey);
|
|
65
|
+
*
|
|
66
|
+
* // On user signup
|
|
67
|
+
* await identify.user({
|
|
68
|
+
* userId: 'user_123',
|
|
69
|
+
* anonymousId: getAnonymousId(),
|
|
70
|
+
* traits: {
|
|
71
|
+
* email: 'user@example.com',
|
|
72
|
+
* name: 'Jane Smith',
|
|
73
|
+
* plan: 'starter',
|
|
74
|
+
* createdAt: new Date().toISOString()
|
|
75
|
+
* }
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* // Associate user with company
|
|
79
|
+
* await identify.group({
|
|
80
|
+
* userId: 'user_123',
|
|
81
|
+
* groupId: 'company_456',
|
|
82
|
+
* traits: { name: 'Acme Inc', employees: 50 }
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export class Identify extends FlowGridTransport {
|
|
87
|
+
/**
|
|
88
|
+
* Identifies a user with traits.
|
|
89
|
+
*
|
|
90
|
+
* @param config - Identification configuration
|
|
91
|
+
* @returns Promise resolving to identify response
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* // Basic identification
|
|
96
|
+
* await identify.user({
|
|
97
|
+
* userId: 'user_123',
|
|
98
|
+
* traits: { email: 'user@example.com' }
|
|
99
|
+
* });
|
|
100
|
+
*
|
|
101
|
+
* // With anonymous ID linking
|
|
102
|
+
* await identify.user({
|
|
103
|
+
* userId: 'user_123',
|
|
104
|
+
* anonymousId: localStorage.getItem('anonId'),
|
|
105
|
+
* traits: {
|
|
106
|
+
* name: 'John Doe',
|
|
107
|
+
* plan: 'premium',
|
|
108
|
+
* ltv: { amount: 29900, currency: 'USD' }
|
|
109
|
+
* }
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
async user(config) {
|
|
114
|
+
return await this.init("identify_user", {
|
|
115
|
+
type: "identify",
|
|
116
|
+
userId: config.userId,
|
|
117
|
+
anonymousId: config.anonymousId,
|
|
118
|
+
traits: config.traits || {},
|
|
119
|
+
timestamp: new Date().toISOString()
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Updates traits for an existing user.
|
|
124
|
+
*
|
|
125
|
+
* @param userId - User identifier
|
|
126
|
+
* @param traits - Traits to update/add
|
|
127
|
+
* @returns Promise resolving to identify response
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* // Update user plan after upgrade
|
|
132
|
+
* await identify.updateTraits('user_123', {
|
|
133
|
+
* plan: 'enterprise',
|
|
134
|
+
* ltv: { amount: 99900, currency: 'USD' }
|
|
135
|
+
* });
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
async updateTraits(userId, traits) {
|
|
139
|
+
return await this.init("update_traits", {
|
|
140
|
+
type: "update_traits",
|
|
141
|
+
userId,
|
|
142
|
+
traits,
|
|
143
|
+
timestamp: new Date().toISOString()
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Creates an alias between two user IDs.
|
|
148
|
+
*
|
|
149
|
+
* @param config - Alias configuration
|
|
150
|
+
* @returns Promise resolving to alias response
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* // When user ID changes (e.g., after migration)
|
|
155
|
+
* await identify.alias({
|
|
156
|
+
* previousId: 'old_user_id',
|
|
157
|
+
* userId: 'new_user_id'
|
|
158
|
+
* });
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
async alias(config) {
|
|
162
|
+
return await this.init("alias_user", {
|
|
163
|
+
type: "alias",
|
|
164
|
+
previousId: config.previousId,
|
|
165
|
+
userId: config.userId,
|
|
166
|
+
timestamp: new Date().toISOString()
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Associates a user with a group/company.
|
|
171
|
+
*
|
|
172
|
+
* @param config - Group configuration
|
|
173
|
+
* @returns Promise resolving to group response
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* await identify.group({
|
|
178
|
+
* userId: 'user_123',
|
|
179
|
+
* groupId: 'company_456',
|
|
180
|
+
* traits: {
|
|
181
|
+
* name: 'Acme Corporation',
|
|
182
|
+
* industry: 'Technology',
|
|
183
|
+
* employees: 500,
|
|
184
|
+
* plan: 'enterprise'
|
|
185
|
+
* }
|
|
186
|
+
* });
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
async group(config) {
|
|
190
|
+
return await this.init("group_user", {
|
|
191
|
+
type: "group",
|
|
192
|
+
userId: config.userId,
|
|
193
|
+
groupId: config.groupId,
|
|
194
|
+
traits: config.traits || {},
|
|
195
|
+
timestamp: new Date().toISOString()
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Resets user identity (logout).
|
|
200
|
+
*
|
|
201
|
+
* @param userId - User ID to reset
|
|
202
|
+
* @returns Promise resolving to reset response
|
|
203
|
+
*/
|
|
204
|
+
async reset(userId) {
|
|
205
|
+
return await this.init("reset_identity", {
|
|
206
|
+
type: "reset",
|
|
207
|
+
userId,
|
|
208
|
+
timestamp: new Date().toISOString()
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
export default Identify;
|
|
213
|
+
//# sourceMappingURL=identify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identify.js","sourceRoot":"","sources":["../../../../src/lib/features/analytics/identify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAkG3D,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,OAAO,QAAS,SAAQ,iBAAiB;IAC7C;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,KAAK,CAAC,IAAI,CAAC,MAAsB;QAC/B,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACtC,IAAI,EAAE,UAAU;YAChB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,WAAW,EAAE,MAAM,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AAC,WAAW,EAAE;SACpC,CAAC,CAAC;IACL,CAAC;CAEF;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -11,6 +11,8 @@ export { Retention } from './retention';
|
|
|
11
11
|
export { Attribution } from './attribution';
|
|
12
12
|
export { Heatmaps } from './heatmaps';
|
|
13
13
|
export { PerformanceTracking, PerformanceTracking as Performance } from './performance';
|
|
14
|
+
export { SessionReplay } from './replay';
|
|
15
|
+
export type { ReplayPrivacyMetadata, SessionReplayDropMetadata, SessionReplayErrorContext, SessionReplayFlushMetadata, SessionReplayFlushReason, SessionReplayOptions, SessionReplaySendChunkOptions, SessionReplayState, SessionReplayStatus, } from './replay';
|
|
14
16
|
export type { PageViewConfig, ScrollDepthConfig, TimeOnPageConfig, PageViewResponse, PageAnalyticsData } from './page-views';
|
|
15
17
|
export type { SessionStartConfig, SessionResponse, SessionEndResponse, SessionAnalyticsData, RealTimeSessionData } from './sessions';
|
|
16
18
|
export type { EventTrackConfig, BatchEventConfig, EventResponse, BatchEventResponse, EventAnalyticsData } from './events';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Analytics features barrel export
|
|
3
|
+
* @module features/analytics
|
|
4
|
+
*/
|
|
5
|
+
export { PageViews } from './page-views';
|
|
6
|
+
export { Sessions } from './sessions';
|
|
7
|
+
export { Events } from './events';
|
|
8
|
+
export { Identify } from './identify';
|
|
9
|
+
export { Funnels } from './funnels';
|
|
10
|
+
export { Retention } from './retention';
|
|
11
|
+
export { Attribution } from './attribution';
|
|
12
|
+
export { Heatmaps } from './heatmaps';
|
|
13
|
+
export { PerformanceTracking, PerformanceTracking as Performance } from './performance';
|
|
14
|
+
export { SessionReplay } from './replay';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/features/analytics/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
* ```
|
|
48
48
|
*/
|
|
49
49
|
import { FlowGridTransport } from "../../client/transport";
|
|
50
|
-
import {
|
|
50
|
+
import { Teardown } from "../../utils/browser";
|
|
51
|
+
import { TimeSeriesData } from "../../types";
|
|
51
52
|
/**
|
|
52
53
|
* Configuration for tracking a page view.
|
|
53
54
|
*/
|
|
@@ -148,17 +149,6 @@ export interface PageAnalyticsData {
|
|
|
148
149
|
* path: '/products',
|
|
149
150
|
* title: 'Our Products'
|
|
150
151
|
* });
|
|
151
|
-
*
|
|
152
|
-
* // Pull analytics data for charts
|
|
153
|
-
* const analytics = await pageViews.getAnalytics({
|
|
154
|
-
* range: 'last30days'
|
|
155
|
-
* });
|
|
156
|
-
*
|
|
157
|
-
* // Data ready for charting
|
|
158
|
-
* const chartData = analytics.timeSeries.data.map(d => ({
|
|
159
|
-
* x: d.label,
|
|
160
|
-
* y: d.value
|
|
161
|
-
* }));
|
|
162
152
|
* ```
|
|
163
153
|
*/
|
|
164
154
|
export declare class PageViews extends FlowGridTransport {
|
|
@@ -223,28 +213,21 @@ export declare class PageViews extends FlowGridTransport {
|
|
|
223
213
|
*/
|
|
224
214
|
trackExit(path: string, duration: number, scrollDepth: number): Promise<PageViewResponse>;
|
|
225
215
|
/**
|
|
226
|
-
*
|
|
216
|
+
* Auto-track page views for both classic full-page navigations and SPA
|
|
217
|
+
* route changes (history.pushState / replaceState / popstate). Also wires
|
|
218
|
+
* scroll-depth thresholds (25/50/75/100%) and a final time-on-page event
|
|
219
|
+
* when the page is hidden or unloaded.
|
|
227
220
|
*
|
|
228
|
-
* @
|
|
229
|
-
* @param pagination - Pagination options
|
|
230
|
-
* @returns Promise resolving to analytics data
|
|
221
|
+
* @returns A teardown function that detaches every listener.
|
|
231
222
|
*
|
|
232
223
|
* @example
|
|
233
|
-
* ```
|
|
234
|
-
* const
|
|
235
|
-
* range: 'last7days'
|
|
236
|
-
* });
|
|
237
|
-
*
|
|
238
|
-
* // Use for line chart
|
|
239
|
-
* const lineData = analytics.timeSeries.data;
|
|
240
|
-
*
|
|
241
|
-
* // Use for bar chart
|
|
242
|
-
* const barData = analytics.topPages.map(p => ({
|
|
243
|
-
* label: p.path,
|
|
244
|
-
* value: p.views
|
|
245
|
-
* }));
|
|
224
|
+
* ```ts
|
|
225
|
+
* const stop = fg.pageViews.client.autoTrack({ userId: "u_1" });
|
|
246
226
|
* ```
|
|
247
227
|
*/
|
|
248
|
-
|
|
228
|
+
autoTrack(options?: {
|
|
229
|
+
userId?: string;
|
|
230
|
+
sessionId?: string;
|
|
231
|
+
}): Teardown;
|
|
249
232
|
}
|
|
250
233
|
export default PageViews;
|