import type createClient from "openapi-fetch"; import type { paths } from "./schema.js"; export type { Logger } from "./base/client-utils.js"; export * from "./support-files/auth/index.js"; export * from "./support-files/console-logger.js"; import { BaseClient, type BaseClientParams } from "./base/base-client.js"; import { type DataResponseValue } from "./base/client-utils.js"; import { type OfflineMode } from "./offline.js"; export { type OfflineMode } from "./offline.js"; export { ErrorCode, AnalyticsError, type ProblemDetail, } from "./errors/index.js"; import type { ProblemDetail } from "./errors/index.js"; declare const DIMENSION_PREFIX = "dimension"; export type CustomDimension = { [x: `${typeof DIMENSION_PREFIX}${number}`]: string | null; }; export type TrackEndpoints = { [K in keyof paths]: K extends `/api/v1/websites/{id}/track-${string}` ? K : never; }[keyof paths]; type BaseTrackingRequest = paths["/api/v1/websites/{id}/track-event"]["post"]; type WebsiteTrackingContextOverride = NonNullable; export type WebsiteTrackingContext = Omit & { /** * Custom dimensions in format: { 'dimension1': 'value1', 'dimension2': 'value2' } * @example { * "dimension1": "value1", * "dimension2": "value2" * } */ customDimensions?: CustomDimension; }; export type WebsiteTrackingMetadata = BaseTrackingRequest["requestBody"]["content"]["application/json"]["metadataOverride"]; export type WebsiteTrackBackendEvent = paths[TrackEndpoints]["post"]["requestBody"]["content"]["application/json"]; export type WebsiteTrackBackendActionResponse = { data?: BaseTrackingRequest["responses"]["200" | "201"]["content"]["application/json"]["data"]; error?: ProblemDetail; }; export type AnalyticsOptions = BaseClientParams & { trackingWebsiteId?: string; organizationId?: string; matomoToken?: string; dryRun?: boolean; optOut?: boolean; forceBackendRequest?: boolean; offlineMode?: OfflineMode; }; export type WebsiteConfiguration = paths["/api/v1/websites/{id}"]["get"]["responses"]["200"]["content"]["application/json"]["data"]; export type WebsiteTrackingCode = NonNullable["content"]["application/json"]; export declare class Analytics extends BaseClient { protected client: ReturnType>; protected serviceName: "analytics"; private matomoToken?; private isDryRun; private isOptOut; private trackingWebsiteId?; private trackingMetadata?; private trackingContext?; private forceBackendRequest; private readonly offlineMode?; private readonly organizationId?; private websiteConfiguration?; private websiteConfigurationPromise?; constructor({ trackingWebsiteId, organizationId, matomoToken, dryRun, optOut, offlineMode, forceBackendRequest, ...baseApiClientOptions }: AnalyticsOptions); private retrieveWebsiteConfiguration; private matomoOnRequestMiddleware; private clientRequest; private ensureWebsiteConfiguration; private validateSiteIds; private restoreTrackingContext; private trackPush; dispatchOfflineEvents(): Promise; private trackBackendAction; /** * Updates the Matomo authentication token. * The token is optional, and is used to validate some params, during the backend requests. * If you don't set the token, the validation will be skipped. * * @note The token is not used in browser environments. */ setMatomoToken(matomoToken: string): void; /** * Configures the website ID for tracking purposes * * When used client-side, this method triggers a background request to fetch the website configuration. * The retrieved configuration is then used to initialize the Matomo tracker via the `initClientTracker` method. * * When used server-side, this method only sets the website ID without making any requests, * since configuration retrieval is handled separately on the backend. */ setTrackingWebsiteId(websiteId: string): void; /** * Retrieves the currently configured tracking website ID. */ getTrackingWebsiteId(): string | undefined; /** * Sets metadata that will be included with all subsequent tracking requests. * Setting a new value clears and overrides all previous metadata. * * @note Metadata is only used for backend tracking requests, as the metadata in browser environments are automatically retrieved. */ setTrackingMetadata(metadata: WebsiteTrackingMetadata): void; /** * Retrieves the current tracking metadata configuration. */ getTrackingMetadata(): { url?: string; clientIp?: string; userAgent?: string; referrer?: string; language?: string; screenResolution?: string; timestamp?: string | number; } | undefined; /** * Removes all configured tracking metadata. */ clearTrackingMetadata(): void; /** * Sets the tracking context for all subsequent tracking operations. * Setting a new value will clear and override all previously configured context data. * * @note When used in a browser environment, this will update the Matomo tracker with the provided user ID and custom dimensions. */ setTrackingContext(context: WebsiteTrackingContext): Promise; /** * Clears all tracking context data, including user ID and custom dimensions, * from both the internal state and the Matomo tracker. * * @note When running in a browser environment, this method also clears * the user ID and custom dimensions from the Matomo tracker instance. */ clearTrackingContext(): void; /** * Retrieves the current tracking context configuration. */ getTrackingContext(): WebsiteTrackingContext | undefined; /** * Enables or disables dry run mode. When enabled, no request will be sent * to the API service, useful for testing and debugging. */ setDryRun(dryRun: boolean): void; /** * Enables or disables tracking opt-out. When enabled, the inizialization of the script will be done, but no tracking data will be sent * to the analytics service respecting user privacy preferences. */ setOptOut(optOut: boolean): void; /** * Returns the current analytics configuration state. */ getAnalyticsConfig(): { dryRun: boolean; optOut: boolean; forceBackendRequest: boolean; }; /** * Updates the analytics configuration state. */ setAnalyticsConfig(config: { dryRun: boolean; optOut: boolean; forceBackendRequest: boolean; }): void; /** * Gets the internal Website configuration, related to the `websiteId` injected during construction * or via the `setTrackingWebsiteId` function. */ getTrackingWebsiteConfiguration(): Promise; /** * Initializes the Matomo tracker by injecting the tracking script * and configuring it with the website configuration of the currently set trackingWebsiteId. * In order to set the user ID and custom dimensions, please use the `setTrackingContext` method. * * @note This method is only available in a browser environment, since it injects the tracking script directly into the HEAD of the document. * The method also preserves any tracking commands issued before the tracker script loads. These commands are pushed to the Matomo tracker once the script is loaded. */ initClientTracker(overrideConfig?: Partial>): Promise; administration: { /** * Retrieves the last updated website seeder configuration checksum. */ getWebsitesSeederChecksum: () => Promise | undefined>>; /** * Updates the website seeder configuration checksum. */ updateWebsitesSeederChecksum: (data: NonNullable["content"]["application/json"]) => Promise; /** * Retrieves a list of all configured websites. */ getWebsites: () => Promise | undefined>>; /** * Retrieves detailed configuration for a specific website. */ getWebsiteById: (id: paths["/api/v1/websites/{id}"]["get"]["parameters"]["path"]["id"], query?: paths["/api/v1/websites/{id}"]["get"]["parameters"]["query"]) => Promise>; /** * Creates a new website configuration */ createWebsite: (data: paths["/api/v1/websites/"]["post"]["requestBody"]["content"]["application/json"]) => Promise>; /** * Updates an existing website configuration. */ updateWebsite: (id: paths["/api/v1/websites/{id}"]["patch"]["parameters"]["path"]["id"], data: NonNullable["content"]["application/json"]) => Promise>; getExportData: (id: paths["/api/v1/websites/{id}/export"]["get"]["parameters"]["path"]["id"], query: paths["/api/v1/websites/{id}/export"]["get"]["parameters"]["query"]) => Promise>; }; generate: { /** * Generates the JavaScript tracking code for initializing analytics on a website. * * @note This method is available only on the backend-side */ initTrackingJsCode: (body?: WebsiteTrackingCode) => Promise>; /** * Generates JavaScript code for tracking custom events. * * @note This method is available only on the backend-side * */ trackEventJsCode: (data: paths["/api/v1/websites/{id}/track-event"]["post"]["requestBody"]["content"]["application/json"]) => Promise; /** * Generates JavaScript code for tracking page views. * * @note This method is available only on the backend-side * */ trackPageViewJsCode: (data: paths["/api/v1/websites/{id}/track-page-view"]["post"]["requestBody"]["content"]["application/json"]) => Promise; /** * Generates JavaScript code for tracking site searches. * * @note This method is available only on the backend-side * */ trackSiteSearchJsCode: (data: paths["/api/v1/websites/{id}/track-search"]["post"]["requestBody"]["content"]["application/json"]) => Promise; /** * Generates JavaScript code for tracking link clicks. * * @note This method is available only on the backend-side * */ trackLinkJsCode: (data: paths["/api/v1/websites/{id}/track-link"]["post"]["requestBody"]["content"]["application/json"]) => Promise; /** * Generates JavaScript code for tracking content impressions. * * @note This method is available only on the backend-side * */ trackContentImpressionJsCode: (data: paths["/api/v1/websites/{id}/track-content-impression"]["post"]["requestBody"]["content"]["application/json"]) => Promise; /** * Generates JavaScript code for tracking content interactions. * * @note This method is available only on the backend-side * */ trackContentInteractionJsCode: (data: paths["/api/v1/websites/{id}/track-content-interaction"]["post"]["requestBody"]["content"]["application/json"]) => Promise; }; track: { /** * Tracks custom event * @note The contextOverride parameter allows overriding specific custom dimensions for this event only, while preserving other global tracking context values. Set a dimension to null to remove it for this event. */ event: (data: paths["/api/v1/websites/{id}/track-event"]["post"]["requestBody"]["content"]["application/json"]) => Promise; /** * Tracks page views * @note The contextOverride parameter allows overriding specific custom dimensions for this event only, while preserving other global tracking context values. Set a dimension to null to remove it for this event. */ pageView: (data: paths["/api/v1/websites/{id}/track-page-view"]["post"]["requestBody"]["content"]["application/json"]) => Promise; /** * Tracks site search * @note The contextOverride parameter allows overriding specific custom dimensions for this event only, while preserving other global tracking context values. Set a dimension to null to remove it for this event. */ siteSearch: (data: paths["/api/v1/websites/{id}/track-search"]["post"]["requestBody"]["content"]["application/json"]) => Promise; /** * Tracks link click * * if linkType is 'link' the link is an outgoing link, if 'download' the link is a download * @note The contextOverride parameter allows overriding specific custom dimensions for this event only, while preserving other global tracking context values. Set a dimension to null to remove it for this event. */ link: (data: paths["/api/v1/websites/{id}/track-link"]["post"]["requestBody"]["content"]["application/json"]) => Promise; /** * Tracks content impression * @note The contextOverride parameter allows overriding specific custom dimensions for this event only, while preserving other global tracking context values. Set a dimension to null to remove it for this event. */ contentImpression: (data: paths["/api/v1/websites/{id}/track-content-impression"]["post"]["requestBody"]["content"]["application/json"]) => Promise; /** * Tracks content interaction * @note The contextOverride parameter allows overriding specific custom dimensions for this event only, while preserving other global tracking context values. Set a dimension to null to remove it for this event. */ contentInteraction: (data: paths["/api/v1/websites/{id}/track-content-interaction"]["post"]["requestBody"]["content"]["application/json"]) => Promise; }; protected checkToken(): void; } //# sourceMappingURL=index.d.ts.map