/************************************************************************* * Copyright 2020 Adobe * All Rights Reserved. * * NOTICE: Adobe permits you to use, modify, and distribute this file in * accordance with the terms of the Adobe license agreement accompanying * it. If you have received this file from a source other than Adobe, * then your use, modification, or distribution of it requires the prior * written permission of Adobe. **************************************************************************/ /** * @packageDocumentation * @module metrics */ import Analytics from './Analytics'; import History from './History'; import Metric from './Metric'; /** * Defines APIs on a timer. */ export interface Timer { /** * Records the elapsed time from when the timer was created by calling Metrics.start API. * @param event The name of the event being logged. The `{event: string}` form of this argument * can be used to specify the precise event name that should be recorded (the prefix supplied * at construction time is ignored). * @returns The elapsed time since the timer started, in milliseconds. */ time(event: string | { event: string; }, ...args: any): number; } /** * Defines metrics APIs. */ export default interface Metrics { /** * The Analytics APIs are designed to mirror the Omega APIs, enabling an Analtyics record to be * remotely stored which simulatenously captures additional context provided by the Metrics system * at the same time that window.digitalData is sent to analytics. Two use cases are supported, * described as follows. * * For applications that provide Omega launch script configuration to the * `MetricsBrowserRuntime.init()` method, the corresponding portions of the digitalData object can * be supplied to the following APIs, and the Metrics SDK will store the provided object in * `window.digitalData`, and simultaneously record the Analytics record in remote storage and call * the Omega `window._satellite.track()` method. This approach assures consistency in the data * between Omega and Metrics. */ analytics: Readonly; /** * The History APIs are designed to mirror browser history management. Calling a Metrics history * API is recommended either immediately before or after a call to window history, and will record * a History record type and begin a new page load by generating a new HistoryID guid. */ history: Readonly; /** * Log a debug message similar to console.debug(). * @param message The message being logged. * @param args Additional data associated to the log entry. */ debug(message: string, ...args: any): void; /** * Log an error message similar to console.error(). * @param message The message being logged. * @param args Additional data associated to the error. */ error(message: string, ...args: any): void; /** * Records the specified event. * @param event The name of the event being logged. * @param args Additional data associated to the event. */ event(event: string | string[], ...args: any): void; /** * Log an informational message similar to console.info(). * @param message The message being logged. * @param args Additional data associated to the log entry. */ info(message: string, ...args: any): void; /** * Log an informational message similar to console.log(). * @param message The message being logged. * @param args Additional data associated to the log entry. */ log(message: string, ...args: any): void; /** * Construct a named "Recent" event and emit it to storage. The payload is expected * to contain PII so downstream handling must a) keep the data bag intact, and * b) send the Recent record (with PII) only to Unified Recents. PII must be * removed before sending to ADX. * @function * @param revent The event. * @param args Optional arguments to be applied to the recorded metrics. * @returns A promise that resolves to the number of metrics that * were queued for eventual flushing. */ recent(revent: string | string[], ...args: any): void; /** * Starts a named timer that can be used to record time taken for an operation. * @param name The name for the timer, which is used as a prefix for the * emitted timer events. * @param args Additional data associated to the timer. */ start(name: string, ...args: any): Timer; /** * Stores the specified metric entry. * @param metric The metric to be logged. */ store(metric: Metric): void; /** * Log a warning message similar to console.warn(). * @param message The message being logged. * @param args Additional data associated to the log entry. */ warn(message: string, ...args: any): void; }