@happyvertical/analytics 0.74.8

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.
@@ -0,0 +1,1235 @@
1
+ /**
2
+ * Core types and interfaces for the Analytics library
3
+ */
4
+ /**
5
+ * Base configuration options for all analytics providers
6
+ */
7
+ export interface BaseAnalyticsOptions {
8
+ /** Request timeout in milliseconds */
9
+ timeout?: number;
10
+ /** Maximum retry attempts for failed requests */
11
+ maxRetries?: number;
12
+ /** Cache TTL in milliseconds for metadata operations */
13
+ cacheTTL?: number;
14
+ }
15
+ /**
16
+ * Service account credentials for Google APIs
17
+ */
18
+ export interface ServiceAccountCredentials {
19
+ type: 'service_account';
20
+ project_id: string;
21
+ private_key_id: string;
22
+ private_key: string;
23
+ client_email: string;
24
+ client_id: string;
25
+ auth_uri: string;
26
+ token_uri: string;
27
+ auth_provider_x509_cert_url: string;
28
+ client_x509_cert_url: string;
29
+ }
30
+ /**
31
+ * Google Analytics 4 provider options
32
+ */
33
+ export interface GA4Options extends BaseAnalyticsOptions {
34
+ type: 'ga4';
35
+ /**
36
+ * Service account credentials for Admin API and Data API
37
+ * Can be path to JSON key file or parsed JSON object
38
+ */
39
+ serviceAccountKey?: string | ServiceAccountCredentials;
40
+ /**
41
+ * Measurement ID (G-XXXXXXX) for Measurement Protocol
42
+ * Required for server-side event tracking
43
+ */
44
+ measurementId?: string;
45
+ /**
46
+ * API Secret for Measurement Protocol
47
+ * Required for server-side event tracking
48
+ */
49
+ apiSecret?: string;
50
+ /**
51
+ * Default property ID for operations that don't specify one
52
+ */
53
+ defaultPropertyId?: string;
54
+ }
55
+ /**
56
+ * Plausible Analytics provider options
57
+ */
58
+ export interface PlausibleOptions extends BaseAnalyticsOptions {
59
+ type: 'plausible';
60
+ /**
61
+ * Plausible API key
62
+ */
63
+ apiKey: string;
64
+ /**
65
+ * Base URL for self-hosted instances
66
+ * @default "https://plausible.io"
67
+ */
68
+ baseUrl?: string;
69
+ /**
70
+ * Default site ID (domain) for operations
71
+ */
72
+ defaultSiteId?: string;
73
+ }
74
+ /**
75
+ * Matomo Analytics provider options
76
+ *
77
+ * Matomo's Reporting API authenticates via per-user `token_auth` values; admin
78
+ * provisioning operations require a token belonging to a super-user.
79
+ */
80
+ export interface MatomoOptions extends BaseAnalyticsOptions {
81
+ type: 'matomo';
82
+ /**
83
+ * Matomo base URL (e.g. `https://matomo.example.com`).
84
+ *
85
+ * Trailing slashes and explicit `/index.php` suffixes are normalized.
86
+ */
87
+ baseUrl: string;
88
+ /**
89
+ * `token_auth` for the calling user. Required for all reporting calls.
90
+ *
91
+ * For admin provisioning (createSite/createUser/etc.) this token must
92
+ * belong to a Matomo super-user.
93
+ */
94
+ tokenAuth: string;
95
+ /**
96
+ * Default site ID (`idSite`) for operations that don't specify one.
97
+ */
98
+ defaultSiteId?: string;
99
+ }
100
+ /**
101
+ * Union type for all provider options
102
+ */
103
+ export type GetAnalyticsOptions = GA4Options | PlausibleOptions | MatomoOptions;
104
+ /**
105
+ * Analytics property/site representation
106
+ */
107
+ export interface Property {
108
+ /** Unique identifier */
109
+ id: string;
110
+ /** Internal name (GA4: properties/123456789) */
111
+ name: string;
112
+ /** Human-readable display name */
113
+ displayName: string;
114
+ /** Creation timestamp (ISO 8601) */
115
+ createTime: string;
116
+ /** Last update timestamp (ISO 8601) */
117
+ updateTime?: string;
118
+ /** Property timezone */
119
+ timeZone?: string;
120
+ /** Currency code (e.g., 'USD', 'EUR') */
121
+ currencyCode?: string;
122
+ /** Industry category */
123
+ industryCategory?: string;
124
+ /** Service level */
125
+ serviceLevel?: 'STANDARD' | 'PREMIUM';
126
+ }
127
+ /**
128
+ * Options for listing properties
129
+ */
130
+ export interface ListPropertiesOptions {
131
+ /**
132
+ * Controls whether the provider should hydrate discovered properties with
133
+ * full metadata.
134
+ *
135
+ * Providers that support hydration should default this to `true` to
136
+ * preserve the existing `listProperties()` behavior. Set this to `false`
137
+ * to use discovery-only metadata, which may omit fields like `createTime`,
138
+ * `updateTime`, `timeZone`, and `currencyCode`.
139
+ */
140
+ hydrate?: boolean;
141
+ }
142
+ /**
143
+ * Options for creating a new property
144
+ */
145
+ export interface CreatePropertyOptions {
146
+ /** Human-readable display name */
147
+ displayName: string;
148
+ /** Timezone (e.g., 'America/Los_Angeles') */
149
+ timeZone?: string;
150
+ /** Currency code (e.g., 'USD') */
151
+ currencyCode?: string;
152
+ /** Industry category */
153
+ industryCategory?: string;
154
+ /** Parent account (GA4: accounts/{account_id}) */
155
+ parent?: string;
156
+ }
157
+ /**
158
+ * Options for updating a property
159
+ */
160
+ export interface UpdatePropertyOptions {
161
+ /** Human-readable display name */
162
+ displayName?: string;
163
+ /** Timezone */
164
+ timeZone?: string;
165
+ /** Currency code */
166
+ currencyCode?: string;
167
+ /** Industry category */
168
+ industryCategory?: string;
169
+ }
170
+ /**
171
+ * Data stream types
172
+ */
173
+ export type DataStreamType = 'WEB_DATA_STREAM' | 'ANDROID_APP_DATA_STREAM' | 'IOS_APP_DATA_STREAM';
174
+ /**
175
+ * Data stream representation
176
+ */
177
+ export interface DataStream {
178
+ /** Unique identifier */
179
+ id: string;
180
+ /** Stream type */
181
+ type: DataStreamType;
182
+ /** Human-readable display name */
183
+ displayName: string;
184
+ /** Measurement ID for web streams (G-XXXXXXX) */
185
+ measurementId?: string;
186
+ /** Firebase App ID for app streams */
187
+ firebaseAppId?: string;
188
+ /** Default URI for web streams */
189
+ defaultUri?: string;
190
+ /** Creation timestamp */
191
+ createTime: string;
192
+ /** Last update timestamp */
193
+ updateTime?: string;
194
+ }
195
+ /**
196
+ * Options for creating a data stream
197
+ */
198
+ export interface CreateDataStreamOptions {
199
+ /** Stream type */
200
+ type: DataStreamType;
201
+ /** Human-readable display name */
202
+ displayName: string;
203
+ /** Default URI for web streams */
204
+ defaultUri?: string;
205
+ /** Bundle ID for iOS apps */
206
+ bundleId?: string;
207
+ /** Package name for Android apps */
208
+ packageName?: string;
209
+ }
210
+ /**
211
+ * Scope for custom dimensions
212
+ */
213
+ export type CustomDimensionScope = 'EVENT' | 'USER' | 'ITEM';
214
+ /**
215
+ * Custom dimension representation
216
+ */
217
+ export interface CustomDimension {
218
+ /** Unique identifier */
219
+ id: string;
220
+ /** Resource name */
221
+ name: string;
222
+ /** Parameter name used in events */
223
+ parameterName: string;
224
+ /** Human-readable display name */
225
+ displayName: string;
226
+ /** Description */
227
+ description?: string;
228
+ /** Scope of the dimension */
229
+ scope: CustomDimensionScope;
230
+ /** Whether to disallow ads personalization */
231
+ disallowAdsPersonalization?: boolean;
232
+ }
233
+ /**
234
+ * Options for creating a custom dimension
235
+ */
236
+ export interface CustomDimensionOptions {
237
+ /** Parameter name used in events */
238
+ parameterName: string;
239
+ /** Human-readable display name */
240
+ displayName: string;
241
+ /** Description */
242
+ description?: string;
243
+ /** Scope of the dimension */
244
+ scope: CustomDimensionScope;
245
+ /** Whether to disallow ads personalization */
246
+ disallowAdsPersonalization?: boolean;
247
+ }
248
+ /**
249
+ * Measurement unit for custom metrics
250
+ */
251
+ export type MeasurementUnit = 'STANDARD' | 'CURRENCY' | 'FEET' | 'METERS' | 'KILOMETERS' | 'MILES' | 'MILLISECONDS' | 'SECONDS' | 'MINUTES' | 'HOURS';
252
+ /**
253
+ * Custom metric representation
254
+ */
255
+ export interface CustomMetric {
256
+ /** Unique identifier */
257
+ id: string;
258
+ /** Resource name */
259
+ name: string;
260
+ /** Parameter name used in events */
261
+ parameterName: string;
262
+ /** Human-readable display name */
263
+ displayName: string;
264
+ /** Description */
265
+ description?: string;
266
+ /** Scope (always EVENT for metrics) */
267
+ scope: 'EVENT';
268
+ /** Measurement unit */
269
+ measurementUnit: MeasurementUnit;
270
+ /** Restricted metric type */
271
+ restrictedMetricType?: 'COST_DATA' | 'REVENUE_DATA';
272
+ }
273
+ /**
274
+ * Options for creating a custom metric
275
+ */
276
+ export interface CustomMetricOptions {
277
+ /** Parameter name used in events */
278
+ parameterName: string;
279
+ /** Human-readable display name */
280
+ displayName: string;
281
+ /** Description */
282
+ description?: string;
283
+ /** Measurement unit */
284
+ measurementUnit: MeasurementUnit;
285
+ /** Restricted metric type */
286
+ restrictedMetricType?: 'COST_DATA' | 'REVENUE_DATA';
287
+ }
288
+ /**
289
+ * Counting method for key events
290
+ */
291
+ export type CountingMethod = 'ONCE_PER_EVENT' | 'ONCE_PER_SESSION';
292
+ /**
293
+ * Key event (conversion) representation
294
+ */
295
+ export interface KeyEvent {
296
+ /** Unique identifier */
297
+ id: string;
298
+ /** Resource name */
299
+ name: string;
300
+ /** Event name that triggers this key event */
301
+ eventName: string;
302
+ /** Creation timestamp */
303
+ createTime: string;
304
+ /** How to count the conversion */
305
+ countingMethod?: CountingMethod;
306
+ /** Default value for the conversion */
307
+ defaultValue?: {
308
+ numericValue?: number;
309
+ currencyCode?: string;
310
+ };
311
+ }
312
+ /**
313
+ * Options for creating a key event
314
+ */
315
+ export interface KeyEventOptions {
316
+ /** Event name that triggers this key event */
317
+ eventName: string;
318
+ /** How to count the conversion */
319
+ countingMethod?: CountingMethod;
320
+ /** Default value for the conversion */
321
+ defaultValue?: {
322
+ numericValue?: number;
323
+ currencyCode?: string;
324
+ };
325
+ }
326
+ /**
327
+ * Date range for reports
328
+ */
329
+ export interface DateRange {
330
+ /** Start date (YYYY-MM-DD or relative: 'today', 'yesterday', '7daysAgo', '30daysAgo') */
331
+ startDate: string;
332
+ /** End date (YYYY-MM-DD or relative: 'today', 'yesterday') */
333
+ endDate: string;
334
+ /** Optional name for this date range */
335
+ name?: string;
336
+ }
337
+ /**
338
+ * Dimension specification for reports
339
+ */
340
+ export interface Dimension {
341
+ /** Dimension name (e.g., 'country', 'deviceCategory') */
342
+ name: string;
343
+ }
344
+ /**
345
+ * Metric specification for reports
346
+ */
347
+ export interface Metric {
348
+ /** Metric name (e.g., 'activeUsers', 'sessions') */
349
+ name: string;
350
+ }
351
+ /**
352
+ * Filter match types
353
+ */
354
+ export type StringMatchType = 'EXACT' | 'BEGINS_WITH' | 'ENDS_WITH' | 'CONTAINS' | 'FULL_REGEXP' | 'PARTIAL_REGEXP';
355
+ /**
356
+ * Numeric filter operations
357
+ */
358
+ export type NumericOperation = 'EQUAL' | 'LESS_THAN' | 'LESS_THAN_OR_EQUAL' | 'GREATER_THAN' | 'GREATER_THAN_OR_EQUAL';
359
+ /**
360
+ * Filter value (numeric)
361
+ */
362
+ export interface NumericValue {
363
+ int64Value?: string;
364
+ doubleValue?: number;
365
+ }
366
+ /**
367
+ * String filter specification
368
+ */
369
+ export interface StringFilter {
370
+ matchType: StringMatchType;
371
+ value: string;
372
+ caseSensitive?: boolean;
373
+ }
374
+ /**
375
+ * In-list filter specification
376
+ */
377
+ export interface InListFilter {
378
+ values: string[];
379
+ caseSensitive?: boolean;
380
+ }
381
+ /**
382
+ * Numeric filter specification
383
+ */
384
+ export interface NumericFilter {
385
+ operation: NumericOperation;
386
+ value: NumericValue;
387
+ }
388
+ /**
389
+ * Between filter specification
390
+ */
391
+ export interface BetweenFilter {
392
+ fromValue: NumericValue;
393
+ toValue: NumericValue;
394
+ }
395
+ /**
396
+ * Individual filter specification
397
+ */
398
+ export interface Filter {
399
+ fieldName: string;
400
+ stringFilter?: StringFilter;
401
+ inListFilter?: InListFilter;
402
+ numericFilter?: NumericFilter;
403
+ betweenFilter?: BetweenFilter;
404
+ }
405
+ /**
406
+ * Filter expression (supports AND/OR/NOT combinations)
407
+ */
408
+ export interface FilterExpression {
409
+ andGroup?: {
410
+ expressions: FilterExpression[];
411
+ };
412
+ orGroup?: {
413
+ expressions: FilterExpression[];
414
+ };
415
+ notExpression?: FilterExpression;
416
+ filter?: Filter;
417
+ }
418
+ /**
419
+ * Order type for dimension sorting
420
+ */
421
+ export type DimensionOrderType = 'ALPHANUMERIC' | 'CASE_INSENSITIVE_ALPHANUMERIC' | 'NUMERIC';
422
+ /**
423
+ * Order specification
424
+ */
425
+ export interface OrderBy {
426
+ metric?: {
427
+ metricName: string;
428
+ };
429
+ dimension?: {
430
+ dimensionName: string;
431
+ orderType?: DimensionOrderType;
432
+ };
433
+ desc?: boolean;
434
+ }
435
+ /**
436
+ * Minute range for realtime reports
437
+ */
438
+ export interface MinuteRange {
439
+ name?: string;
440
+ startMinutesAgo: number;
441
+ endMinutesAgo: number;
442
+ }
443
+ /**
444
+ * Report request options
445
+ */
446
+ export interface ReportOptions {
447
+ /** Date ranges to query */
448
+ dateRanges: DateRange[];
449
+ /** Dimensions to group by */
450
+ dimensions?: Dimension[];
451
+ /** Metrics to retrieve */
452
+ metrics: Metric[];
453
+ /** Dimension filter expression */
454
+ dimensionFilter?: FilterExpression;
455
+ /** Metric filter expression */
456
+ metricFilter?: FilterExpression;
457
+ /** Result offset for pagination */
458
+ offset?: number;
459
+ /** Maximum results to return */
460
+ limit?: number;
461
+ /** Sort order */
462
+ orderBys?: OrderBy[];
463
+ /** Whether to keep empty rows */
464
+ keepEmptyRows?: boolean;
465
+ /** Whether to return property quota information */
466
+ returnPropertyQuota?: boolean;
467
+ }
468
+ /**
469
+ * Realtime report options
470
+ */
471
+ export interface RealtimeReportOptions {
472
+ /** Dimensions to group by */
473
+ dimensions?: Dimension[];
474
+ /** Metrics to retrieve */
475
+ metrics?: Metric[];
476
+ /** Dimension filter expression */
477
+ dimensionFilter?: FilterExpression;
478
+ /** Metric filter expression */
479
+ metricFilter?: FilterExpression;
480
+ /** Maximum results to return */
481
+ limit?: number;
482
+ /** Minute ranges to query */
483
+ minuteRanges?: MinuteRange[];
484
+ }
485
+ /**
486
+ * Report row
487
+ */
488
+ export interface ReportRow {
489
+ dimensionValues: {
490
+ value: string;
491
+ }[];
492
+ metricValues: {
493
+ value: string;
494
+ }[];
495
+ }
496
+ /**
497
+ * Quota information
498
+ */
499
+ export interface QuotaInfo {
500
+ consumed: number;
501
+ remaining: number;
502
+ }
503
+ /**
504
+ * Property quota information
505
+ */
506
+ export interface PropertyQuota {
507
+ tokensPerDay: QuotaInfo;
508
+ tokensPerHour: QuotaInfo;
509
+ concurrentRequests: QuotaInfo;
510
+ }
511
+ /**
512
+ * Report result
513
+ */
514
+ export interface ReportResult {
515
+ /** Column headers for dimensions */
516
+ dimensionHeaders: {
517
+ name: string;
518
+ }[];
519
+ /** Column headers for metrics */
520
+ metricHeaders: {
521
+ name: string;
522
+ type: string;
523
+ }[];
524
+ /** Data rows */
525
+ rows: ReportRow[];
526
+ /** Total row count */
527
+ rowCount?: number;
528
+ /** Report metadata */
529
+ metadata?: {
530
+ currencyCode?: string;
531
+ timeZone?: string;
532
+ dataLossFromOtherRow?: boolean;
533
+ emptyReason?: string;
534
+ };
535
+ /** Property quota usage */
536
+ propertyQuota?: PropertyQuota;
537
+ }
538
+ /**
539
+ * Metric type
540
+ */
541
+ export type MetricType = 'METRIC_TYPE_UNSPECIFIED' | 'TYPE_INTEGER' | 'TYPE_FLOAT' | 'TYPE_SECONDS' | 'TYPE_MILLISECONDS' | 'TYPE_MINUTES' | 'TYPE_HOURS' | 'TYPE_STANDARD' | 'TYPE_CURRENCY' | 'TYPE_FEET' | 'TYPE_MILES' | 'TYPE_METERS' | 'TYPE_KILOMETERS';
542
+ /**
543
+ * Metric metadata
544
+ */
545
+ export interface MetricMetadata {
546
+ /** API name for the metric */
547
+ apiName: string;
548
+ /** UI display name */
549
+ uiName: string;
550
+ /** Description */
551
+ description: string;
552
+ /** Deprecated API names */
553
+ deprecatedApiNames?: string[];
554
+ /** Metric data type */
555
+ type: MetricType;
556
+ /** Expression for calculated metrics */
557
+ expression?: string;
558
+ /** Whether this is a custom definition */
559
+ customDefinition?: boolean;
560
+ /** Reasons metric may be blocked */
561
+ blockedReasons?: string[];
562
+ /** Category */
563
+ category?: string;
564
+ }
565
+ /**
566
+ * Dimension metadata
567
+ */
568
+ export interface DimensionMetadata {
569
+ /** API name for the dimension */
570
+ apiName: string;
571
+ /** UI display name */
572
+ uiName: string;
573
+ /** Description */
574
+ description: string;
575
+ /** Deprecated API names */
576
+ deprecatedApiNames?: string[];
577
+ /** Whether this is a custom definition */
578
+ customDefinition?: boolean;
579
+ /** Category */
580
+ category?: string;
581
+ }
582
+ /**
583
+ * Track event payload
584
+ */
585
+ export interface TrackEvent {
586
+ /** Event name */
587
+ name: string;
588
+ /** Event parameters */
589
+ params?: Record<string, string | number | boolean>;
590
+ /** Client ID for anonymous tracking */
591
+ clientId?: string;
592
+ /** User ID for identified tracking */
593
+ userId?: string;
594
+ /** Event timestamp (Unix epoch in microseconds) */
595
+ timestamp?: number;
596
+ /** Whether to disable personalized ads */
597
+ nonPersonalizedAds?: boolean;
598
+ }
599
+ /**
600
+ * Pageview event payload
601
+ */
602
+ export interface PageviewEvent {
603
+ /** Page path */
604
+ pagePath: string;
605
+ /** Page title */
606
+ pageTitle?: string;
607
+ /** Full page location URL */
608
+ pageLocation?: string;
609
+ /** Client ID for anonymous tracking */
610
+ clientId?: string;
611
+ /** User ID for identified tracking */
612
+ userId?: string;
613
+ /** Additional parameters */
614
+ params?: Record<string, string | number | boolean>;
615
+ }
616
+ /**
617
+ * Generated tracking snippet
618
+ */
619
+ export interface TrackingSnippet {
620
+ /** HTML snippet ready to embed */
621
+ html: string;
622
+ /** Configuration object */
623
+ config: Record<string, unknown>;
624
+ /** External script URLs */
625
+ scripts: string[];
626
+ }
627
+ /**
628
+ * Options for snippet generation
629
+ */
630
+ export interface SnippetOptions {
631
+ /** Whether to anonymize IP addresses */
632
+ anonymizeIp?: boolean;
633
+ /** Whether to send initial pageview */
634
+ sendPageView?: boolean;
635
+ /** Cookie flags */
636
+ cookieFlags?: string;
637
+ /** Custom configuration options */
638
+ customConfig?: Record<string, unknown>;
639
+ }
640
+ /**
641
+ * Options for config generation
642
+ */
643
+ export interface ConfigOptions {
644
+ /** Whether to anonymize IP addresses */
645
+ anonymizeIp?: boolean;
646
+ /** Whether to send initial pageview */
647
+ sendPageView?: boolean;
648
+ /** User ID for cross-device tracking */
649
+ userId?: string;
650
+ /** Custom dimensions to set */
651
+ customDimensions?: Record<string, string>;
652
+ }
653
+ /**
654
+ * Analytics provider capabilities
655
+ */
656
+ export interface AnalyticsCapabilities {
657
+ /** Whether property management is supported */
658
+ propertyManagement: boolean;
659
+ /** Whether data streams are supported */
660
+ dataStreams: boolean;
661
+ /** Whether custom dimensions are supported */
662
+ customDimensions: boolean;
663
+ /** Whether custom metrics are supported */
664
+ customMetrics: boolean;
665
+ /** Whether key events (conversions) are supported */
666
+ keyEvents: boolean;
667
+ /** Whether reporting is supported */
668
+ reporting: boolean;
669
+ /** Whether realtime reporting is supported */
670
+ realtimeReporting: boolean;
671
+ /** Whether server-side tracking is supported */
672
+ serverSideTracking: boolean;
673
+ /** Whether client-side snippet generation is supported */
674
+ clientSideSnippet: boolean;
675
+ /** Whether user identification is supported */
676
+ userIdentification: boolean;
677
+ /** Whether batch tracking is supported */
678
+ batchTracking: boolean;
679
+ }
680
+ /**
681
+ * Core analytics interface that all providers must implement
682
+ */
683
+ export interface AnalyticsInterface {
684
+ /**
685
+ * Create a new analytics property
686
+ */
687
+ createProperty(options: CreatePropertyOptions): Promise<Property>;
688
+ /**
689
+ * List all properties accessible to this account
690
+ */
691
+ listProperties(options?: ListPropertiesOptions): Promise<Property[]>;
692
+ /**
693
+ * Get a specific property by ID
694
+ */
695
+ getProperty(propertyId: string): Promise<Property>;
696
+ /**
697
+ * Update a property
698
+ */
699
+ updateProperty(propertyId: string, data: UpdatePropertyOptions): Promise<Property>;
700
+ /**
701
+ * Delete a property
702
+ */
703
+ deleteProperty(propertyId: string): Promise<void>;
704
+ /**
705
+ * Get all data streams for a property
706
+ */
707
+ getDataStreams(propertyId: string): Promise<DataStream[]>;
708
+ /**
709
+ * Create a new data stream
710
+ */
711
+ createDataStream(propertyId: string, options: CreateDataStreamOptions): Promise<DataStream>;
712
+ /**
713
+ * Delete a data stream
714
+ */
715
+ deleteDataStream(propertyId: string, streamId: string): Promise<void>;
716
+ /**
717
+ * Get all custom dimensions for a property
718
+ */
719
+ getCustomDimensions(propertyId: string): Promise<CustomDimension[]>;
720
+ /**
721
+ * Create a new custom dimension
722
+ */
723
+ createCustomDimension(propertyId: string, options: CustomDimensionOptions): Promise<CustomDimension>;
724
+ /**
725
+ * Archive (soft-delete) a custom dimension
726
+ */
727
+ archiveCustomDimension(propertyId: string, dimensionId: string): Promise<void>;
728
+ /**
729
+ * Get all custom metrics for a property
730
+ */
731
+ getCustomMetrics(propertyId: string): Promise<CustomMetric[]>;
732
+ /**
733
+ * Create a new custom metric
734
+ */
735
+ createCustomMetric(propertyId: string, options: CustomMetricOptions): Promise<CustomMetric>;
736
+ /**
737
+ * Archive (soft-delete) a custom metric
738
+ */
739
+ archiveCustomMetric(propertyId: string, metricId: string): Promise<void>;
740
+ /**
741
+ * Get all key events for a property
742
+ */
743
+ getKeyEvents(propertyId: string): Promise<KeyEvent[]>;
744
+ /**
745
+ * Create a new key event
746
+ */
747
+ createKeyEvent(propertyId: string, options: KeyEventOptions): Promise<KeyEvent>;
748
+ /**
749
+ * Delete a key event
750
+ */
751
+ deleteKeyEvent(propertyId: string, eventId: string): Promise<void>;
752
+ /**
753
+ * Run a report query
754
+ */
755
+ runReport(propertyId: string, options: ReportOptions): Promise<ReportResult>;
756
+ /**
757
+ * Run a realtime report query
758
+ */
759
+ runRealtimeReport(propertyId: string, options?: RealtimeReportOptions): Promise<ReportResult>;
760
+ /**
761
+ * Get available metrics for a property
762
+ */
763
+ getMetrics(propertyId: string): Promise<MetricMetadata[]>;
764
+ /**
765
+ * Get available dimensions for a property
766
+ */
767
+ getDimensions(propertyId: string): Promise<DimensionMetadata[]>;
768
+ /**
769
+ * Track a single event
770
+ */
771
+ track(event: TrackEvent): Promise<void>;
772
+ /**
773
+ * Track a pageview
774
+ */
775
+ trackPageview(pageview: PageviewEvent): Promise<void>;
776
+ /**
777
+ * Track multiple events in a batch
778
+ */
779
+ trackBatch(events: TrackEvent[]): Promise<void>;
780
+ /**
781
+ * Identify a user with traits
782
+ */
783
+ identify(userId: string, traits?: Record<string, unknown>): Promise<void>;
784
+ /**
785
+ * Generate a tracking snippet for embedding in HTML
786
+ */
787
+ generateTrackingSnippet(propertyId: string, options?: SnippetOptions): TrackingSnippet;
788
+ /**
789
+ * Generate a configuration object for programmatic use
790
+ */
791
+ generateConfig(propertyId: string, options?: ConfigOptions): Record<string, unknown>;
792
+ /**
793
+ * Get provider capabilities
794
+ */
795
+ getCapabilities(): Promise<AnalyticsCapabilities>;
796
+ /**
797
+ * Provisioning admin operations exposed by providers that support them.
798
+ *
799
+ * Optional. Providers that don't support tenant/site/user provisioning leave
800
+ * this undefined. Implementations should mirror the pattern used by
801
+ * `@happyvertical/ai`'s `AIAdminInterface`.
802
+ */
803
+ admin?: AnalyticsAdminInterface;
804
+ }
805
+ /**
806
+ * Site descriptor returned by admin providers.
807
+ */
808
+ export interface AnalyticsSite {
809
+ /**
810
+ * Provider site ID. For Matomo this is the numeric `idSite` as a string.
811
+ */
812
+ id: string;
813
+ /**
814
+ * Human-readable site name as stored by the provider.
815
+ */
816
+ name: string;
817
+ /**
818
+ * Primary URL or domain for the site.
819
+ */
820
+ url?: string;
821
+ /**
822
+ * Site timezone (e.g. `America/Edmonton`).
823
+ */
824
+ timezone?: string;
825
+ /**
826
+ * Currency code where applicable (e.g. `CAD`).
827
+ */
828
+ currency?: string;
829
+ /**
830
+ * Tenant identifier this site is associated with, when supplied at create time.
831
+ */
832
+ tenantId?: string;
833
+ /**
834
+ * Provider that owns this site descriptor.
835
+ */
836
+ provider: string;
837
+ /**
838
+ * Raw provider response.
839
+ */
840
+ raw?: unknown;
841
+ }
842
+ /**
843
+ * Options for creating a site.
844
+ */
845
+ export interface CreateAnalyticsSiteOptions {
846
+ /**
847
+ * Human-readable site name.
848
+ */
849
+ name: string;
850
+ /**
851
+ * Site URL(s). At least one is required for Matomo.
852
+ */
853
+ urls: string[];
854
+ /**
855
+ * Site timezone (IANA, e.g. `America/Edmonton`). Defaults to provider default.
856
+ */
857
+ timezone?: string;
858
+ /**
859
+ * Currency code. Defaults to provider default.
860
+ */
861
+ currency?: string;
862
+ /**
863
+ * Optional tenant identifier to associate with this site.
864
+ */
865
+ tenantId?: string;
866
+ /**
867
+ * Provider-specific request body overrides.
868
+ */
869
+ raw?: Record<string, unknown>;
870
+ }
871
+ /**
872
+ * Options for updating an existing site.
873
+ *
874
+ * Reuses the `createSite` field shapes — every field except `siteId` is
875
+ * optional, and omitted fields are left unchanged on the provider (partial
876
+ * update).
877
+ */
878
+ export interface UpdateAnalyticsSiteOptions extends Partial<CreateAnalyticsSiteOptions> {
879
+ /**
880
+ * Provider site ID of the site to update. For Matomo this is the numeric
881
+ * `idSite` as a string.
882
+ */
883
+ siteId: string;
884
+ }
885
+ /**
886
+ * User access role assignable to an analytics site.
887
+ */
888
+ export type AnalyticsAccessRole = 'noaccess' | 'view' | 'write' | 'admin';
889
+ /**
890
+ * Analytics user descriptor returned by admin providers.
891
+ */
892
+ export interface AnalyticsUser {
893
+ /**
894
+ * Login or username used to authenticate the user.
895
+ */
896
+ login: string;
897
+ /**
898
+ * Email address recorded for the user.
899
+ */
900
+ email?: string;
901
+ /**
902
+ * Tenant identifier this user is associated with, when supplied at create time.
903
+ */
904
+ tenantId?: string;
905
+ /**
906
+ * Whether the user has been granted super-user access.
907
+ */
908
+ isSuperUser?: boolean;
909
+ /**
910
+ * Provider that owns this user descriptor.
911
+ */
912
+ provider: string;
913
+ /**
914
+ * Raw provider response.
915
+ */
916
+ raw?: unknown;
917
+ }
918
+ /**
919
+ * Options for creating a user.
920
+ */
921
+ export interface CreateAnalyticsUserOptions {
922
+ /**
923
+ * Login or username for the new user.
924
+ */
925
+ login: string;
926
+ /**
927
+ * Email address for the new user.
928
+ */
929
+ email: string;
930
+ /**
931
+ * Initial password. Implementations may generate one if omitted, but should
932
+ * surface it on the returned user. For Matomo the password is required.
933
+ */
934
+ password?: string;
935
+ /**
936
+ * Optional tenant identifier to associate with this user (stored in
937
+ * provider metadata where supported).
938
+ */
939
+ tenantId?: string;
940
+ /**
941
+ * Provider-specific request body overrides.
942
+ */
943
+ raw?: Record<string, unknown>;
944
+ }
945
+ /**
946
+ * Options for granting site access to a user.
947
+ */
948
+ export interface SetUserAccessOptions {
949
+ /**
950
+ * Login or username to grant access to.
951
+ */
952
+ login: string;
953
+ /**
954
+ * Access level to grant.
955
+ */
956
+ access: AnalyticsAccessRole;
957
+ /**
958
+ * Site IDs the access applies to.
959
+ */
960
+ siteIds: string[];
961
+ }
962
+ /**
963
+ * Options for verifying that a user has sufficient access to a site.
964
+ */
965
+ export interface VerifyUserSiteAccessOptions {
966
+ /**
967
+ * Login or username to inspect.
968
+ */
969
+ login: string;
970
+ /**
971
+ * Site ID the user should be able to access.
972
+ */
973
+ siteId: string;
974
+ /**
975
+ * Minimum required access. Defaults to `view`.
976
+ */
977
+ minimumAccess?: AnalyticsAccessRole;
978
+ }
979
+ /**
980
+ * Options for verifying that a token can read a site.
981
+ */
982
+ export interface VerifyTokenSiteAccessOptions {
983
+ /**
984
+ * Token to probe. This is the token under test, not necessarily the admin
985
+ * token used by the provider instance.
986
+ */
987
+ tokenAuth: string;
988
+ /**
989
+ * Site ID the token should be able to read.
990
+ */
991
+ siteId: string;
992
+ }
993
+ /**
994
+ * Result returned by access-verification helpers.
995
+ */
996
+ export interface AnalyticsAccessVerificationResult {
997
+ /**
998
+ * Whether the requested access check passed.
999
+ */
1000
+ ok: boolean;
1001
+ /**
1002
+ * Provider that performed the check.
1003
+ */
1004
+ provider: string;
1005
+ /**
1006
+ * Login that was inspected, when the check targets a user.
1007
+ */
1008
+ login?: string;
1009
+ /**
1010
+ * Site ID that was inspected.
1011
+ */
1012
+ siteId: string;
1013
+ /**
1014
+ * Observed access level. Token probes report `view` when the token can read
1015
+ * the site and `noaccess` when it cannot.
1016
+ */
1017
+ access?: AnalyticsAccessRole;
1018
+ /**
1019
+ * Required access level used by the check.
1020
+ */
1021
+ requiredAccess?: AnalyticsAccessRole;
1022
+ /**
1023
+ * Failure reason when `ok` is false.
1024
+ */
1025
+ error?: string;
1026
+ /**
1027
+ * Provider-specific failure code when `ok` is false.
1028
+ */
1029
+ errorCode?: string;
1030
+ /**
1031
+ * Raw provider response. This is intended for debugging and may include more
1032
+ * provider data than the specific access check asked for; avoid logging it
1033
+ * verbatim in application logs.
1034
+ */
1035
+ raw?: unknown;
1036
+ }
1037
+ /**
1038
+ * Options for minting a per-user auth token scoped to a user's permissions.
1039
+ */
1040
+ export interface MintUserTokenOptions {
1041
+ /**
1042
+ * Login or username to mint the token for.
1043
+ */
1044
+ login: string;
1045
+ /**
1046
+ * Description of the token (where supported).
1047
+ */
1048
+ description?: string;
1049
+ /**
1050
+ * The target user's password. Matomo's `createAppSpecificTokenAuth`
1051
+ * confirms the *target* user's password (not the caller's) — this prevents
1052
+ * a stolen super-user token from minting tokens for arbitrary other users.
1053
+ *
1054
+ * Other providers may not need this; it's optional in the shared interface
1055
+ * but Matomo will throw without it.
1056
+ */
1057
+ passwordConfirmation?: string;
1058
+ }
1059
+ /**
1060
+ * Auth token descriptor returned by admin providers.
1061
+ */
1062
+ export interface AnalyticsUserToken {
1063
+ /**
1064
+ * The token value. Show-once for most providers; not stored in plaintext on
1065
+ * the provider side.
1066
+ */
1067
+ token: string;
1068
+ /**
1069
+ * Login the token belongs to.
1070
+ */
1071
+ login: string;
1072
+ /**
1073
+ * Description recorded on the provider.
1074
+ */
1075
+ description?: string;
1076
+ /**
1077
+ * Provider that owns this token descriptor.
1078
+ */
1079
+ provider: string;
1080
+ /**
1081
+ * Raw provider response.
1082
+ */
1083
+ raw?: unknown;
1084
+ }
1085
+ /**
1086
+ * Result of a provider health probe.
1087
+ */
1088
+ export interface AnalyticsHealthResult {
1089
+ /**
1090
+ * Whether the probe was able to reach the provider AND complete an authed
1091
+ * round-trip (if the probe is authed).
1092
+ */
1093
+ ok: boolean;
1094
+ /**
1095
+ * Provider version string, when available.
1096
+ */
1097
+ version?: string;
1098
+ /**
1099
+ * Failure reason when `ok` is false.
1100
+ */
1101
+ error?: string;
1102
+ }
1103
+ /**
1104
+ * Admin operations exposed by analytics providers that support provisioning.
1105
+ *
1106
+ * Mirrors the shape of `@happyvertical/ai`'s `AIAdminInterface`. Methods that a
1107
+ * particular provider can't support (e.g. `mintUserToken` against GA4) are left
1108
+ * out of that provider's admin object — callers should feature-check via
1109
+ * `typeof admin.mintUserToken === 'function'`.
1110
+ *
1111
+ * Because that feature-check idiom typically narrows a method into a local
1112
+ * (`const fn = admin.mintUserToken; if (fn) await fn(...)`), implementations
1113
+ * MUST keep these methods detachment-safe — i.e. bind them to the instance so a
1114
+ * detached/destructured reference still carries `this`. See `MatomoAdmin`'s
1115
+ * constructor for the reference implementation (https://github.com/happyvertical/sdk/issues/1043).
1116
+ */
1117
+ export interface AnalyticsAdminInterface {
1118
+ /**
1119
+ * Create a site/property for a tenant.
1120
+ */
1121
+ createSite(options: CreateAnalyticsSiteOptions): Promise<AnalyticsSite>;
1122
+ /**
1123
+ * List all sites visible to the calling token.
1124
+ */
1125
+ listSites(): Promise<AnalyticsSite[]>;
1126
+ /**
1127
+ * Look up a site by id. Resolves to undefined when the site does not exist.
1128
+ */
1129
+ getSite(siteId: string): Promise<AnalyticsSite | undefined>;
1130
+ /**
1131
+ * Update an existing site in place. Optional capability — partial update:
1132
+ * only the fields supplied in the options change on the provider.
1133
+ *
1134
+ * Implementations should resolve to the post-update site as read back from
1135
+ * the provider, normalized the same way `createSite`'s result is.
1136
+ */
1137
+ updateSite?(options: UpdateAnalyticsSiteOptions): Promise<AnalyticsSite>;
1138
+ /**
1139
+ * Delete a site.
1140
+ */
1141
+ deleteSite(siteId: string): Promise<void>;
1142
+ /**
1143
+ * Create a user.
1144
+ */
1145
+ createUser?(options: CreateAnalyticsUserOptions): Promise<AnalyticsUser>;
1146
+ /**
1147
+ * Look up a user by login. Resolves to undefined when the user does not exist.
1148
+ */
1149
+ getUser?(login: string): Promise<AnalyticsUser | undefined>;
1150
+ /**
1151
+ * Delete a user.
1152
+ */
1153
+ deleteUser?(login: string): Promise<void>;
1154
+ /**
1155
+ * Grant a user access to one or more sites at the given role.
1156
+ */
1157
+ setUserAccess?(options: SetUserAccessOptions): Promise<void>;
1158
+ /**
1159
+ * Verify that a user has at least the requested access to a site.
1160
+ */
1161
+ verifyUserSiteAccess?(options: VerifyUserSiteAccessOptions): Promise<AnalyticsAccessVerificationResult>;
1162
+ /**
1163
+ * Verify that a token can read a site.
1164
+ */
1165
+ verifyTokenSiteAccess?(options: VerifyTokenSiteAccessOptions): Promise<AnalyticsAccessVerificationResult>;
1166
+ /**
1167
+ * Mint a per-user auth token scoped to that user's existing permissions.
1168
+ *
1169
+ * The returned token is shown-once on most providers — implementations are
1170
+ * expected to return the live value in the response and not refetch it.
1171
+ */
1172
+ mintUserToken?(options: MintUserTokenOptions): Promise<AnalyticsUserToken>;
1173
+ /**
1174
+ * Probe provider reachability and auth. Always available — providers that
1175
+ * lack a public health endpoint should make a cheap authed call instead.
1176
+ */
1177
+ health(): Promise<AnalyticsHealthResult>;
1178
+ }
1179
+ /**
1180
+ * Base error class for analytics operations
1181
+ */
1182
+ export declare class AnalyticsError extends Error {
1183
+ code: string;
1184
+ provider?: string | undefined;
1185
+ propertyId?: string | undefined;
1186
+ constructor(message: string, code: string, provider?: string | undefined, propertyId?: string | undefined);
1187
+ }
1188
+ /**
1189
+ * Authentication failed
1190
+ */
1191
+ export declare class AuthenticationError extends AnalyticsError {
1192
+ constructor(provider?: string, message?: string, code?: string);
1193
+ }
1194
+ /**
1195
+ * Rate limit exceeded
1196
+ */
1197
+ export declare class RateLimitError extends AnalyticsError {
1198
+ retryAfter?: number;
1199
+ constructor(provider?: string, retryAfter?: number);
1200
+ }
1201
+ /**
1202
+ * Property not found
1203
+ */
1204
+ export declare class PropertyNotFoundError extends AnalyticsError {
1205
+ constructor(propertyId: string, provider?: string);
1206
+ }
1207
+ /**
1208
+ * Invalid dimension specified
1209
+ */
1210
+ export declare class InvalidDimensionError extends AnalyticsError {
1211
+ dimension: string;
1212
+ constructor(dimension: string, provider?: string);
1213
+ }
1214
+ /**
1215
+ * Invalid metric specified
1216
+ */
1217
+ export declare class InvalidMetricError extends AnalyticsError {
1218
+ metric: string;
1219
+ constructor(metric: string, provider?: string);
1220
+ }
1221
+ /**
1222
+ * Quota exceeded
1223
+ */
1224
+ export declare class QuotaExceededError extends AnalyticsError {
1225
+ quotaType?: string;
1226
+ constructor(provider?: string, quotaType?: string);
1227
+ }
1228
+ /**
1229
+ * Feature not supported by this provider
1230
+ */
1231
+ export declare class NotSupportedError extends AnalyticsError {
1232
+ feature: string;
1233
+ constructor(feature: string, provider?: string);
1234
+ }
1235
+ //# sourceMappingURL=types.d.ts.map