@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.
Files changed (237) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +361 -0
  4. package/bin/cli.ts +169 -0
  5. package/dist/Analytics.d.ts +558 -0
  6. package/dist/api.d.ts +109 -0
  7. package/dist/batching.d.ts +93 -0
  8. package/dist/chunk-2mx7fq49.js +4 -0
  9. package/dist/chunk-3z29508k.js +204 -0
  10. package/dist/chunk-deephkz6.js +56 -0
  11. package/dist/chunk-j261vgyp.js +305 -0
  12. package/dist/chunk-xga17tz7.js +207 -0
  13. package/dist/config.d.ts +132 -0
  14. package/dist/dashboard/components/index.d.ts +80 -0
  15. package/dist/dashboard/composables/useAnalytics.d.ts +99 -0
  16. package/dist/dashboard/index.d.ts +110 -0
  17. package/dist/dashboard/types/index.d.ts +144 -0
  18. package/dist/dashboard/utils/index.d.ts +81 -0
  19. package/dist/dynamodb.d.ts +86 -0
  20. package/dist/funnels.d.ts +104 -0
  21. package/dist/geolocation.d.ts +96 -0
  22. package/dist/index.d.ts +371 -0
  23. package/dist/index.js +10211 -0
  24. package/dist/infrastructure/cdk.d.ts +60 -0
  25. package/dist/infrastructure/cloudformation.d.ts +44 -0
  26. package/dist/infrastructure/index.d.ts +45 -0
  27. package/dist/infrastructure/setup.d.ts +133 -0
  28. package/dist/integrations/cloudflare.d.ts +76 -0
  29. package/dist/integrations/hono.d.ts +60 -0
  30. package/dist/integrations/index.d.ts +24 -0
  31. package/dist/integrations/nuxt.d.ts +7 -0
  32. package/dist/integrations/nuxt.js +42 -0
  33. package/dist/integrations/runtime/use-ts-analytics.d.ts +18 -0
  34. package/dist/integrations/runtime/use-ts-analytics.js +17 -0
  35. package/dist/integrations/stx.d.ts +88 -0
  36. package/dist/integrations/stx.js +18 -0
  37. package/dist/lib/crypto-random.d.ts +4 -0
  38. package/dist/lib/salt.d.ts +16 -0
  39. package/dist/local.d.ts +56 -0
  40. package/dist/model-connector.d.ts +145 -0
  41. package/dist/models/AggregatedStats.d.ts +9 -0
  42. package/dist/models/CampaignStats.d.ts +9 -0
  43. package/dist/models/Conversion.d.ts +11 -0
  44. package/dist/models/CustomEvent.d.ts +11 -0
  45. package/dist/models/DeviceStats.d.ts +9 -0
  46. package/dist/models/EventStats.d.ts +9 -0
  47. package/dist/models/GeoStats.d.ts +9 -0
  48. package/dist/models/Goal.d.ts +9 -0
  49. package/dist/models/GoalStats.d.ts +9 -0
  50. package/dist/models/PageStats.d.ts +11 -0
  51. package/dist/models/PageView.d.ts +13 -0
  52. package/dist/models/RealtimeStats.d.ts +9 -0
  53. package/dist/models/ReferrerStats.d.ts +9 -0
  54. package/dist/models/Session.d.ts +11 -0
  55. package/dist/models/Site.d.ts +11 -0
  56. package/dist/models/index.d.ts +28 -0
  57. package/dist/models/types.d.ts +60 -0
  58. package/dist/sqs-buffering.d.ts +243 -0
  59. package/dist/stacks-integration.d.ts +159 -0
  60. package/dist/tracking-script.d.ts +71 -0
  61. package/dist/tracking.d.ts +17 -0
  62. package/dist/tracking.js +26 -0
  63. package/dist/types.d.ts +595 -0
  64. package/dist/utils/geolocation.d.ts +111 -0
  65. package/dist/utils/user-agent.d.ts +17 -0
  66. package/dist/version.d.ts +7 -0
  67. package/package.json +119 -0
  68. package/src/Analytics.ts +3349 -0
  69. package/src/api.ts +1286 -0
  70. package/src/assets/crosswind.css +2220 -0
  71. package/src/batching.ts +452 -0
  72. package/src/components/dashboard/index.ts +18 -0
  73. package/src/config.ts +456 -0
  74. package/src/dashboard/Dashboard.stx +1517 -0
  75. package/src/dashboard/components/AlertCard.stx +177 -0
  76. package/src/dashboard/components/AnalyticsDashboard.stx +354 -0
  77. package/src/dashboard/components/AnimatedNumber.stx +86 -0
  78. package/src/dashboard/components/BarChart.stx +220 -0
  79. package/src/dashboard/components/BrowserBreakdown.stx +98 -0
  80. package/src/dashboard/components/BrowsersTable.stx +125 -0
  81. package/src/dashboard/components/CampaignBreakdown.stx +163 -0
  82. package/src/dashboard/components/CampaignTable.stx +238 -0
  83. package/src/dashboard/components/CountryList.stx +101 -0
  84. package/src/dashboard/components/DataTable.stx +226 -0
  85. package/src/dashboard/components/DateRangePicker.stx +77 -0
  86. package/src/dashboard/components/DeviceBreakdown.stx +94 -0
  87. package/src/dashboard/components/DevicesTable.stx +163 -0
  88. package/src/dashboard/components/DonutChart.stories.ts +55 -0
  89. package/src/dashboard/components/DonutChart.stx +157 -0
  90. package/src/dashboard/components/EmptyState.stx +90 -0
  91. package/src/dashboard/components/EngagementMetrics.stx +183 -0
  92. package/src/dashboard/components/EventsSection.stx +192 -0
  93. package/src/dashboard/components/FilterBar.stx +104 -0
  94. package/src/dashboard/components/FullAnalyticsDashboard.stx +455 -0
  95. package/src/dashboard/components/FunnelChart.stx +142 -0
  96. package/src/dashboard/components/GeoTable.stx +337 -0
  97. package/src/dashboard/components/GoalsPanel.stx +109 -0
  98. package/src/dashboard/components/Header.stx +39 -0
  99. package/src/dashboard/components/HeatmapChart.stx +140 -0
  100. package/src/dashboard/components/LiveActivityFeed.stx +172 -0
  101. package/src/dashboard/components/MetricComparison.stx +106 -0
  102. package/src/dashboard/components/MiniStats.stx +96 -0
  103. package/src/dashboard/components/OSBreakdown.stx +124 -0
  104. package/src/dashboard/components/PageDetailCard.stx +102 -0
  105. package/src/dashboard/components/PagesTable.stx +127 -0
  106. package/src/dashboard/components/ProgressRing.stx +89 -0
  107. package/src/dashboard/components/RealtimeCounter.stories.ts +45 -0
  108. package/src/dashboard/components/RealtimeCounter.stx +46 -0
  109. package/src/dashboard/components/ReferrersTable.stx +180 -0
  110. package/src/dashboard/components/SparklineChart.stx +160 -0
  111. package/src/dashboard/components/StatCard.stories.ts +58 -0
  112. package/src/dashboard/components/StatCard.stx +90 -0
  113. package/src/dashboard/components/SummaryStats.stx +81 -0
  114. package/src/dashboard/components/TabNav.stx +66 -0
  115. package/src/dashboard/components/ThemeSwitcher.stx +124 -0
  116. package/src/dashboard/components/TimeSeriesChart.stx +106 -0
  117. package/src/dashboard/components/TopList.stories.ts +58 -0
  118. package/src/dashboard/components/TopList.stx +74 -0
  119. package/src/dashboard/components/TrendIndicator.stx +84 -0
  120. package/src/dashboard/components/heatmap/ClickHeatmap.stx +264 -0
  121. package/src/dashboard/components/heatmap/ElementClickList.stx +125 -0
  122. package/src/dashboard/components/heatmap/HeatmapControls.stx +125 -0
  123. package/src/dashboard/components/heatmap/HeatmapLegend.stx +69 -0
  124. package/src/dashboard/components/heatmap/PageHeatmap.stx +264 -0
  125. package/src/dashboard/components/heatmap/ScrollHeatmap.stx +127 -0
  126. package/src/dashboard/components/heatmap/index.ts +12 -0
  127. package/src/dashboard/components/index.ts +86 -0
  128. package/src/dashboard/composables/useAnalytics.ts +465 -0
  129. package/src/dashboard/demo/DemoApp.stx +370 -0
  130. package/src/dashboard/demo/index.ts +8 -0
  131. package/src/dashboard/demo/mockData.ts +234 -0
  132. package/src/dashboard/index.ts +117 -0
  133. package/src/dashboard/stx-shim.d.ts +4 -0
  134. package/src/dashboard/types/index.ts +203 -0
  135. package/src/dashboard/utils/index.ts +426 -0
  136. package/src/dynamodb.ts +344 -0
  137. package/src/funnels.ts +534 -0
  138. package/src/geolocation.ts +515 -0
  139. package/src/handlers/alerts.ts +328 -0
  140. package/src/handlers/annotations.ts +128 -0
  141. package/src/handlers/api-keys.ts +240 -0
  142. package/src/handlers/auth.ts +1020 -0
  143. package/src/handlers/authz.ts +137 -0
  144. package/src/handlers/collect.ts +724 -0
  145. package/src/handlers/data.ts +625 -0
  146. package/src/handlers/experiments.ts +138 -0
  147. package/src/handlers/funnels.ts +216 -0
  148. package/src/handlers/goals.ts +218 -0
  149. package/src/handlers/heatmaps.ts +272 -0
  150. package/src/handlers/index.ts +56 -0
  151. package/src/handlers/lib/read-cache.ts +63 -0
  152. package/src/handlers/misc.ts +486 -0
  153. package/src/handlers/oauth.ts +233 -0
  154. package/src/handlers/performance.ts +388 -0
  155. package/src/handlers/sessions.ts +413 -0
  156. package/src/handlers/sharing.ts +198 -0
  157. package/src/handlers/stats.ts +1368 -0
  158. package/src/handlers/team.ts +161 -0
  159. package/src/handlers/uptime.ts +283 -0
  160. package/src/handlers/views.ts +390 -0
  161. package/src/handlers/webhooks.ts +226 -0
  162. package/src/heatmap/index.ts +32 -0
  163. package/src/heatmap/tracking-script.ts +452 -0
  164. package/src/heatmap/types.ts +79 -0
  165. package/src/index.ts +387 -0
  166. package/src/infrastructure/cdk.ts +496 -0
  167. package/src/infrastructure/cloudformation.ts +595 -0
  168. package/src/infrastructure/index.ts +48 -0
  169. package/src/infrastructure/setup.ts +611 -0
  170. package/src/integrations/cloudflare.ts +732 -0
  171. package/src/integrations/hono.ts +589 -0
  172. package/src/integrations/index.ts +27 -0
  173. package/src/integrations/nuxt.ts +78 -0
  174. package/src/integrations/runtime/use-ts-analytics.ts +32 -0
  175. package/src/integrations/stx.ts +138 -0
  176. package/src/jobs/index.ts +127 -0
  177. package/src/lib/crypto-random.ts +41 -0
  178. package/src/lib/ddb-errors.ts +20 -0
  179. package/src/lib/dynamodb.ts +216 -0
  180. package/src/lib/email.ts +38 -0
  181. package/src/lib/ga-import.ts +471 -0
  182. package/src/lib/ga4-api.ts +244 -0
  183. package/src/lib/goals.ts +205 -0
  184. package/src/lib/index.ts +6 -0
  185. package/src/lib/ingest-counters.ts +123 -0
  186. package/src/lib/log.ts +36 -0
  187. package/src/lib/membership.ts +98 -0
  188. package/src/lib/plans.ts +90 -0
  189. package/src/lib/quota.ts +46 -0
  190. package/src/lib/rate-limit.ts +27 -0
  191. package/src/lib/rollups.ts +472 -0
  192. package/src/lib/salt.ts +97 -0
  193. package/src/lib/scheduler.ts +97 -0
  194. package/src/lib/significance.ts +66 -0
  195. package/src/lib/site-retention.ts +56 -0
  196. package/src/local.ts +360 -0
  197. package/src/model-connector.ts +616 -0
  198. package/src/models/AggregatedStats.ts +162 -0
  199. package/src/models/CampaignStats.ts +141 -0
  200. package/src/models/Conversion.ts +135 -0
  201. package/src/models/CustomEvent.ts +123 -0
  202. package/src/models/DeviceStats.ts +105 -0
  203. package/src/models/EventStats.ts +108 -0
  204. package/src/models/GeoStats.ts +112 -0
  205. package/src/models/Goal.ts +105 -0
  206. package/src/models/GoalStats.ts +106 -0
  207. package/src/models/PageStats.ts +152 -0
  208. package/src/models/PageView.ts +277 -0
  209. package/src/models/RealtimeStats.ts +96 -0
  210. package/src/models/ReferrerStats.ts +115 -0
  211. package/src/models/Session.ts +235 -0
  212. package/src/models/Site.ts +115 -0
  213. package/src/models/index.ts +50 -0
  214. package/src/models/orm/index.ts +2043 -0
  215. package/src/models/types.ts +71 -0
  216. package/src/router.ts +521 -0
  217. package/src/sqs-buffering.ts +806 -0
  218. package/src/stacks-integration.ts +527 -0
  219. package/src/tracking-script.ts +944 -0
  220. package/src/tracking.ts +27 -0
  221. package/src/types/analytics.ts +219 -0
  222. package/src/types/api.ts +75 -0
  223. package/src/types/bun-router.d.ts +15 -0
  224. package/src/types/dashboard.ts +62 -0
  225. package/src/types/index.ts +66 -0
  226. package/src/types/stx.d.ts +27 -0
  227. package/src/types/window.d.ts +101 -0
  228. package/src/types.ts +911 -0
  229. package/src/utils/cache.ts +148 -0
  230. package/src/utils/date.ts +118 -0
  231. package/src/utils/filters.ts +71 -0
  232. package/src/utils/geolocation.ts +323 -0
  233. package/src/utils/index.ts +9 -0
  234. package/src/utils/response.ts +180 -0
  235. package/src/utils/timezone-country.ts +242 -0
  236. package/src/utils/user-agent.ts +110 -0
  237. package/src/version.ts +7 -0
