@stacksjs/ts-analytics 0.1.6
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/CHANGELOG.md +68 -0
- package/LICENSE.md +21 -0
- package/README.md +361 -0
- package/bin/cli.ts +169 -0
- package/dist/Analytics.d.ts +558 -0
- package/dist/api.d.ts +109 -0
- package/dist/batching.d.ts +93 -0
- package/dist/chunk-2mx7fq49.js +4 -0
- package/dist/chunk-3z29508k.js +204 -0
- package/dist/chunk-deephkz6.js +56 -0
- package/dist/chunk-j261vgyp.js +305 -0
- package/dist/chunk-xga17tz7.js +207 -0
- package/dist/config.d.ts +132 -0
- package/dist/dashboard/components/index.d.ts +80 -0
- package/dist/dashboard/composables/useAnalytics.d.ts +99 -0
- package/dist/dashboard/index.d.ts +110 -0
- package/dist/dashboard/types/index.d.ts +144 -0
- package/dist/dashboard/utils/index.d.ts +81 -0
- package/dist/dynamodb.d.ts +86 -0
- package/dist/funnels.d.ts +104 -0
- package/dist/geolocation.d.ts +96 -0
- package/dist/index.d.ts +371 -0
- package/dist/index.js +10211 -0
- package/dist/infrastructure/cdk.d.ts +60 -0
- package/dist/infrastructure/cloudformation.d.ts +44 -0
- package/dist/infrastructure/index.d.ts +45 -0
- package/dist/infrastructure/setup.d.ts +133 -0
- package/dist/integrations/cloudflare.d.ts +76 -0
- package/dist/integrations/hono.d.ts +60 -0
- package/dist/integrations/index.d.ts +24 -0
- package/dist/integrations/nuxt.d.ts +7 -0
- package/dist/integrations/nuxt.js +42 -0
- package/dist/integrations/runtime/use-ts-analytics.d.ts +18 -0
- package/dist/integrations/runtime/use-ts-analytics.js +17 -0
- package/dist/integrations/stx.d.ts +88 -0
- package/dist/integrations/stx.js +18 -0
- package/dist/lib/crypto-random.d.ts +4 -0
- package/dist/lib/salt.d.ts +16 -0
- package/dist/local.d.ts +56 -0
- package/dist/model-connector.d.ts +145 -0
- package/dist/models/AggregatedStats.d.ts +9 -0
- package/dist/models/CampaignStats.d.ts +9 -0
- package/dist/models/Conversion.d.ts +11 -0
- package/dist/models/CustomEvent.d.ts +11 -0
- package/dist/models/DeviceStats.d.ts +9 -0
- package/dist/models/EventStats.d.ts +9 -0
- package/dist/models/GeoStats.d.ts +9 -0
- package/dist/models/Goal.d.ts +9 -0
- package/dist/models/GoalStats.d.ts +9 -0
- package/dist/models/PageStats.d.ts +11 -0
- package/dist/models/PageView.d.ts +13 -0
- package/dist/models/RealtimeStats.d.ts +9 -0
- package/dist/models/ReferrerStats.d.ts +9 -0
- package/dist/models/Session.d.ts +11 -0
- package/dist/models/Site.d.ts +11 -0
- package/dist/models/index.d.ts +28 -0
- package/dist/models/types.d.ts +60 -0
- package/dist/sqs-buffering.d.ts +243 -0
- package/dist/stacks-integration.d.ts +159 -0
- package/dist/tracking-script.d.ts +71 -0
- package/dist/tracking.d.ts +17 -0
- package/dist/tracking.js +26 -0
- package/dist/types.d.ts +595 -0
- package/dist/utils/geolocation.d.ts +111 -0
- package/dist/utils/user-agent.d.ts +17 -0
- package/dist/version.d.ts +7 -0
- package/package.json +119 -0
- package/src/Analytics.ts +3349 -0
- package/src/api.ts +1286 -0
- package/src/assets/crosswind.css +2220 -0
- package/src/batching.ts +452 -0
- package/src/components/dashboard/index.ts +18 -0
- package/src/config.ts +456 -0
- package/src/dashboard/Dashboard.stx +1517 -0
- package/src/dashboard/components/AlertCard.stx +177 -0
- package/src/dashboard/components/AnalyticsDashboard.stx +354 -0
- package/src/dashboard/components/AnimatedNumber.stx +86 -0
- package/src/dashboard/components/BarChart.stx +220 -0
- package/src/dashboard/components/BrowserBreakdown.stx +98 -0
- package/src/dashboard/components/BrowsersTable.stx +125 -0
- package/src/dashboard/components/CampaignBreakdown.stx +163 -0
- package/src/dashboard/components/CampaignTable.stx +238 -0
- package/src/dashboard/components/CountryList.stx +101 -0
- package/src/dashboard/components/DataTable.stx +226 -0
- package/src/dashboard/components/DateRangePicker.stx +77 -0
- package/src/dashboard/components/DeviceBreakdown.stx +94 -0
- package/src/dashboard/components/DevicesTable.stx +163 -0
- package/src/dashboard/components/DonutChart.stories.ts +55 -0
- package/src/dashboard/components/DonutChart.stx +157 -0
- package/src/dashboard/components/EmptyState.stx +90 -0
- package/src/dashboard/components/EngagementMetrics.stx +183 -0
- package/src/dashboard/components/EventsSection.stx +192 -0
- package/src/dashboard/components/FilterBar.stx +104 -0
- package/src/dashboard/components/FullAnalyticsDashboard.stx +455 -0
- package/src/dashboard/components/FunnelChart.stx +142 -0
- package/src/dashboard/components/GeoTable.stx +337 -0
- package/src/dashboard/components/GoalsPanel.stx +109 -0
- package/src/dashboard/components/Header.stx +39 -0
- package/src/dashboard/components/HeatmapChart.stx +140 -0
- package/src/dashboard/components/LiveActivityFeed.stx +172 -0
- package/src/dashboard/components/MetricComparison.stx +106 -0
- package/src/dashboard/components/MiniStats.stx +96 -0
- package/src/dashboard/components/OSBreakdown.stx +124 -0
- package/src/dashboard/components/PageDetailCard.stx +102 -0
- package/src/dashboard/components/PagesTable.stx +127 -0
- package/src/dashboard/components/ProgressRing.stx +89 -0
- package/src/dashboard/components/RealtimeCounter.stories.ts +45 -0
- package/src/dashboard/components/RealtimeCounter.stx +46 -0
- package/src/dashboard/components/ReferrersTable.stx +180 -0
- package/src/dashboard/components/SparklineChart.stx +160 -0
- package/src/dashboard/components/StatCard.stories.ts +58 -0
- package/src/dashboard/components/StatCard.stx +90 -0
- package/src/dashboard/components/SummaryStats.stx +81 -0
- package/src/dashboard/components/TabNav.stx +66 -0
- package/src/dashboard/components/ThemeSwitcher.stx +124 -0
- package/src/dashboard/components/TimeSeriesChart.stx +106 -0
- package/src/dashboard/components/TopList.stories.ts +58 -0
- package/src/dashboard/components/TopList.stx +74 -0
- package/src/dashboard/components/TrendIndicator.stx +84 -0
- package/src/dashboard/components/heatmap/ClickHeatmap.stx +264 -0
- package/src/dashboard/components/heatmap/ElementClickList.stx +125 -0
- package/src/dashboard/components/heatmap/HeatmapControls.stx +125 -0
- package/src/dashboard/components/heatmap/HeatmapLegend.stx +69 -0
- package/src/dashboard/components/heatmap/PageHeatmap.stx +264 -0
- package/src/dashboard/components/heatmap/ScrollHeatmap.stx +127 -0
- package/src/dashboard/components/heatmap/index.ts +12 -0
- package/src/dashboard/components/index.ts +86 -0
- package/src/dashboard/composables/useAnalytics.ts +465 -0
- package/src/dashboard/demo/DemoApp.stx +370 -0
- package/src/dashboard/demo/index.ts +8 -0
- package/src/dashboard/demo/mockData.ts +234 -0
- package/src/dashboard/index.ts +117 -0
- package/src/dashboard/stx-shim.d.ts +4 -0
- package/src/dashboard/types/index.ts +203 -0
- package/src/dashboard/utils/index.ts +426 -0
- package/src/dynamodb.ts +344 -0
- package/src/funnels.ts +534 -0
- package/src/geolocation.ts +515 -0
- package/src/handlers/alerts.ts +328 -0
- package/src/handlers/annotations.ts +128 -0
- package/src/handlers/api-keys.ts +240 -0
- package/src/handlers/auth.ts +1020 -0
- package/src/handlers/authz.ts +137 -0
- package/src/handlers/collect.ts +724 -0
- package/src/handlers/data.ts +625 -0
- package/src/handlers/experiments.ts +138 -0
- package/src/handlers/funnels.ts +216 -0
- package/src/handlers/goals.ts +218 -0
- package/src/handlers/heatmaps.ts +272 -0
- package/src/handlers/index.ts +56 -0
- package/src/handlers/lib/read-cache.ts +63 -0
- package/src/handlers/misc.ts +486 -0
- package/src/handlers/oauth.ts +233 -0
- package/src/handlers/performance.ts +388 -0
- package/src/handlers/sessions.ts +413 -0
- package/src/handlers/sharing.ts +198 -0
- package/src/handlers/stats.ts +1368 -0
- package/src/handlers/team.ts +161 -0
- package/src/handlers/uptime.ts +283 -0
- package/src/handlers/views.ts +390 -0
- package/src/handlers/webhooks.ts +226 -0
- package/src/heatmap/index.ts +32 -0
- package/src/heatmap/tracking-script.ts +452 -0
- package/src/heatmap/types.ts +79 -0
- package/src/index.ts +387 -0
- package/src/infrastructure/cdk.ts +496 -0
- package/src/infrastructure/cloudformation.ts +595 -0
- package/src/infrastructure/index.ts +48 -0
- package/src/infrastructure/setup.ts +611 -0
- package/src/integrations/cloudflare.ts +732 -0
- package/src/integrations/hono.ts +589 -0
- package/src/integrations/index.ts +27 -0
- package/src/integrations/nuxt.ts +78 -0
- package/src/integrations/runtime/use-ts-analytics.ts +32 -0
- package/src/integrations/stx.ts +138 -0
- package/src/jobs/index.ts +127 -0
- package/src/lib/crypto-random.ts +41 -0
- package/src/lib/ddb-errors.ts +20 -0
- package/src/lib/dynamodb.ts +216 -0
- package/src/lib/email.ts +38 -0
- package/src/lib/ga-import.ts +471 -0
- package/src/lib/ga4-api.ts +244 -0
- package/src/lib/goals.ts +205 -0
- package/src/lib/index.ts +6 -0
- package/src/lib/ingest-counters.ts +123 -0
- package/src/lib/log.ts +36 -0
- package/src/lib/membership.ts +98 -0
- package/src/lib/plans.ts +90 -0
- package/src/lib/quota.ts +46 -0
- package/src/lib/rate-limit.ts +27 -0
- package/src/lib/rollups.ts +472 -0
- package/src/lib/salt.ts +97 -0
- package/src/lib/scheduler.ts +97 -0
- package/src/lib/significance.ts +66 -0
- package/src/lib/site-retention.ts +56 -0
- package/src/local.ts +360 -0
- package/src/model-connector.ts +616 -0
- package/src/models/AggregatedStats.ts +162 -0
- package/src/models/CampaignStats.ts +141 -0
- package/src/models/Conversion.ts +135 -0
- package/src/models/CustomEvent.ts +123 -0
- package/src/models/DeviceStats.ts +105 -0
- package/src/models/EventStats.ts +108 -0
- package/src/models/GeoStats.ts +112 -0
- package/src/models/Goal.ts +105 -0
- package/src/models/GoalStats.ts +106 -0
- package/src/models/PageStats.ts +152 -0
- package/src/models/PageView.ts +277 -0
- package/src/models/RealtimeStats.ts +96 -0
- package/src/models/ReferrerStats.ts +115 -0
- package/src/models/Session.ts +235 -0
- package/src/models/Site.ts +115 -0
- package/src/models/index.ts +50 -0
- package/src/models/orm/index.ts +2043 -0
- package/src/models/types.ts +71 -0
- package/src/router.ts +521 -0
- package/src/sqs-buffering.ts +806 -0
- package/src/stacks-integration.ts +527 -0
- package/src/tracking-script.ts +944 -0
- package/src/tracking.ts +27 -0
- package/src/types/analytics.ts +219 -0
- package/src/types/api.ts +75 -0
- package/src/types/bun-router.d.ts +15 -0
- package/src/types/dashboard.ts +62 -0
- package/src/types/index.ts +66 -0
- package/src/types/stx.d.ts +27 -0
- package/src/types/window.d.ts +101 -0
- package/src/types.ts +911 -0
- package/src/utils/cache.ts +148 -0
- package/src/utils/date.ts +118 -0
- package/src/utils/filters.ts +71 -0
- package/src/utils/geolocation.ts +323 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/response.ts +180 -0
- package/src/utils/timezone-country.ts +242 -0
- package/src/utils/user-agent.ts +110 -0
- package/src/version.ts +7 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
export declare const defaultTheme: DashboardTheme;
|
|
2
|
+
export declare const darkTheme: DashboardTheme;
|
|
3
|
+
/**
|
|
4
|
+
* Analytics Dashboard Types
|
|
5
|
+
*/
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Dashboard Data Types
|
|
8
|
+
// ============================================================================
|
|
9
|
+
export declare interface DashboardStats {
|
|
10
|
+
pageViews: number
|
|
11
|
+
uniqueVisitors: number
|
|
12
|
+
sessions: number
|
|
13
|
+
bounceRate: number
|
|
14
|
+
avgSessionDuration: number
|
|
15
|
+
avgPagesPerSession: number
|
|
16
|
+
}
|
|
17
|
+
export declare interface StatsChange {
|
|
18
|
+
pageViews: number
|
|
19
|
+
uniqueVisitors: number
|
|
20
|
+
sessions: number
|
|
21
|
+
bounceRate: number
|
|
22
|
+
avgSessionDuration: number
|
|
23
|
+
}
|
|
24
|
+
export declare interface DashboardSummary extends DashboardStats {
|
|
25
|
+
change?: StatsChange
|
|
26
|
+
}
|
|
27
|
+
export declare interface TimeSeriesDataPoint {
|
|
28
|
+
date: string
|
|
29
|
+
pageViews: number
|
|
30
|
+
uniqueVisitors: number
|
|
31
|
+
sessions: number
|
|
32
|
+
}
|
|
33
|
+
export declare interface TopItem {
|
|
34
|
+
name: string
|
|
35
|
+
value: number
|
|
36
|
+
percentage: number
|
|
37
|
+
change?: number
|
|
38
|
+
}
|
|
39
|
+
export declare interface RealtimeData {
|
|
40
|
+
currentVisitors: number
|
|
41
|
+
pageViewsLastHour: number
|
|
42
|
+
topActivePages: TopItem[]
|
|
43
|
+
}
|
|
44
|
+
export declare interface DeviceBreakdown {
|
|
45
|
+
desktop: number
|
|
46
|
+
mobile: number
|
|
47
|
+
tablet: number
|
|
48
|
+
}
|
|
49
|
+
export declare interface BrowserStats {
|
|
50
|
+
name: string
|
|
51
|
+
visitors: number
|
|
52
|
+
percentage: number
|
|
53
|
+
}
|
|
54
|
+
export declare interface CountryStats {
|
|
55
|
+
country: string
|
|
56
|
+
countryCode: string
|
|
57
|
+
visitors: number
|
|
58
|
+
percentage: number
|
|
59
|
+
}
|
|
60
|
+
export declare interface GoalConversion {
|
|
61
|
+
goalId: string
|
|
62
|
+
goalName: string
|
|
63
|
+
conversions: number
|
|
64
|
+
conversionRate: number
|
|
65
|
+
revenue: number
|
|
66
|
+
}
|
|
67
|
+
// ============================================================================
|
|
68
|
+
// Component Props Types
|
|
69
|
+
// ============================================================================
|
|
70
|
+
export declare interface StatCardProps {
|
|
71
|
+
title: string
|
|
72
|
+
value: number | string
|
|
73
|
+
change?: number
|
|
74
|
+
changeLabel?: string
|
|
75
|
+
icon?: string
|
|
76
|
+
format?: 'number' | 'percentage' | 'duration' | 'currency'
|
|
77
|
+
loading?: boolean
|
|
78
|
+
}
|
|
79
|
+
export declare interface TopListProps {
|
|
80
|
+
title: string
|
|
81
|
+
items: TopItem[]
|
|
82
|
+
loading?: boolean
|
|
83
|
+
showPercentage?: boolean
|
|
84
|
+
maxItems?: number
|
|
85
|
+
emptyMessage?: string
|
|
86
|
+
}
|
|
87
|
+
export declare interface ChartProps {
|
|
88
|
+
data: TimeSeriesDataPoint[]
|
|
89
|
+
loading?: boolean
|
|
90
|
+
height?: number
|
|
91
|
+
showLegend?: boolean
|
|
92
|
+
metrics?: Array<'pageViews' | 'uniqueVisitors' | 'sessions'>
|
|
93
|
+
}
|
|
94
|
+
export declare interface RealtimeCounterProps {
|
|
95
|
+
count: number
|
|
96
|
+
label?: string
|
|
97
|
+
pulseColor?: string
|
|
98
|
+
loading?: boolean
|
|
99
|
+
}
|
|
100
|
+
export declare interface DateRangeOption {
|
|
101
|
+
label: string
|
|
102
|
+
value: string
|
|
103
|
+
days: number
|
|
104
|
+
}
|
|
105
|
+
export declare interface DateRange {
|
|
106
|
+
start: Date
|
|
107
|
+
end: Date
|
|
108
|
+
preset?: string
|
|
109
|
+
}
|
|
110
|
+
// ============================================================================
|
|
111
|
+
// API Types
|
|
112
|
+
// ============================================================================
|
|
113
|
+
export declare interface AnalyticsApiConfig {
|
|
114
|
+
baseUrl: string
|
|
115
|
+
siteId: string
|
|
116
|
+
headers?: Record<string, string>
|
|
117
|
+
}
|
|
118
|
+
export declare interface FetchOptions {
|
|
119
|
+
startDate?: Date
|
|
120
|
+
endDate?: Date
|
|
121
|
+
period?: 'hour' | 'day' | 'month'
|
|
122
|
+
limit?: number
|
|
123
|
+
}
|
|
124
|
+
// ============================================================================
|
|
125
|
+
// Theme Types
|
|
126
|
+
// ============================================================================
|
|
127
|
+
export declare interface DashboardTheme {
|
|
128
|
+
primary: string
|
|
129
|
+
secondary: string
|
|
130
|
+
success: string
|
|
131
|
+
warning: string
|
|
132
|
+
danger: string
|
|
133
|
+
background: string
|
|
134
|
+
surface: string
|
|
135
|
+
text: string
|
|
136
|
+
textSecondary: string
|
|
137
|
+
border: string
|
|
138
|
+
chart: {
|
|
139
|
+
pageViews: string
|
|
140
|
+
visitors: string
|
|
141
|
+
sessions: string
|
|
142
|
+
grid: string
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format a number with locale-aware separators
|
|
3
|
+
*/
|
|
4
|
+
export declare function formatNumber(value: number, decimals?: number): string;
|
|
5
|
+
/**
|
|
6
|
+
* Format a number as compact (1.2K, 3.4M, etc.)
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatCompact(value: number): string;
|
|
9
|
+
/**
|
|
10
|
+
* Format a percentage
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatPercentage(value: number, decimals?: number): string;
|
|
13
|
+
/**
|
|
14
|
+
* Format duration in milliseconds to human-readable string
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatDuration(ms: number): string;
|
|
17
|
+
/**
|
|
18
|
+
* Format currency
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatCurrency(value: number, currency?: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Format a change percentage with + or - sign
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatChange(value: number): string;
|
|
25
|
+
/**
|
|
26
|
+
* Format date for display
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatDate(date: Date | string, format?: 'short' | 'long' | 'time'): string;
|
|
29
|
+
/**
|
|
30
|
+
* Format date range for display
|
|
31
|
+
*/
|
|
32
|
+
export declare function formatDateRange(start: Date, end: Date): string;
|
|
33
|
+
/**
|
|
34
|
+
* Get relative time string (e.g., "2 hours ago")
|
|
35
|
+
*/
|
|
36
|
+
export declare function getRelativeTime(date: Date | string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Get date range from preset value
|
|
39
|
+
*/
|
|
40
|
+
export declare function getDateRangeFromPreset(preset: string): { start: Date, end: Date } | null;
|
|
41
|
+
/**
|
|
42
|
+
* Generate chart gradient
|
|
43
|
+
*/
|
|
44
|
+
export declare function createChartGradient(ctx: CanvasRenderingContext2D, color: string, height: number): CanvasGradient;
|
|
45
|
+
/**
|
|
46
|
+
* Calculate nice axis ticks
|
|
47
|
+
*/
|
|
48
|
+
export declare function calculateAxisTicks(min: number, max: number, count?: number): number[];
|
|
49
|
+
/**
|
|
50
|
+
* Calculate percentage change between two values
|
|
51
|
+
*/
|
|
52
|
+
export declare function calculateChange(current: number, previous: number): number;
|
|
53
|
+
/**
|
|
54
|
+
* Aggregate time series data by period
|
|
55
|
+
*/
|
|
56
|
+
export declare function aggregateTimeSeries<T extends { date: string }>(data: T[], period: 'hour' | 'day' | 'week' | 'month', aggregator: (items: T[]) => Omit<T, 'date'>): T[];
|
|
57
|
+
/**
|
|
58
|
+
* Fill missing dates in time series
|
|
59
|
+
*/
|
|
60
|
+
export declare function fillMissingDates<T extends { date: string }>(data: T[], startDate: Date, endDate: Date, defaultValue: Omit<T, 'date'>): T[];
|
|
61
|
+
/**
|
|
62
|
+
* Convert hex to RGB
|
|
63
|
+
*/
|
|
64
|
+
export declare function hexToRgb(hex: string): { r: number, g: number, b: number } | null;
|
|
65
|
+
/**
|
|
66
|
+
* Add alpha to hex color
|
|
67
|
+
*/
|
|
68
|
+
export declare function hexWithAlpha(hex: string, alpha: number): string;
|
|
69
|
+
/**
|
|
70
|
+
* Generate color palette for charts
|
|
71
|
+
*/
|
|
72
|
+
export declare function generateColorPalette(baseColor: string, count: number): string[];
|
|
73
|
+
export declare const dateRangePresets: DateRangePreset[];
|
|
74
|
+
// ============================================================================
|
|
75
|
+
// Date Range Helpers
|
|
76
|
+
// ============================================================================
|
|
77
|
+
export declare interface DateRangePreset {
|
|
78
|
+
label: string
|
|
79
|
+
value: string
|
|
80
|
+
getRange: () => { start: Date, end: Date }
|
|
81
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { AggregationPeriod, AnalyticsEntityType } from './types';
|
|
2
|
+
import type { AnalyticsConfig } from './config';
|
|
3
|
+
/**
|
|
4
|
+
* Build a partition key for an analytics entity
|
|
5
|
+
*/
|
|
6
|
+
export declare function buildPK(entityType: AnalyticsEntityType, id: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Build a sort key for an analytics entity
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildSK(entityType: AnalyticsEntityType, ...parts: string[]): string;
|
|
11
|
+
/**
|
|
12
|
+
* Build a composite key with timestamp
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildTimestampKey(prefix: string, timestamp: Date, id?: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Build GSI1 partition key
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildGSI1PK(siteId: string, dimension: string, value: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Build period-based sort key for aggregates
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildPeriodSK(prefix: string, period: AggregationPeriod, periodStart: string, ...additionalParts: string[]): string;
|
|
23
|
+
/**
|
|
24
|
+
* Convert a JavaScript value to DynamoDB AttributeValue
|
|
25
|
+
*/
|
|
26
|
+
export declare function toDynamoValue(value: unknown): Record<string, unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* Convert DynamoDB AttributeValue to JavaScript value
|
|
29
|
+
*/
|
|
30
|
+
export declare function fromDynamoValue(attr: Record<string, unknown>): unknown;
|
|
31
|
+
/**
|
|
32
|
+
* Marshal a JavaScript object to DynamoDB Item
|
|
33
|
+
*/
|
|
34
|
+
export declare function marshal(obj: Record<string, unknown>): Record<string, Record<string, unknown>>;
|
|
35
|
+
/**
|
|
36
|
+
* Unmarshal a DynamoDB Item to JavaScript object
|
|
37
|
+
*/
|
|
38
|
+
export declare function unmarshal(item: Record<string, Record<string, unknown>>): Record<string, unknown>;
|
|
39
|
+
/**
|
|
40
|
+
* Build a query for items by site and sort key prefix
|
|
41
|
+
*/
|
|
42
|
+
export declare function buildSiteQuery(siteId: string, skPrefix: string, config?: AnalyticsConfig): {
|
|
43
|
+
TableName: string
|
|
44
|
+
KeyConditionExpression: string
|
|
45
|
+
ExpressionAttributeValues: Record<string, Record<string, string>>
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Build a query for items in a time range
|
|
49
|
+
*/
|
|
50
|
+
export declare function buildTimeRangeQuery(siteId: string, skPrefix: string, startTime: Date, endTime: Date, config?: AnalyticsConfig): {
|
|
51
|
+
TableName: string
|
|
52
|
+
KeyConditionExpression: string
|
|
53
|
+
ExpressionAttributeValues: Record<string, Record<string, string>>
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Generate a unique ID (ULID-like)
|
|
57
|
+
*/
|
|
58
|
+
export declare function generateId(): string;
|
|
59
|
+
/**
|
|
60
|
+
* Generate a session ID
|
|
61
|
+
*/
|
|
62
|
+
export declare function generateSessionId(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Hash a visitor ID for privacy
|
|
65
|
+
*/
|
|
66
|
+
export declare function hashVisitorId(ip: string, userAgent: string, siteId: string, salt: string): Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Get the start of a period
|
|
69
|
+
*/
|
|
70
|
+
export declare function getPeriodStart(date: Date, period: AggregationPeriod): string;
|
|
71
|
+
/**
|
|
72
|
+
* Get the appropriate period for a date range
|
|
73
|
+
*/
|
|
74
|
+
export declare function determinePeriod(startDate: Date, endDate: Date): AggregationPeriod;
|
|
75
|
+
/**
|
|
76
|
+
* Analytics key patterns for single-table design
|
|
77
|
+
*/
|
|
78
|
+
export declare const KeyPatterns: ({
|
|
79
|
+
site: {
|
|
80
|
+
pk: (siteId: string)) => string;
|
|
81
|
+
/**
|
|
82
|
+
* Get daily salt for visitor ID hashing (rotates daily for privacy).
|
|
83
|
+
* Secret-seeded so visitor hashes cannot be reproduced without the server
|
|
84
|
+
* secret (#88) — see src/lib/salt.ts.
|
|
85
|
+
*/
|
|
86
|
+
export { getDailySalt, getSharedDailySalt } from './lib/salt';
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { CustomEvent, PageView, Session } from './types';
|
|
2
|
+
/*' })
|
|
3
|
+
* .step('add_to_cart', 'Add to Cart', { eventName: 'add_to_cart' })
|
|
4
|
+
* .step('checkout', 'Checkout', { path: '/checkout' })
|
|
5
|
+
* .step('purchase', 'Purchase', { eventName: 'purchase' })
|
|
6
|
+
* .window(30 * 60 * 1000) // 30 minutes
|
|
7
|
+
* .build()
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare function createFunnel(id: string): FunnelBuilder;
|
|
11
|
+
/**
|
|
12
|
+
* Calculate drop-off rate between two steps
|
|
13
|
+
*/
|
|
14
|
+
export declare function calculateDropOffRate(stepACount: number, stepBCount: number): number;
|
|
15
|
+
/**
|
|
16
|
+
* Format funnel analysis as a simple report
|
|
17
|
+
*/
|
|
18
|
+
export declare function formatFunnelReport(analysis: FunnelAnalysis): string;
|
|
19
|
+
/**
|
|
20
|
+
* Identify common drop-off points
|
|
21
|
+
*/
|
|
22
|
+
// eslint-disable-next-line pickier/no-unused-vars
|
|
23
|
+
export declare function identifyDropOffPoints(analysis: FunnelAnalysis): Array<{
|
|
24
|
+
step: FunnelStep
|
|
25
|
+
dropOffRate: number
|
|
26
|
+
impact: number // How much this affects overall conversion
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Common e-commerce checkout funnel
|
|
30
|
+
*/
|
|
31
|
+
export declare const ecommerceCheckoutFunnel: Funnel;
|
|
32
|
+
/**
|
|
33
|
+
* SaaS signup funnel
|
|
34
|
+
*/
|
|
35
|
+
export declare const saasSignupFunnel: Funnel;
|
|
36
|
+
/**
|
|
37
|
+
* Content engagement funnel
|
|
38
|
+
*/
|
|
39
|
+
export declare const contentEngagementFunnel: Funnel;
|
|
40
|
+
// ============================================================================
|
|
41
|
+
// Types
|
|
42
|
+
// ============================================================================
|
|
43
|
+
export declare interface FunnelStep {
|
|
44
|
+
id: string
|
|
45
|
+
name: string
|
|
46
|
+
match: FunnelStepMatcher
|
|
47
|
+
}
|
|
48
|
+
export declare interface FunnelStepMatcher {
|
|
49
|
+
path?: string
|
|
50
|
+
eventName?: string
|
|
51
|
+
eventCategory?: string
|
|
52
|
+
custom?: (event: PageView | CustomEvent) => boolean
|
|
53
|
+
}
|
|
54
|
+
export declare interface Funnel {
|
|
55
|
+
id: string
|
|
56
|
+
name: string
|
|
57
|
+
steps: FunnelStep[]
|
|
58
|
+
windowMs?: number
|
|
59
|
+
}
|
|
60
|
+
export declare interface FunnelAnalysis {
|
|
61
|
+
funnel: Funnel
|
|
62
|
+
dateRange: {
|
|
63
|
+
start: Date
|
|
64
|
+
end: Date
|
|
65
|
+
}
|
|
66
|
+
totalEntries: number
|
|
67
|
+
completions: number
|
|
68
|
+
conversionRate: number
|
|
69
|
+
steps: FunnelStepAnalysis[]
|
|
70
|
+
avgCompletionTimeMs?: number
|
|
71
|
+
}
|
|
72
|
+
export declare interface FunnelStepAnalysis {
|
|
73
|
+
step: FunnelStep
|
|
74
|
+
reached: number
|
|
75
|
+
droppedOff: number
|
|
76
|
+
conversionFromPrevious: number
|
|
77
|
+
conversionFromStart: number
|
|
78
|
+
avgTimeOnStepMs?: number
|
|
79
|
+
}
|
|
80
|
+
export declare interface UserJourney {
|
|
81
|
+
visitorId: string
|
|
82
|
+
sessionId: string
|
|
83
|
+
stepsCompleted: number
|
|
84
|
+
totalSteps: number
|
|
85
|
+
completed: boolean
|
|
86
|
+
stepTimestamps: Date[]
|
|
87
|
+
completionTimeMs?: number
|
|
88
|
+
dropOffStep?: string
|
|
89
|
+
}
|
|
90
|
+
declare class FunnelBuilder {
|
|
91
|
+
constructor(id: string);
|
|
92
|
+
name(name: string): this;
|
|
93
|
+
step(id: string, name: string, match: FunnelStepMatcher): this;
|
|
94
|
+
window(windowMs: number): this;
|
|
95
|
+
build(): Funnel;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Analyze funnel performance from event data
|
|
99
|
+
*/
|
|
100
|
+
export declare class FunnelAnalyzer {
|
|
101
|
+
constructor(funnel: Funnel);
|
|
102
|
+
analyze(pageViews: PageView[], events: CustomEvent[], sessions: Session[]): FunnelAnalysis;
|
|
103
|
+
getJourneys(pageViews: PageView[], events: CustomEvent[]): UserJourney[];
|
|
104
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare headers provider - uses CF-* headers from Cloudflare
|
|
3
|
+
*/
|
|
4
|
+
export declare function createCloudflareProvider(): GeoProvider;
|
|
5
|
+
/**
|
|
6
|
+
* MaxMind GeoLite2 provider
|
|
7
|
+
* Requires maxmind package and GeoLite2-City.mmdb database
|
|
8
|
+
*/
|
|
9
|
+
export declare function createMaxMindProvider(databasePath?: string): GeoProvider;
|
|
10
|
+
/**
|
|
11
|
+
* IP-API.com free provider (limited to 45 req/min)
|
|
12
|
+
*/
|
|
13
|
+
export declare function createIpApiProvider(): GeoProvider;
|
|
14
|
+
/**
|
|
15
|
+
* Cloudflare request headers extractor
|
|
16
|
+
*/
|
|
17
|
+
export declare function extractCloudflareGeo(headers: Record<string, string>): IPGeoResult | null;
|
|
18
|
+
/**
|
|
19
|
+
* Vercel request headers extractor
|
|
20
|
+
*/
|
|
21
|
+
export declare function extractVercelGeo(headers: Record<string, string>): IPGeoResult | null;
|
|
22
|
+
/**
|
|
23
|
+
* Get or create default geolocation service
|
|
24
|
+
*/
|
|
25
|
+
export declare function getGeolocationService(config?: GeoServiceConfig): GeolocationService;
|
|
26
|
+
/**
|
|
27
|
+
* Lookup IP address using default service
|
|
28
|
+
*/
|
|
29
|
+
export declare function lookupIP(ip: string): Promise<IPGeoResult | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Lookup from request headers using default service
|
|
32
|
+
*/
|
|
33
|
+
export declare function lookupFromHeaders(headers: Record<string, string>): Promise<IPGeoResult | null>;
|
|
34
|
+
/**
|
|
35
|
+
* Format location for display
|
|
36
|
+
*/
|
|
37
|
+
export declare function formatGeoLocation(result: IPGeoResult): string;
|
|
38
|
+
/**
|
|
39
|
+
* Format short location (City, State/Region)
|
|
40
|
+
*/
|
|
41
|
+
export declare function formatGeoLocationShort(result: IPGeoResult): string;
|
|
42
|
+
/**
|
|
43
|
+
* IP geolocation result
|
|
44
|
+
*/
|
|
45
|
+
export declare interface IPGeoResult {
|
|
46
|
+
ip: string
|
|
47
|
+
countryCode: string
|
|
48
|
+
country: string
|
|
49
|
+
regionCode?: string
|
|
50
|
+
region?: string
|
|
51
|
+
city?: string
|
|
52
|
+
metro?: string
|
|
53
|
+
postalCode?: string
|
|
54
|
+
latitude?: number
|
|
55
|
+
longitude?: number
|
|
56
|
+
timezone?: string
|
|
57
|
+
accuracyRadius?: number
|
|
58
|
+
isp?: string
|
|
59
|
+
organization?: string
|
|
60
|
+
asn?: number
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Geolocation provider interface
|
|
64
|
+
*/
|
|
65
|
+
export declare interface GeoProvider {
|
|
66
|
+
name: string
|
|
67
|
+
lookup: (ip: string) => Promise<IPGeoResult | null>
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Geolocation service configuration
|
|
71
|
+
*/
|
|
72
|
+
export declare interface GeoServiceConfig {
|
|
73
|
+
provider?: GeoProvider
|
|
74
|
+
fallbackProviders?: GeoProvider[]
|
|
75
|
+
cacheTtlSeconds?: number
|
|
76
|
+
enableCache?: boolean
|
|
77
|
+
privacyMode?: boolean
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* IP Geolocation Module
|
|
81
|
+
*
|
|
82
|
+
* Provides IP-to-location resolution for analytics tracking.
|
|
83
|
+
* Uses ts-countries for geographic data enrichment.
|
|
84
|
+
*/
|
|
85
|
+
// ts-countries loaded dynamically
|
|
86
|
+
export type GeoLocation = any;
|
|
87
|
+
/**
|
|
88
|
+
* Main geolocation service
|
|
89
|
+
*/
|
|
90
|
+
export declare class GeolocationService {
|
|
91
|
+
constructor(config?: GeoServiceConfig);
|
|
92
|
+
lookup(ip: string): Promise<IPGeoResult | null>;
|
|
93
|
+
lookupFromHeaders(headers: Record<string, string>): Promise<IPGeoResult | null>;
|
|
94
|
+
clearCache(): void;
|
|
95
|
+
getCacheStats(): { size: number, hitRate: number };
|
|
96
|
+
}
|