Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Nov 7, 2023
1 parent bc890e6 commit 5600222
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/browser/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export interface LegacySettings {
*/
allCategories: string[]
}

disableAnalytics: boolean
}

export interface AnalyticsBrowserSettings extends AnalyticsSettings {
Expand Down Expand Up @@ -323,6 +325,14 @@ async function loadAnalytics(
legacySettings = options.updateCDNSettings(legacySettings)
}

// if options.disable is a function, we allow user to disable analytics based on CDN Settings
if (typeof options.disable === 'function') {
const disabled = await options.disable(legacySettings)
if (disabled) {
return [new NullAnalytics(), Context.system()]
}
}

const retryQueue: boolean =
legacySettings.integrations['Segment.io']?.retryQueue ?? true

Expand Down
12 changes: 11 additions & 1 deletion packages/browser/src/core/analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,19 @@ export interface InitOptions {
* 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.
*
* @example
* ### Basic (Will not not fetch any CDN settings)
* ```ts
* disable: process.env.NODE_ENV === 'test'
* ```
*
* ### Advanced (Fetches CDN Settings. Do not use this unless you require CDN settings for some reason)
* ```ts
* disable: (cdnSettings) => cdnSettings.foo === 'bar'
* ```
*/
disable?: boolean
disable?:
| boolean
| ((LegacySettings: LegacySettings) => boolean | Promise<boolean>)
}

/* analytics-classic stubs */
Expand Down

0 comments on commit 5600222

Please sign in to comment.