UNPKG

@ztimson/momentum

Version:

Client library for momentum

197 lines 6.14 kB
import { AssetController } from './asset-controller'; import { Meta } from './core'; import { Momentum } from './momentum'; export type AnalyticInfo = Meta & { /** Track ad campaign */ readonly adCampaign: { /** Source of the ad campaign (e.g., search engine or platform) */ readonly source?: string; /** Medium of the ad campaign (e.g., cost-per-click, email) */ readonly medium?: string; /** Name of the ad campaign */ readonly campaign?: string; /** Search term or keywords used in the campaign */ readonly term?: string; /** Specific content that triggered the campaign */ readonly content?: string; }; /** Browser information */ readonly browser: { /** Browser name */ readonly name?: string; /** Browser version */ readonly version?: string; /** Browser major version */ readonly major?: string; }; /** CAPTCHA score 0-1 (0 = bot, 1 = human) */ readonly captcha?: number; /** User consent for additional tracking */ readonly consent?: boolean; /** CPU information */ readonly cpu: { /** CPU architecture */ readonly architecture?: string; /** Number of CPU cors */ readonly cores?: number | 'Unknown'; }; /** Device information */ readonly device: { /** Device type (mobile, etc...) */ readonly type?: string; /** Manufacturer */ readonly vendor?: string; /** Device name */ readonly model?: string; }; /** JavaScript Engine information */ readonly engine: { /** Name of engine */ readonly name?: string; /** Engine version */ readonly version?: string; }; /** originating IP */ readonly ip?: string; /** System language */ readonly lang?: string; /** JavaScript heap size */ readonly mem?: number | 'Unknown'; /** Custom metrics */ readonly metrics: { [key: string]: Metric; }; /** Network speed in bytes-per-second */ readonly net?: number; /** Operating System */ readonly os: { /** OS name */ readonly name?: string; /** OS version */ readonly version?: string; }; /** User journey */ readonly pages: { page: string | 'CLOSED'; timestamp: Date; duration?: number; meta?: any; }[]; /** Website performance */ readonly performance?: Performance; /** Referer */ readonly referer?: string; /** Screen resolution */ readonly res?: number[]; /** IP Trace */ readonly trace?: IpTrace; /** Timezone offset */ readonly tz?: string; /** Original user agent string */ readonly ua?: string; }; export type IpTrace = { /** Ip trace target */ readonly query: string; /** Trace result */ readonly status: string; /** Geolocated continent */ readonly continent: string; /** Geolocated continent shortcode */ readonly continentCode: string; /** Geolocated country */ readonly country: string; /** Geolocated country shortcode */ readonly countryCode: string; /** Geolocated country region shortcode */ readonly region: string; /** Geolocated country region */ readonly regionName: string; /** Geolocated city */ readonly city: string; /** Geolocated city district/suburb */ readonly district: string; /** Geolocated postal code/zip */ readonly zip: string; /** Geolocated latitude */ readonly lat: number; /** Geolocated longitude */ readonly lon: number; /** Geolocated timezone */ readonly timezone: string; /** Geolocated timezone offset */ readonly offset: number; /** Geolocated currency */ readonly currency: string; /** Address provider */ readonly isp: string; /** Registered organization */ readonly org: string; /** AS number and organization */ readonly as: string; /** AS organization */ readonly asname: string; /** Cellular network */ readonly mobile: boolean; /** Known proxy, VPN or Tor exit node */ readonly proxy: boolean; /** Known Host/Datacenter */ readonly hosting: boolean; /** Failed trace reason */ readonly message?: string; }; /** Analytics metric */ export type Metric<T = any> = { /** Name of metric */ name: string; /** Metric category for grouping */ category?: string; /** Metric value */ value: T; /** Aggregation strategy, defaults to add */ strategy?: 'add' | 'avg' | 'count' | 'min' | 'max' | 'set'; }; export type Performance = { /** Time until first contentful paint (ms) */ fcp: number; /** Time until largest contentful paint (ms) */ lcp: number; /** Time until first byte (ms) */ ttfb: number; /** DOM load time (ms) */ dom: number; /** Total load time (ms) */ total: number; }; /** Audience metrics and metadata */ export declare class Analytics extends AssetController<AnalyticInfo> { protected momentum: Momentum; private lastPage?; private _ready?; readonly ready: Promise<void>; private _performance; performance: Promise<Performance>; private _consented?; readonly consented: Promise<boolean>; _consent?: boolean; get consent(): boolean | undefined; set consent(value: boolean | undefined); private _id; get id(): string; set id(id: string); private _new; private set new(value); get new(): boolean; constructor(momentum: Momentum); private canPromptAgain; private collectNavigationMetrics; private collectLCPMetrics; private init; consentPrompt(content?: string): Promise<boolean>; speedTest(format: true, bytes?: number): Promise<string>; speedTest(format?: false, bytes?: number): Promise<number>; ipTrace(ip: string): Promise<IpTrace>; metric(name: string | [string, string], value: number, strategy?: string): Promise<void>; page(page?: string, meta?: any): Promise<void>; } //# sourceMappingURL=analytics.d.ts.map