@@ -0,0 +1,595 @@
1
+ /**
2
+ * GSI projection configuration
3
+ */
4
+ export declare interface IndexProjection {
5
+ type: ProjectionType
6
+ attributes?: string[]
7
+ }
8
+ /**
9
+ * Global Secondary Index definition
10
+ */
11
+ export declare interface GSIDefinition {
12
+ name: string
13
+ partitionKey: string
14
+ sortKey?: string
15
+ projection: IndexProjection
16
+ readCapacity?: number
17
+ writeCapacity?: number
18
+ }
19
+ /**
20
+ * Local Secondary Index definition
21
+ */
22
+ export declare interface LSIDefinition {
23
+ name: string
24
+ sortKey: string
25
+ projection: IndexProjection
26
+ }
27
+ /**
28
+ * Single-table design configuration (compatible with dynamodb-tooling)
29
+ */
30
+ export declare interface SingleTableDesignConfig {
31
+ enabled: boolean
32
+ partitionKeyName: string
33
+ sortKeyName: string
34
+ gsi1pkName: string
35
+ gsi1skName: string
36
+ gsi2pkName: string
37
+ gsi2skName: string
38
+ entityTypeAttribute: string
39
+ pkPrefix: string
40
+ skPrefix: string
41
+ gsiCount: number
42
+ keyDelimiter: string
43
+ }
44
+ /**
45
+ * Analytics DynamoDB table configuration
46
+ */
47
+ export declare interface AnalyticsTableConfig {
48
+ tableName: string
49
+ billingMode: BillingMode
50
+ singleTable: SingleTableDesignConfig
51
+ globalSecondaryIndexes: GSIDefinition[]
52
+ localSecondaryIndexes: LSIDefinition[]
53
+ ttlAttributeName?: string
54
+ }
55
+ /**
56
+ * Key pattern templates for analytics entities
57
+ *
58
+ * Single-table design following Alex DeBrie patterns:
59
+ * - PK: ENTITY#id (for direct lookups)
60
+ * - SK: ENTITY#id or composite for hierarchical data
61
+ * - GSI1: For access patterns like site-based queries
62
+ * - GSI2: For time-based queries
63
+ */
64
+ export declare interface AnalyticsKeyPatterns {
65
+ site: {
66
+ pk: `SITE#${string}`
67
+ sk: `SITE#${string}`
68
+ }
69
+ pageView: {
70
+ pk: `SITE#${string}`
71
+ sk: `PV#${string}#${string}`
72
+ gsi1pk: `SESSION#${string}`
73
+ gsi1sk: `PV#${string}`
74
+ }
75
+ session: {
76
+ pk: `SITE#${string}`
77
+ sk: `SESSION#${string}`
78
+ gsi1pk: `VISITOR#${string}`
79
+ gsi1sk: `SESSION#${string}`
80
+ }
81
+ event: {
82
+ pk: `SITE#${string}`
83
+ sk: `EVENT#${string}#${string}`
84
+ gsi1pk: `SESSION#${string}`
85
+ gsi1sk: `EVENT#${string}`
86
+ }
87
+ goal: {
88
+ pk: `SITE#${string}`
89
+ sk: `GOAL#${string}`
90
+ }
91
+ conversion: {
92
+ pk: `SITE#${string}`
93
+ sk: `CONV#${string}#${string}`
94
+ gsi1pk: `GOAL#${string}`
95
+ gsi1sk: `CONV#${string}`
96
+ }
97
+ aggregatedStats: {
98
+ pk: `SITE#${string}`
99
+ sk: `STATS#${string}#${string}`
100
+ }
101
+ pageStats: {
102
+ pk: `SITE#${string}`
103
+ sk: `PSTATS#${string}#${string}#${string}`
104
+ }
105
+ referrerStats: {
106
+ pk: `SITE#${string}`
107
+ sk: `RSTATS#${string}#${string}#${string}`
108
+ }
109
+ realtimeStats: {
110
+ pk: `SITE#${string}`
111
+ sk: `RT#${string}`
112
+ }
113
+ }
114
+ /**
115
+ * Site settings
116
+ */
117
+ export declare interface SiteSettings {
118
+ collectGeolocation: boolean
119
+ trackReferrers: boolean
120
+ trackUtmParams: boolean
121
+ trackDeviceType: boolean
122
+ publicDashboard: boolean
123
+ publicDashboardPassword?: string
124
+ excludedPaths: string[]
125
+ excludedIps: string[]
126
+ dataRetentionDays: number
127
+ }
128
+ /**
129
+ * Site/Website being tracked
130
+ */
131
+ export declare interface Site {
132
+ id: string
133
+ name: string
134
+ domains: string[]
135
+ timezone: string
136
+ isActive: boolean
137
+ ownerId: string
138
+ settings: SiteSettings
139
+ createdAt: Date
140
+ updatedAt: Date
141
+ }
142
+ /**
143
+ * Page view event (raw event - stored temporarily for aggregation)
144
+ */
145
+ export declare interface PageView {
146
+ id: string
147
+ siteId: string
148
+ visitorId: string
149
+ sessionId: string
150
+ path: string
151
+ hostname: string
152
+ title?: string
153
+ referrer?: string
154
+ referrerSource?: string
155
+ utmSource?: string
156
+ utmMedium?: string
157
+ utmCampaign?: string
158
+ utmContent?: string
159
+ utmTerm?: string
160
+ gclid?: string
161
+ fbclid?: string
162
+ country?: string
163
+ region?: string
164
+ city?: string
165
+ deviceType?: DeviceType
166
+ browser?: string
167
+ browserVersion?: string
168
+ os?: string
169
+ osVersion?: string
170
+ screenWidth?: number
171
+ screenHeight?: number
172
+ isUnique: boolean
173
+ isBounce: boolean
174
+ timeOnPage?: number
175
+ timestamp: Date
176
+ ttl?: number
177
+ }
178
+ /**
179
+ * Custom event (non-pageview events like button clicks, form submissions)
180
+ */
181
+ export declare interface CustomEvent {
182
+ id: string
183
+ siteId: string
184
+ visitorId: string
185
+ sessionId: string
186
+ name: string
187
+ category?: string
188
+ value?: number
189
+ properties?: Record<string, string | number | boolean>
190
+ path: string
191
+ timestamp: Date
192
+ ttl?: number
193
+ }
194
+ /**
195
+ * Session (visitor session)
196
+ */
197
+ export declare interface Session {
198
+ id: string
199
+ siteId: string
200
+ visitorId: string
201
+ entryPath: string
202
+ exitPath: string
203
+ referrer?: string
204
+ referrerSource?: string
205
+ utmSource?: string
206
+ utmMedium?: string
207
+ utmCampaign?: string
208
+ utmContent?: string
209
+ utmTerm?: string
210
+ gclid?: string
211
+ fbclid?: string
212
+ country?: string
213
+ region?: string
214
+ city?: string
215
+ deviceType?: DeviceType
216
+ browser?: string
217
+ os?: string
218
+ pageViewCount: number
219
+ eventCount: number
220
+ isBounce: boolean
221
+ duration: number
222
+ startedAt: Date
223
+ endedAt: Date
224
+ ttl?: number
225
+ }
226
+ /**
227
+ * Goal/Conversion definition
228
+ */
229
+ export declare interface Goal {
230
+ id: string
231
+ siteId: string
232
+ name: string
233
+ type: GoalType
234
+ pattern: string
235
+ matchType: 'exact' | 'contains' | 'regex'
236
+ value?: number
237
+ isActive: boolean
238
+ createdAt: Date
239
+ updatedAt: Date
240
+ }
241
+ /**
242
+ * Conversion record (goal completion)
243
+ */
244
+ export declare interface Conversion {
245
+ id: string
246
+ siteId: string
247
+ goalId: string
248
+ visitorId: string
249
+ sessionId: string
250
+ value?: number
251
+ path: string
252
+ referrerSource?: string
253
+ utmSource?: string
254
+ utmCampaign?: string
255
+ timestamp: Date
256
+ ttl?: number
257
+ }
258
+ /**
259
+ * Aggregated stats (pre-computed for fast dashboard queries)
260
+ */
261
+ export declare interface AggregatedStats {
262
+ siteId: string
263
+ period: AggregationPeriod
264
+ periodStart: string
265
+ pageViews: number
266
+ uniqueVisitors: number
267
+ sessions: number
268
+ bounces: number
269
+ bounceRate: number
270
+ avgSessionDuration: number
271
+ avgPagesPerSession: number
272
+ totalTimeOnSite: number
273
+ newVisitors: number
274
+ returningVisitors: number
275
+ createdAt: Date
276
+ updatedAt: Date
277
+ }
278
+ /**
279
+ * Page-level aggregated stats
280
+ */
281
+ export declare interface PageStats {
282
+ siteId: string
283
+ period: AggregationPeriod
284
+ periodStart: string
285
+ path: string
286
+ title?: string
287
+ pageViews: number
288
+ uniqueVisitors: number
289
+ entries: number
290
+ exits: number
291
+ bounces: number
292
+ avgTimeOnPage: number
293
+ exitRate: number
294
+ }
295
+ /**
296
+ * Referrer stats
297
+ */
298
+ export declare interface ReferrerStats {
299
+ siteId: string
300
+ period: AggregationPeriod
301
+ periodStart: string
302
+ source: string
303
+ referrer?: string
304
+ visitors: number
305
+ pageViews: number
306
+ bounceRate: number
307
+ avgSessionDuration: number
308
+ }
309
+ /**
310
+ * Geographic stats
311
+ */
312
+ export declare interface GeoStats {
313
+ siteId: string
314
+ period: AggregationPeriod
315
+ periodStart: string
316
+ country: string
317
+ region?: string
318
+ city?: string
319
+ visitors: number
320
+ pageViews: number
321
+ bounceRate: number
322
+ }
323
+ /**
324
+ * Device/Browser stats
325
+ */
326
+ export declare interface DeviceStats {
327
+ siteId: string
328
+ period: AggregationPeriod
329
+ periodStart: string
330
+ dimension: 'device' | 'browser' | 'os' | 'screen'
331
+ value: string
332
+ visitors: number
333
+ pageViews: number
334
+ bounceRate: number
335
+ }
336
+ /**
337
+ * UTM Campaign stats
338
+ */
339
+ export declare interface CampaignStats {
340
+ siteId: string
341
+ period: AggregationPeriod
342
+ periodStart: string
343
+ utmSource: string
344
+ utmMedium?: string
345
+ utmCampaign?: string
346
+ visitors: number
347
+ pageViews: number
348
+ conversions: number
349
+ conversionRate: number
350
+ revenue: number
351
+ bounceRate: number
352
+ }
353
+ /**
354
+ * Custom event stats
355
+ */
356
+ export declare interface EventStats {
357
+ siteId: string
358
+ period: AggregationPeriod
359
+ periodStart: string
360
+ eventName: string
361
+ count: number
362
+ uniqueVisitors: number
363
+ totalValue: number
364
+ avgValue: number
365
+ }
366
+ /**
367
+ * Goal stats (conversions)
368
+ */
369
+ export declare interface GoalStats {
370
+ siteId: string
371
+ goalId: string
372
+ period: AggregationPeriod
373
+ periodStart: string
374
+ conversions: number
375
+ uniqueConversions: number
376
+ conversionRate: number
377
+ revenue: number
378
+ }
379
+ /**
380
+ * Real-time stats (last 5 minutes, stored with short TTL)
381
+ */
382
+ export declare interface RealtimeStats {
383
+ siteId: string
384
+ minute: string
385
+ currentVisitors: number
386
+ pageViews: number
387
+ activePages: Record<string, number>
388
+ visitorIds?: string[]
389
+ ttl: number
390
+ }
391
+ /**
392
+ * Date range for queries
393
+ */
394
+ export declare interface DateRange {
395
+ start: Date
396
+ end: Date
397
+ }
398
+ /**
399
+ * Query options
400
+ */
401
+ export declare interface QueryOptions {
402
+ siteId: string
403
+ dateRange: DateRange
404
+ includeComparison?: boolean
405
+ groupBy?: 'hour' | 'day' | 'month'
406
+ }
407
+ /**
408
+ * Dashboard summary data
409
+ */
410
+ export declare interface DashboardSummary {
411
+ pageViews: number
412
+ uniqueVisitors: number
413
+ sessions: number
414
+ bounceRate: number
415
+ avgSessionDuration: number
416
+ avgPagesPerSession: number
417
+ change?: {
418
+ pageViews: number
419
+ uniqueVisitors: number
420
+ sessions: number
421
+ bounceRate: number
422
+ avgSessionDuration: number
423
+ }
424
+ }
425
+ /**
426
+ * Time series data point
427
+ */
428
+ export declare interface TimeSeriesPoint {
429
+ date: string
430
+ pageViews: number
431
+ uniqueVisitors: number
432
+ sessions: number
433
+ }
434
+ /**
435
+ * Top item (page, referrer, etc.)
436
+ */
437
+ export declare interface TopItem {
438
+ name: string
439
+ value: number
440
+ percentage: number
441
+ metadata?: Record<string, string | undefined>
442
+ }
443
+ /**
444
+ * Realtime data
445
+ */
446
+ export declare interface RealtimeData {
447
+ currentVisitors: number
448
+ pageViewsLastHour: number
449
+ topActivePages: TopItem[]
450
+ }
451
+ /**
452
+ * Dashboard data
453
+ */
454
+ export declare interface DashboardData {
455
+ summary: DashboardSummary
456
+ timeSeries: TimeSeriesPoint[]
457
+ topPages: TopItem[]
458
+ topReferrers: TopItem[]
459
+ deviceBreakdown: TopItem[]
460
+ realtime?: RealtimeData
461
+ }
462
+ /**
463
+ * Goal match result
464
+ */
465
+ export declare interface GoalMatchResult {
466
+ goalId: string
467
+ goalName: string
468
+ value?: number
469
+ matchedAt: Date
470
+ matchedPath: string
471
+ matchedEvent?: string
472
+ }
473
+ /**
474
+ * Goal performance metrics
475
+ */
476
+ export declare interface GoalPerformance {
477
+ goalId: string
478
+ goalName: string
479
+ conversions: number
480
+ conversionRate: number
481
+ revenue: number
482
+ topConvertingPages: TopItem[]
483
+ topConvertingSources: TopItem[]
484
+ }
485
+ /**
486
+ * Aggregation job status
487
+ */
488
+ export declare interface AggregationJobStatus {
489
+ jobId: string
490
+ siteId: string
491
+ period: AggregationPeriod
492
+ status: 'pending' | 'running' | 'completed' | 'failed'
493
+ startedAt?: Date
494
+ completedAt?: Date
495
+ error?: string
496
+ stats?: {
497
+ pageViewsProcessed: number
498
+ sessionsProcessed: number
499
+ eventsProcessed: number
500
+ }
501
+ }
502
+ /**
503
+ * Pipeline job configuration
504
+ */
505
+ export declare interface PipelineJobConfig {
506
+ siteId: string
507
+ period: AggregationPeriod
508
+ windowStart: Date
509
+ windowEnd: Date
510
+ processPageViews: boolean
511
+ processSessions: boolean
512
+ processEvents: boolean
513
+ processGoals: boolean
514
+ }
515
+ /**
516
+ * Pipeline job result
517
+ */
518
+ export declare interface PipelineJobResult {
519
+ success: boolean
520
+ aggregatedStats?: AggregatedStats
521
+ pageStats?: PageStats[]
522
+ referrerStats?: ReferrerStats[]
523
+ geoStats?: GeoStats[]
524
+ deviceStats?: DeviceStats[]
525
+ campaignStats?: CampaignStats[]
526
+ eventStats?: EventStats[]
527
+ goalStats?: GoalStats[]
528
+ errors?: string[]
529
+ }
530
+ /**
531
+ * Tracking script options
532
+ */
533
+ export declare interface TrackingScriptOptions {
534
+ siteId: string
535
+ apiEndpoint?: string
536
+ honorDnt?: boolean
537
+ trackHashChanges?: boolean
538
+ trackOutboundLinks?: boolean
539
+ stealthMode?: boolean
540
+ }
541
+ /**
542
+ * Analytics store options
543
+ */
544
+ export declare interface AnalyticsStoreOptions {
545
+ tableName: string
546
+ useTtl?: boolean
547
+ rawEventTtl?: number
548
+ hourlyAggregateTtl?: number
549
+ dailyAggregateTtl?: number
550
+ }
551
+ /**
552
+ * Aggregator options
553
+ */
554
+ export declare interface AggregatorOptions {
555
+ store: unknown
556
+ batchSize?: number
557
+ }
558
+ /**
559
+ * DynamoDB billing mode
560
+ */
561
+ export type BillingMode = 'PAY_PER_REQUEST' | 'PROVISIONED';
562
+ /**
563
+ * Projection type for indexes
564
+ */
565
+ export type ProjectionType = 'ALL' | 'KEYS_ONLY' | 'INCLUDE';
566
+ /**
567
+ * Analytics entity types for single-table design
568
+ */
569
+ export type AnalyticsEntityType = | 'SITE'
570
+ | 'PAGEVIEW'
571
+ | 'SESSION'
572
+ | 'EVENT'
573
+ | 'GOAL'
574
+ | 'CONVERSION'
575
+ | 'STATS_AGG'
576
+ | 'STATS_PAGE'
577
+ | 'STATS_REF'
578
+ | 'STATS_GEO'
579
+ | 'STATS_DEVICE'
580
+ | 'STATS_CAMPAIGN'
581
+ | 'STATS_EVENT'
582
+ | 'STATS_GOAL'
583
+ | 'REALTIME';
584
+ /**
585
+ * Device type
586
+ */
587
+ export type DeviceType = 'desktop' | 'mobile' | 'tablet' | 'unknown';
588
+ /**
589
+ * Goal type
590
+ */
591
+ export type GoalType = 'pageview' | 'event';
592
+ /**
593
+ * Time period for aggregations
594
+ */
595
+ export type AggregationPeriod = 'hour' | 'day' | 'month';
@@ -0,0 +1,111 @@
1
+ /** ISO-3166 alpha-2 code for a stored country value (name or code). */
2
+ export declare function countryCodeOf(nameOrCode: string): string | undefined;
3
+ /** Emoji flag (regional indicator pair) for an ISO alpha-2 code — Fathom-style. */
4
+ export declare function countryFlagEmoji(code: string): string;
5
+ /**
6
+ * Get country from CloudFront/Cloudflare headers
7
+ */
8
+ export declare function getCountryFromHeaders(headers: Record<string, string> | undefined): string | undefined;
9
+ /**
10
+ * Get country from IP address using geolocation services
11
+ */
12
+ /**
13
+ * Reduce an IP's precision before it leaves the system (e.g. to a third-party
14
+ * geo API), per config.privacy.ipAnonymization (#144). 'partial' drops the host
15
+ * portion (IPv4 /24, IPv6 /48) — still country-accurate; 'full' drops it
16
+ * entirely; 'none' passes through.
17
+ */
18
+ export declare function anonymizeIp(ip: string, mode?: string): string;
19
+ export declare function getCountryFromIP(ip: string): Promise<string | undefined>;
20
+ /**
21
+ * Parse a referrer URL into a normalized, human-readable source name
22
+ * (e.g. "Google", "Reddit", "ChatGPT"). Unknown hosts fall back to the
23
+ * bare domain (www. stripped). Empty → "Direct", invalid → "Unknown".
24
+ */
25
+ export declare function parseReferrerSource(referrer?: string): string;
26
+ /**
27
+ * Classify traffic into a marketing channel. Paid/email are inferred from
28
+ * UTM medium and ad click IDs (gclid/fbclid); otherwise from the referrer.
29
+ */
30
+ export declare function getReferrerChannel(opts: {
31
+ referrer?: string
32
+ utmMedium?: string
33
+ gclid?: string
34
+ fbclid?: string
35
+ }): ReferrerChannel;
36
+ /**
37
+ * Channel for an already-normalized source name (e.g. a stored referrerSource).
38
+ * Used at query time where the original referrer/UTM is no longer available, so
39
+ * it can only classify Search/Social/AI/Referral/Direct (not Paid/Email).
40
+ */
41
+ export declare function getReferrerSourceChannel(source?: string): ReferrerChannel;
42
+ /**
43
+ * Whether a referrer is a known referral-spam domain (so its hits can be dropped).
44
+ */
45
+ export declare function isSpamReferrer(referrer?: string): boolean;
46
+ /**
47
+ * Get region from headers (CloudFront/Cloudflare)
48
+ */
49
+ export declare function getRegionFromHeaders(headers: Record<string, string> | undefined): string | undefined;
50
+ /**
51
+ * Get city from headers (CloudFront/Cloudflare)
52
+ */
53
+ export declare function getCityFromHeaders(headers: Record<string, string> | undefined): string | undefined;
54
+ /**
55
+ * Geolocation utilities
56
+ */
57
+ // Country code to name mapping
58
+ export declare const COUNTRY_NAMES: {
59
+ US: 'United States';
60
+ GB: 'United Kingdom';
61
+ CA: 'Canada';
62
+ AU: 'Australia';
63
+ DE: 'Germany';
64
+ FR: 'France';
65
+ JP: 'Japan';
66
+ CN: 'China';
67
+ IN: 'India';
68
+ BR: 'Brazil';
69
+ MX: 'Mexico';
70
+ ES: 'Spain';
71
+ IT: 'Italy';
72
+ NL: 'Netherlands';
73
+ SE: 'Sweden';
74
+ NO: 'Norway';
75
+ DK: 'Denmark';
76
+ FI: 'Finland';
77
+ CH: 'Switzerland';
78
+ AT: 'Austria';
79
+ BE: 'Belgium';
80
+ PL: 'Poland';
81
+ RU: 'Russia';
82
+ KR: 'South Korea';
83
+ SG: 'Singapore';
84
+ HK: 'Hong Kong';
85
+ TW: 'Taiwan';
86
+ NZ: 'New Zealand';
87
+ IE: 'Ireland';
88
+ PT: 'Portugal';
89
+ CZ: 'Czech Republic';
90
+ GR: 'Greece';
91
+ IL: 'Israel';
92
+ ZA: 'South Africa';
93
+ AR: 'Argentina';
94
+ CL: 'Chile';
95
+ CO: 'Colombia';
96
+ PH: 'Philippines';
97
+ TH: 'Thailand';
98
+ MY: 'Malaysia';
99
+ ID: 'Indonesia';
100
+ VN: 'Vietnam';
101
+ AE: 'UAE';
102
+ SA: 'Saudi Arabia';
103
+ TR: 'Turkey';
104
+ UA: 'Ukraine';
105
+ RO: 'Romania';
106
+ HU: 'Hungary'
107
+ };
108
+ /**
109
+ * Marketing channel a referrer belongs to.
110
+ */
111
+ export type ReferrerChannel = 'Search' | 'Social' | 'AI' | 'Email' | 'Referral' | 'Paid' | 'Direct';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Parse user agent string to extract device, browser, and OS info
3
+ */
4
+ export declare function parseUserAgent(ua: string): ParsedUserAgent;
5
+ export declare function isBot(ua: string): boolean;
6
+ /**
7
+ * Get browser family (simplifies browser name to family)
8
+ */
9
+ export declare function getBrowserFamily(browser: string): string;
10
+ /**
11
+ * User agent parsing utilities
12
+ */
13
+ export declare interface ParsedUserAgent {
14
+ deviceType: 'desktop' | 'mobile' | 'tablet'
15
+ browser: string
16
+ os: string
17
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Tracker/library version (#179) — embedded in the generated script, sent on
3
+ * every beacon (`v`), and aggregated into the hourly ingest counters, so
4
+ * support can tell exactly which tracker build a site is running instead of
5
+ * guessing at cache states. Kept in sync with package.json by a test.
6
+ */
7
+ export declare const TRACKER_VERSION: string;