import { analyticsreporting_v4 } from 'googleapis'; import { DateTime } from 'luxon'; import { JsonPrimitive } from '@salesforce/ts-types'; export type UaRequest = analyticsreporting_v4.Schema$ReportRequest; export type UaResponse = analyticsreporting_v4.Schema$GetReportsResponse; export type UaReport = analyticsreporting_v4.Schema$Report; export type UaReportRow = analyticsreporting_v4.Schema$ReportRow; type DateWindow = 'day' | 'week' | 'month' | 'year'; /** * Simplified reporting options for Google Universal Analytics. * * By default, Spidergram's Universal Analytics helper generates reports * on a per-URL basis, and pulls raw value metrics rather than pre-calculated * aggregates (e.e., 'total time on page' and 'total visits' rather than 'average * time on page'). This allows us to summarize and aggregate on axis that were * never exposed to Google Analytics. * * More traditional GA reports are still possible, but it may be easier to * bypass Spidergram's helper and use Google's API directly. * * @export * @interface UaRequestOptions * @typedef {UaRequestOptions} */ export interface UaRequestOptions { /** * The number of rows to return in a single request. * * @defaultValue {100_000} * @type {number} */ pageSize: number; /** * An object with startDate and endDate strings, in 'YYYY-MM-DD' format * or '000daysago' format. If this property is populated, dateWindow and * dateOffset will be ignored. * * @see {@link buildDateRange} * * @type {startDate: string, endDate: string} */ dateRange?: { startDate: string; endDate: string; }; /** * The unit of time covered by the report. Ignored if dateRange is populated. * * @see {@link buildDateRange} * * @defaultValue {'month'} * @type {DateWindow} */ dateWindow?: DateWindow; /** * Used in conjunction with `dateWindow` to calculate the report's start * and end date. Ignored if dateRange is populated. * * @see {@link buildDateRange} * * @defaultValue {-1} * @type {number} */ dateOffset?: number; /** * The dimension used to subdivide traffic data. * * 'page': Stats for individual URLs * 'host': Aggregate stats for each hostname * 'none': Sum of all stats; will return one row only. * * @defaultValue {'page'} * @type {string} */ dimension: 'page' | 'host' | 'none'; /** * A list of GA metric expressions, or a dictionary whose keys contain * metric aliases and values contain GA metric expressions. If no metrics * are specified, Spidergram retrieves uniquePageViews, users, timeOnPage, * entrances, bounces, and exits. * * @example * ``` * let metrics = [ * 'ga:uniquePageViews', * 'ga:timeOnPage', * ]; * * metrics = { * users: 'ga:uniquePageViews', * totalTime: 'ga:timeOnPage', * } * ``` * * @type {(string[] | Record)} */ metrics: string[] | Record; /** * The metric used to sort the returned results. * * NOTE: Results are always sorted in descending order. * * @defaultValue {'ga:uniquePageViews'} * @type {string} */ order: string; /** * If set, only data for URLs at the specified hostname will be returned. * * @type {?string} */ hostname?: string; /** * A specific user agent whose traffic should be ignored; by default, Spidergram * ignores its own traffic. * * @defaultValue {'spidergram'} * @type {?string} */ spiderUserAgent?: string; /** * Ignore results with no uniquePageVisits. * * @defaultValue {true} * @type {boolean} */ ignoreUnvisited: boolean; } export declare function fetchUaReport(request: UaRequest, pageToken?: string): Promise; export declare function buildUaRequest(viewId: string, customOptions?: Partial): analyticsreporting_v4.Schema$ReportRequest; /** * Given a unit of time and an offset, generates start and end ISO dates. * * A dateOffset of -1 will generate a range starting one dateWindow ago, and * ending yesterday. (e.g., on November 10th a window of 'month' and an * offset of '-1' would generate a report for Oct9-Nov9.) * * A dateOffset of 0 will generate a range covering the most recent complete * dateWindow. (e.g., on November 10th a window of 'month' and and * offset of '0' would generate a report for Oct1-Oct31.) * * Incrementing the dateOffset (1, 2, 3, etc) moves back in time by the * specified dateWindow, much like the 'page' of a paged result set. * * @export * @param window The span of time the range should cover. * @param offset The span's offset from the current day. * @param today Optional override for the 'current day'; primarily intended for testing. */ export declare function buildDateRange(window?: DateWindow, offset?: number, today?: DateTime): { startDate: string; endDate: string; }; export declare function flattenReport(report: UaReport, defaults?: Record): Record[]; export declare function sumReportByUrl(report: Record[], normalizer?: import("@autogram/url-tools/dist/source/mutators.js").UrlMutator, key?: string): Record[]; export {}; //# sourceMappingURL=universal-analytics.d.ts.map