@segment/analytics-react-native
Version:
The hassle-free way to add Segment analytics to your React-Native app.
123 lines (120 loc) • 4.81 kB
TypeScript
import type { SegmentClient } from './analytics';
import { Timeline } from './timeline';
import { AliasEventType, GroupEventType, IdentifyEventType, PluginType, ScreenEventType, SegmentAPISettings, SegmentEvent, TrackEventType, UpdateType } from './types';
export declare class Plugin {
type: PluginType;
analytics?: SegmentClient;
configure(analytics: SegmentClient): void;
update(_settings: SegmentAPISettings, _type: UpdateType): void;
execute(event: SegmentEvent): Promise<SegmentEvent | undefined> | SegmentEvent | undefined;
shutdown(): void;
}
export declare class EventPlugin extends Plugin {
execute(event: SegmentEvent): Promise<SegmentEvent | undefined> | SegmentEvent | undefined;
identify(event: IdentifyEventType): Promise<IdentifyEventType | undefined> | IdentifyEventType | undefined;
track(event: TrackEventType): Promise<TrackEventType | undefined> | TrackEventType | undefined;
screen(event: ScreenEventType): Promise<ScreenEventType | undefined> | ScreenEventType | undefined;
alias(event: AliasEventType): Promise<AliasEventType | undefined> | AliasEventType | undefined;
group(event: GroupEventType): Promise<GroupEventType | undefined> | GroupEventType | undefined;
flush(): void | Promise<void>;
reset(): void | Promise<void>;
}
export declare class DestinationPlugin extends EventPlugin {
type: PluginType;
key: string;
timeline: Timeline;
store: any;
private hasSettings;
protected isEnabled(event: SegmentEvent): boolean;
/**
Adds a new plugin to the currently loaded set.
- Parameter plugin: The plugin to be added.
- Returns: Returns the name of the supplied plugin.
*/
add(plugin: Plugin): Plugin;
/**
Applies the supplied closure to the currently loaded set of plugins.
- Parameter closure: A closure that takes an plugin to be operated on as a parameter.
*/
apply(closure: (plugin: Plugin) => void): void;
configure(analytics: SegmentClient): void;
/**
Removes and unloads plugins with a matching name from the system.
- Parameter pluginName: An plugin name.
*/
remove(plugin: Plugin): void;
execute(event: SegmentEvent): Promise<SegmentEvent | undefined>;
}
export declare class UtilityPlugin extends EventPlugin {
}
export declare class PlatformPlugin extends Plugin {
}
export { PluginType };
/**
* WaitingPlugin - A base class for plugins that need to pause event processing
* until an asynchronous operation completes.
*
* When a WaitingPlugin is added to the Analytics client, it automatically pauses
* event processing. Events are buffered in memory until the plugin calls resume().
* If resume() is not called within 30 seconds, event processing automatically resumes.
*
* @example
* ```typescript
* class IDFAPlugin extends WaitingPlugin {
* type = PluginType.enrichment;
*
* configure(analytics: SegmentClient) {
* super.configure(analytics);
* // Request IDFA permission
* requestTrackingPermission().then((status) => {
* if (status === 'authorized') {
* // Add IDFA to context
* }
* this.resume(); // Resume event processing
* });
* }
*
* track(event: SegmentEvent) {
* // Enrich event with IDFA if available
* return event;
* }
* }
* ```
*
* Common use cases:
* - Waiting for user permissions (IDFA, location, notifications)
* - Initializing native SDKs that provide enrichment data
* - Loading remote configuration required for event processing
* - Waiting for authentication state before sending events
*
* @remarks
* Multiple WaitingPlugins can be active simultaneously. Event processing
* only resumes when ALL waiting plugins have called resume() or timed out.
*
* WaitingPlugins can be added at any plugin type (before, enrichment, destination).
* They can also be added to DestinationPlugins to pause only that destination's
* event processing.
*/
export declare class WaitingPlugin extends Plugin {
constructor();
/**
* Configure the plugin with the Analytics client.
* Automatically pauses event processing when called.
* Override this method to perform async initialization, then call resume().
*
* @param analytics - The Analytics client instance
*/
configure(analytics: SegmentClient): void;
/**
* Manually pause event processing.
* Generally not needed as adding a WaitingPlugin automatically pauses processing.
*/
pause(): void;
/**
* Resume event processing for this plugin.
* Call this method when your async operation completes.
* If all WaitingPlugins have resumed, buffered events will be processed.
*/
resume(): Promise<void>;
}
//# sourceMappingURL=plugin.d.ts.map