@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.
51 lines (40 loc) • 885 B
text/typescript
import {
Alias,
Facade,
Group,
Identify,
Options,
Page,
Screen,
Track,
} from '@segment/facade'
import { SegmentEvent } from '../core/events'
export type SegmentFacade = Facade<SegmentEvent> & {
obj: SegmentEvent
}
export function toFacade(evt: SegmentEvent, options?: Options): SegmentFacade {
let fcd = new Facade(evt, options)
if (evt.type === 'track') {
fcd = new Track(evt, options)
}
if (evt.type === 'identify') {
fcd = new Identify(evt, options)
}
if (evt.type === 'page') {
fcd = new Page(evt, options)
}
if (evt.type === 'alias') {
fcd = new Alias(evt, options)
}
if (evt.type === 'group') {
fcd = new Group(evt, options)
}
if (evt.type === 'screen') {
fcd = new Screen(evt, options)
}
Object.defineProperty(fcd, 'obj', {
value: evt,
writable: true,
})
return fcd as SegmentFacade
}