API Reference
BirdSdk
BirdSdk is the main class for the Bird SDK. It provides access to the SDK's core features and plugins.
Examples
If using the SDK as a script tag, the SDK is automatically initialized with the provided configuration and can be accessed through the global Bird variable.
Ejemplo de código
// Identify the user
await Bird.contact.identify({
strategy: 'Visitor',
identifier: {
key: 'emailaddress',
value: 'dan@example.com',
},
});
// Track an event
Bird.tracker.web.pageViewed(event_props, event_opts);Properties
| Property | Type |
|---|---|
| api | BirdSdkApi |
| contact | IdentityManager |
| tracker | BirdTracker |
Accessors
status
Ejemplo de código
get status(): SdkStatusProvides the current status of the SDK. The status can be one of the following:
- idle: The SDK has not been initialized yet.
- initializing: The SDK is currently initializing.
- initialized: The SDK has been initialized successfully.
- error: The SDK failed to initialize.
Ejemplo de código
set status(status: SdkStatus): voidParameters
• status: SdkStatus
Returns
SdkStatus
Methods
init()
Ejemplo de código
init(opts: BirdSdkInitOptions): Promise<void>Initializes the Bird SDK with the provided options.
- If using the SDK as a script tag, this method is automatically called with the provided configuration.
- This method should be called once before using any other SDK methods.
- This is an async method and should be awaited before using the SDK.
Parameters
• opts: BirdSdkInitOptions
Returns
Promise<void>
BirdInTheWindow
Represents the Bird SDK instance that is available in the global scope.
Example
You can access the sdk instance in the global scope after the sdk is loaded:
Ejemplo de código
<script src="sdk_url" data-config-url="your_config_url"></script>
<script>
window.Bird.contact.identify(...identify_args);
</script>Properties
| Property | Type | Description |
|---|---|---|
| Bird? | BirdSdk | BirdSdk is the main class for the Bird SDK. It provides access to the SDK's core features and plugins. |
| birdAsyncInit? | (sdk: BirdSdk, conf?: BirdSdkConf) => void | This function is used to initialize the sdk asynchronously. It can be used to override the default configuration of the sdk.Example<script> window.birdAsyncInit = function (sdk, conf) { sdk.init({ config: { ...conf, tracking: { ...conf.tracking, enabled: true, }, }, }); }; </script> <script async src="sdk_url" data-config-url="your_config_url"></script> |
BirdPluginContext
BirdPluginContext is the context that is passed to the plugins when they are initialized. It provides access to the sdk's core features and allows the plugins to interact with the sdk.
Example
Ejemplo de código
const plugin: BirdPlugin = (ctx) => {
ctx.tracker.track(...trackArgs);
};Properties
| Property | Type |
|---|---|
| api | BirdSdkApi |
| contact | IdentityManager |
| getConf | () => null | { apiHost: string; embeddables: EmbeddablesConf; tracking: TrackingConf; trackingEndpoint: string; workspaceId: string; writeKey: string; } |
| persister | BirdSdkPersister |
| status | SdkStatus |
| tracker | BirdTracker |
createBirdSdk()
Ejemplo de código
function createBirdSdk(deps: CreateSdkDependencies): BirdSdk;Factory function to create an instance of BirdSdk.
Parameters
• deps: CreateSdkDependencies = {}
Returns
BirdSdk
Remarks
- No dependencies are required but can be injected to override the default implementations.