@@ -2,12 +2,7 @@ import { getProcessEnv } from '../lib/get-process-env'
22import { getCDN , setGlobalCDNUrl } from '../lib/parse-cdn'
33
44import { fetch } from '../lib/fetch'
5- import {
6- Analytics ,
7- AnalyticsSettings ,
8- NullAnalytics ,
9- InitOptions ,
10- } from '../core/analytics'
5+ import { Analytics , NullAnalytics , InitOptions } from '../core/analytics'
116import { Context } from '../core/context'
127import { Plan } from '../core/events'
138import { Plugin } from '../core/plugin'
@@ -111,7 +106,8 @@ export interface CDNSettings {
111106 }
112107}
113108
114- export interface AnalyticsBrowserSettings extends AnalyticsSettings {
109+ export interface AnalyticsBrowserSettings {
110+ writeKey : string
115111 /**
116112 * The settings for the Segment Source.
117113 * If provided, `AnalyticsBrowser` will not fetch remote settings
@@ -122,6 +118,14 @@ export interface AnalyticsBrowserSettings extends AnalyticsSettings {
122118 * If provided, will override the default Segment CDN (https://cdn.segment.com) for this application.
123119 */
124120 cdnURL ?: string
121+ /**
122+ * Plugins or npm-installed action destinations
123+ */
124+ plugins ?: ( Plugin | PluginFactory ) [ ]
125+ /**
126+ * npm-installed classic destinations
127+ */
128+ classicIntegrations ?: ClassicIntegrationSource [ ]
125129}
126130
127131export function loadLegacySettings (
@@ -330,31 +334,31 @@ async function loadAnalytics(
330334 preInitBuffer . push ( new PreInitMethodCall ( 'page' , [ ] ) )
331335 }
332336
333- let legacySettings =
337+ let cdnSettings =
334338 settings . cdnSettings ??
335339 ( await loadLegacySettings ( settings . writeKey , settings . cdnURL ) )
336340
337341 if ( options . updateCDNSettings ) {
338- legacySettings = options . updateCDNSettings ( legacySettings )
342+ cdnSettings = options . updateCDNSettings ( cdnSettings )
339343 }
340344
341345 // if options.disable is a function, we allow user to disable analytics based on CDN Settings
342346 if ( typeof options . disable === 'function' ) {
343- const disabled = await options . disable ( legacySettings )
347+ const disabled = await options . disable ( cdnSettings )
344348 if ( disabled ) {
345349 return [ new NullAnalytics ( ) , Context . system ( ) ]
346350 }
347351 }
348352
349353 const retryQueue : boolean =
350- legacySettings . integrations [ 'Segment.io' ] ?. retryQueue ?? true
354+ cdnSettings . integrations [ 'Segment.io' ] ?. retryQueue ?? true
351355
352356 options = {
353357 retryQueue,
354358 ...options ,
355359 }
356360
357- const analytics = new Analytics ( settings , options )
361+ const analytics = new Analytics ( { ... settings , cdnSettings } , options )
358362
359363 attachInspector ( analytics )
360364
@@ -367,8 +371,8 @@ async function loadAnalytics(
367371 | undefined
368372
369373 Stats . initRemoteMetrics ( {
370- ...legacySettings . metrics ,
371- host : segmentLoadOptions ?. apiHost ?? legacySettings . metrics ?. host ,
374+ ...cdnSettings . metrics ,
375+ host : segmentLoadOptions ?. apiHost ?? cdnSettings . metrics ?. host ,
372376 protocol : segmentLoadOptions ?. protocol ,
373377 } )
374378
@@ -377,7 +381,7 @@ async function loadAnalytics(
377381
378382 const ctx = await registerPlugins (
379383 settings . writeKey ,
380- legacySettings ,
384+ cdnSettings ,
381385 analytics ,
382386 options ,
383387 plugins ,
0 commit comments