UNPKG

@segment/analytics-next

Version:

Analytics Next (aka Analytics 2.0) is the latest version of Segment’s JavaScript SDK - enabling you to send your data to any tool without having to learn, test, or use a new API every time.

147 lines 5 kB
import { Analytics, InitOptions } from '../core/analytics'; import { Plan } from '../core/events'; import { Plugin } from '../core/plugin'; import { MetricsOptions } from '../core/stats/remote-metrics'; import { PluginFactory, RemotePlugin } from '../plugins/remote-loader'; import type { RoutingRule } from '../plugins/routing-middleware'; import { AnalyticsBuffered } from '../core/buffer'; import { ClassicIntegrationSource } from '../plugins/ajs-destination/types'; export interface RemoteIntegrationSettings { type?: string; versionSettings?: { version?: string; override?: string; componentTypes?: ('browser' | 'android' | 'ios' | 'server')[]; }; /** * We know if an integration is device mode if it has `bundlingStatus: 'bundled'` and the `browser` componentType in `versionSettings`. * History: The term 'bundle' is left over from before action destinations, when a device mode destinations were 'bundled' in a custom bundle for every analytics.js source. */ bundlingStatus?: 'bundled' | 'unbundled'; /** * Consent settings for the integration */ consentSettings?: { /** * Consent categories for the integration * @example ["CAT001", "CAT002"] */ categories: string[]; }; retryQueue?: boolean; [key: string]: any; } /** * The remote settings object for a source, typically fetched from the Segment CDN. * Warning: this is an *unstable* object. */ export interface CDNSettings { integrations: { [creationName: string]: RemoteIntegrationSettings; }; middlewareSettings?: { routingRules: RoutingRule[]; }; enabledMiddleware?: Record<string, boolean>; metrics?: MetricsOptions; plan?: Plan; legacyVideoPluginsEnabled?: boolean; remotePlugins?: RemotePlugin[]; /** * Top level consent settings */ consentSettings?: { /** * All unique consent categories for enabled destinations. * There can be categories in this array that are important for consent that are not included in any integration (e.g. 2 cloud mode categories). * @example ["Analytics", "Advertising", "CAT001"] */ allCategories: string[]; /** * Whether or not there are any unmapped destinations for enabled destinations. */ hasUnmappedDestinations: boolean; }; /** * Settings for edge function. Used for signals. */ edgeFunction?: { /** * The URL of the edge function (.js file). * @example 'https://cdn.edgefn.segment.com/MY-WRITEKEY/foo.js', */ downloadURL: string; /** * The version of the edge function * @example 1 */ version: number; } | {}; } export interface AnalyticsBrowserSettings { writeKey: string; /** * The settings for the Segment Source. * If provided, `AnalyticsBrowser` will not fetch remote settings * for the source. */ cdnSettings?: CDNSettings & Record<string, unknown>; /** * If provided, will override the default Segment CDN (https://cdn.segment.com) for this application. */ cdnURL?: string; /** * Plugins or npm-installed action destinations */ plugins?: (Plugin | PluginFactory)[]; /** * npm-installed classic destinations */ classicIntegrations?: ClassicIntegrationSource[]; } export declare function loadCDNSettings(writeKey: string, baseUrl: string): Promise<CDNSettings>; /** * The public browser interface for Segment Analytics * * @example * ```ts * export const analytics = new AnalyticsBrowser() * analytics.load({ writeKey: 'foo' }) * ``` * @link https://github.com/segmentio/analytics-next/#readme */ export declare class AnalyticsBrowser extends AnalyticsBuffered { private _resolveLoadStart; constructor(); /** * Fully initialize an analytics instance, including: * * * Fetching settings from the segment CDN (by default). * * Fetching all remote destinations configured by the user (if applicable). * * Flushing buffered analytics events. * * Loading all middleware. * * Note:️ This method should only be called *once* in your application. * * @example * ```ts * export const analytics = new AnalyticsBrowser() * analytics.load({ writeKey: 'foo' }) * ``` */ load(settings: AnalyticsBrowserSettings, options?: InitOptions): AnalyticsBrowser; /** * Instantiates an object exposing Analytics methods. * * @example * ```ts * const ajs = AnalyticsBrowser.load({ writeKey: '<YOUR_WRITE_KEY>' }) * * ajs.track("foo") * ... * ``` */ static load(settings: AnalyticsBrowserSettings, options?: InitOptions): AnalyticsBrowser; static standalone(writeKey: string, options?: InitOptions): Promise<Analytics>; } //# sourceMappingURL=index.d.ts.map