# 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.

```ts
// 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**

```ts
get status(): SdkStatus
```

Provides 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.

```ts
set status(status: SdkStatus): void
```

**Parameters**

• **status**: `SdkStatus`

**Returns**

`SdkStatus`

#### Methods

**init()**

```ts
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:

```html
<script src="sdk_url" data-config-url="your_config_url"></script>

<script>
	window.Bird.contact.identify(...identify_args);
</script>
```

#### Properties

<table><thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>Bird?</code></td><td><code>BirdSdk</code></td><td>BirdSdk is the main class for the Bird SDK. It provides access to the SDK's core features and plugins.</td></tr><tr><td><code>birdAsyncInit?</code></td><td>(<code>sdk</code>: <code>BirdSdk</code>, <code>conf</code>?: <code>BirdSdkConf</code>) => <code>void</code></td><td><p>This function is used to initialize the sdk asynchronously. It can be used to override the default configuration of the sdk.</p><p><strong>Example</strong></p><pre class="language-html"><code class="lang-html">&#x3C;script>
	window.birdAsyncInit = function (sdk, conf) {
		sdk.init({
			config: {
				...conf,
				tracking: {
					...conf.tracking,
					enabled: true,
				},
			},
		});
	};
&#x3C;/script>

\<script async src="sdk\_url" data-config-url="your\_config\_url">\</script> </code></pre></td></tr></tbody></table>

***

### 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

```ts
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()

```ts
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.
