|
| 1 | +/** |
| 2 | + * These settings will be exposed via the public API |
| 3 | + */ |
| 4 | +import { IntegrationsOptions, Plan } from '../core/events' |
| 5 | +import { MetricsOptions } from '../core/stats/remote-metrics' |
| 6 | +import { ClassicIntegrationSource } from '../plugins/ajs-destination/types' |
| 7 | +import { PluginFactory, RemotePlugin } from '../plugins/remote-loader' |
| 8 | +import { Plugin } from '../core/plugin' |
| 9 | +import { RoutingRule } from '../plugins/routing-middleware' |
| 10 | +import { CookieOptions, StorageSettings } from '../core/storage' |
| 11 | +import { UserOptions } from '../core/user' |
| 12 | +import { HighEntropyHint } from '../lib/client-hints/interfaces' |
| 13 | + |
| 14 | +export interface RemoteIntegrationSettings { |
| 15 | + /* @deprecated - This does not indicate browser types anymore */ |
| 16 | + type?: string |
| 17 | + |
| 18 | + versionSettings?: { |
| 19 | + version?: string |
| 20 | + override?: string |
| 21 | + componentTypes?: ('browser' | 'android' | 'ios' | 'server')[] |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * We know if an integration is device mode if it has `bundlingStatus: 'bundled'` and the `browser` componentType in `versionSettings`. |
| 26 | + * 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. |
| 27 | + */ |
| 28 | + bundlingStatus?: 'bundled' | 'unbundled' |
| 29 | + |
| 30 | + /** |
| 31 | + * Consent settings for the integration |
| 32 | + */ |
| 33 | + consentSettings?: { |
| 34 | + /** |
| 35 | + * Consent categories for the integration |
| 36 | + * @example ["CAT001", "CAT002"] |
| 37 | + */ |
| 38 | + categories: string[] |
| 39 | + } |
| 40 | + |
| 41 | + // Segment.io specific |
| 42 | + retryQueue?: boolean |
| 43 | + |
| 44 | + // any extra unknown settings |
| 45 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 46 | + [key: string]: any |
| 47 | +} |
| 48 | + |
| 49 | +/** |
| 50 | + * The remote settings object for a source, typically fetched from the Segment CDN. |
| 51 | + * Warning: this is an *unstable* object. |
| 52 | + */ |
| 53 | +export interface CDNSettings { |
| 54 | + integrations: { |
| 55 | + [creationName: string]: RemoteIntegrationSettings |
| 56 | + } |
| 57 | + |
| 58 | + middlewareSettings?: { |
| 59 | + routingRules: RoutingRule[] |
| 60 | + } |
| 61 | + |
| 62 | + enabledMiddleware?: Record<string, boolean> |
| 63 | + metrics?: MetricsOptions |
| 64 | + |
| 65 | + plan?: Plan |
| 66 | + |
| 67 | + legacyVideoPluginsEnabled?: boolean |
| 68 | + |
| 69 | + remotePlugins?: RemotePlugin[] |
| 70 | + |
| 71 | + /** |
| 72 | + * Top level consent settings |
| 73 | + */ |
| 74 | + consentSettings?: { |
| 75 | + /** |
| 76 | + * All unique consent categories for enabled destinations. |
| 77 | + * 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). |
| 78 | + * @example ["Analytics", "Advertising", "CAT001"] |
| 79 | + */ |
| 80 | + allCategories: string[] |
| 81 | + |
| 82 | + /** |
| 83 | + * Whether or not there are any unmapped destinations for enabled destinations. |
| 84 | + */ |
| 85 | + hasUnmappedDestinations: boolean |
| 86 | + } |
| 87 | + /** |
| 88 | + * Settings for edge function. Used for signals. |
| 89 | + */ |
| 90 | + edgeFunction?: // this is technically non-nullable according to ajs-renderer atm, but making it optional because it's strange API choice, and we might want to change it. |
| 91 | + | { |
| 92 | + /** |
| 93 | + * The URL of the edge function (.js file). |
| 94 | + * @example 'https://cdn.edgefn.segment.com/MY-WRITEKEY/foo.js', |
| 95 | + */ |
| 96 | + downloadURL: string |
| 97 | + /** |
| 98 | + * The version of the edge function |
| 99 | + * @example 1 |
| 100 | + */ |
| 101 | + version: number |
| 102 | + } |
| 103 | + | {} |
| 104 | + |
| 105 | + /** |
| 106 | + * Settings for auto instrumentation |
| 107 | + */ |
| 108 | + autoInstrumentationSettings?: { |
| 109 | + sampleRate: number |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +/** |
| 114 | + * These are the settings that are the first argument to the npm installed plugin. |
| 115 | + */ |
| 116 | +export interface AnalyticsBrowserSettings { |
| 117 | + // TODO: Having two different configuration patterns for snippet and npm is confusing. |
| 118 | + writeKey: string |
| 119 | + /** |
| 120 | + * The settings for the Segment Source. |
| 121 | + * If provided, `AnalyticsBrowser` will not fetch remote settings |
| 122 | + * for the source. |
| 123 | + */ |
| 124 | + cdnSettings?: CDNSettings & Record<string, unknown> |
| 125 | + /** |
| 126 | + * If provided, will override the default Segment CDN (https://cdn.segment.com) for this application. |
| 127 | + */ |
| 128 | + cdnURL?: string |
| 129 | + /** |
| 130 | + * Plugins or npm-installed action destinations |
| 131 | + */ |
| 132 | + plugins?: (Plugin | PluginFactory)[] |
| 133 | + /** |
| 134 | + * npm-installed classic destinations |
| 135 | + */ |
| 136 | + classicIntegrations?: ClassicIntegrationSource[] |
| 137 | +} |
| 138 | + |
| 139 | +/** |
| 140 | + * The settings that are used to configure the analytics instance |
| 141 | + */ |
| 142 | +export interface AnalyticsSettings { |
| 143 | + writeKey: string |
| 144 | + cdnSettings?: CDNSettings |
| 145 | + cdnURL?: string |
| 146 | +} |
| 147 | + |
| 148 | +export interface InitOptions { |
| 149 | + /** |
| 150 | + * Disables storing any data on the client-side via cookies or localstorage. |
| 151 | + * Defaults to `false`. |
| 152 | + * |
| 153 | + */ |
| 154 | + disableClientPersistence?: boolean |
| 155 | + /** |
| 156 | + * Disables automatically converting ISO string event properties into Dates. |
| 157 | + * ISO string to Date conversions occur right before sending events to a classic device mode integration, |
| 158 | + * after any destination middleware have been ran. |
| 159 | + * Defaults to `false`. |
| 160 | + */ |
| 161 | + disableAutoISOConversion?: boolean |
| 162 | + initialPageview?: boolean |
| 163 | + cookie?: CookieOptions |
| 164 | + storage?: StorageSettings |
| 165 | + user?: UserOptions |
| 166 | + group?: UserOptions |
| 167 | + integrations?: IntegrationsOptions |
| 168 | + plan?: Plan |
| 169 | + retryQueue?: boolean |
| 170 | + obfuscate?: boolean |
| 171 | + /** |
| 172 | + * This callback allows you to update/mutate CDN Settings. |
| 173 | + * This is called directly after settings are fetched from the CDN. |
| 174 | + * @internal |
| 175 | + */ |
| 176 | + updateCDNSettings?: (unstableCDNSettings: CDNSettings) => CDNSettings |
| 177 | + /** |
| 178 | + * Disables or sets constraints on processing of query string parameters |
| 179 | + */ |
| 180 | + useQueryString?: |
| 181 | + | boolean |
| 182 | + | { |
| 183 | + aid?: RegExp |
| 184 | + uid?: RegExp |
| 185 | + } |
| 186 | + /** |
| 187 | + * Array of high entropy Client Hints to request. These may be rejected by the user agent - only required hints should be requested. |
| 188 | + */ |
| 189 | + highEntropyValuesClientHints?: HighEntropyHint[] |
| 190 | + /** |
| 191 | + * When using the snippet, this is the key that points to the global analytics instance (e.g. window.analytics). |
| 192 | + * default: analytics |
| 193 | + */ |
| 194 | + globalAnalyticsKey?: string |
| 195 | + |
| 196 | + /** |
| 197 | + * Disable sending any data to Segment's servers. All emitted events and API calls (including .ready()), will be no-ops, and no cookies or localstorage will be used. |
| 198 | + * |
| 199 | + * @example |
| 200 | + * ```ts |
| 201 | + * disable: process.env.NODE_ENV === 'test' |
| 202 | + * ``` |
| 203 | + */ |
| 204 | + disable?: |
| 205 | + | boolean |
| 206 | + | ((unstableCDNSettings: CDNSettings) => boolean | Promise<boolean>) |
| 207 | +} |
0 commit comments