@@ -5174,102 +5174,19 @@ import Ajv, { ErrorObject } from 'ajv'
51745174 * You can install it by following instructions at: https://segment.com/docs/sources/website/analytics.js/quickstart/
51755175 * Make sure to also include the TypeScript declarations with: \`npm install --dev @types/segment-analytics\`
51765176 */
5177- declare global {
5177+ import type { AnalyticsSnippet, Analytics, AnalyticsBrowser, Options } from '@segment/analytics-next'
5178+
5179+ declare global {
51785180 interface Window {
5179- analytics: SegmentAnalytics.AnalyticsJS
5181+ analytics: AnalyticsSnippet;
51805182 }
51815183}
51825184
5185+ type AnyAnalytics = AnalyticsSnippet | Analytics | AnalyticsBrowser
5186+
51835187/** The callback exposed by analytics.js. */
51845188export type Callback = () => void
51855189
5186- /** A dictionary of options. For example, enable or disable specific destinations for the call. */
5187- export interface Options {
5188- /**
5189- * Selectivly filter destinations. By default all destinations are enabled.
5190- * https://segment.com/docs/sources/website/analytics.js/#selecting-destinations
5191- */
5192- integrations?: {
5193- [key: string]: boolean | { [key: string]: any }
5194- }
5195- /**
5196- * A dictionary of extra context to attach to the call.
5197- * https://segment.com/docs/spec/common/#context
5198- */
5199- context?: Context
5200- }
5201-
5202- /**
5203- * Context is a dictionary of extra information that provides useful context about a datapoint.
5204- * @see {@link https://segment.com/docs/spec/common/#context}
5205- */
5206- export interface Context extends Record<string, any> {
5207- active?: boolean
5208- app?: {
5209- name?: string
5210- version?: string
5211- build?: string
5212- }
5213- campaign?: {
5214- name?: string
5215- source?: string
5216- medium?: string
5217- term?: string
5218- content?: string
5219- }
5220- device?: {
5221- id?: string
5222- manufacturer?: string
5223- model?: string
5224- name?: string
5225- type?: string
5226- version?: string
5227- }
5228- ip?: string
5229- locale?: string
5230- location?: {
5231- city?: string
5232- country?: string
5233- latitude?: string
5234- longitude?: string
5235- region?: string
5236- speed?: string
5237- }
5238- network?: {
5239- bluetooth?: string
5240- carrier?: string
5241- cellular?: string
5242- wifi?: string
5243- }
5244- os?: {
5245- name?: string
5246- version?: string
5247- }
5248- page?: {
5249- hash?: string
5250- path?: string
5251- referrer?: string
5252- search?: string
5253- title?: string
5254- url?: string
5255- }
5256- referrer?: {
5257- type?: string
5258- name?: string
5259- url?: string
5260- link?: string
5261- }
5262- screen?: {
5263- density?: string
5264- height?: string
5265- width?: string
5266- }
5267- timezone?: string
5268- groupId?: string
5269- traits?: Record<string, any>
5270- userAgent?: string
5271- }
5272-
52735190export type ViolationHandler = (
52745191 message: Record<string, any>,
52755192 violations: ErrorObject[]
@@ -5297,7 +5214,7 @@ export const defaultValidationErrorHandler: ViolationHandler = (message, violati
52975214
52985215let onViolation = defaultValidationErrorHandler
52995216
5300- let analytics: () => SegmentAnalytics.AnalyticsJS | undefined = () => {
5217+ let analytics: () => AnyAnalytics | undefined = () => {
53015218 return window.analytics;
53025219};
53035220
@@ -5307,7 +5224,7 @@ export interface TypewriterOptions {
53075224 * Underlying analytics instance where analytics calls are forwarded on to.
53085225 * Defaults to window.analytics.
53095226 */
5310- analytics?: SegmentAnalytics.AnalyticsJS ;
5227+ analytics?: AnyAnalytics ;
53115228 /**
53125229 * Handler fired when if an event does not match its spec. This handler
53135230 * does not fire in production mode, because it requires inlining the full
@@ -5325,7 +5242,7 @@ export interface TypewriterOptions {
53255242 * @param {TypewriterOptions} options - the options to upsert
53265243 *
53275244 * @typedef {Object} TypewriterOptions
5328- * @property {AnalyticsJS } [analytics] - Underlying analytics instance where analytics
5245+ * @property {AnyAnalytics } [analytics] - Underlying analytics instance where analytics
53295246 * calls are forwarded on to. Defaults to window.analytics.
53305247 * @property {Function} [onViolation] - Handler fired when if an event does not match its spec. This handler does not fire in
53315248 * production mode, because it requires inlining the full JSON Schema spec for each event in your Tracking Plan. By default,
@@ -5785,7 +5702,7 @@ const clientAPI = {
57855702 * @param {TypewriterOptions} options - the options to upsert
57865703 *
57875704 * @typedef {Object} TypewriterOptions
5788- * @property {AnalyticsJS } [analytics] - Underlying analytics instance where analytics
5705+ * @property {AnyAnalytics } [analytics] - Underlying analytics instance where analytics
57895706 * calls are forwarded on to. Defaults to window.analytics.
57905707 * @property {Function} [onViolation] - Handler fired when if an event does not match its spec. This handler does not fire in
57915708 * production mode, because it requires inlining the full JSON Schema spec for each event in your Tracking Plan. By default,
0 commit comments