npm package: @geeklab.app/audiencelab-sdk
Description: The Geeklab AudienceLab SDK is a powerful tool for integrating audience analytics and event tracking into your React applications.
Latest version: 1.2.20

# Geeklab AudienceLab SDK

The Geeklab AudienceLab SDK is a powerful tool for integrating audience analytics and event tracking into your React applications.

## Installation

To install the SDK, use npm:

```bash
npm install @geeklab.app/audiencelab-sdk@latest
```

Install the dependencies

```bash
npm install react-native-device-info @react-native-async-storage/async-storage
```

Link the dependencies (React Native 0.60 or newer, you don’t need to run the link command manually. Instead, ensure the libraries are correctly installed, and React Native will handle linking automatically.)

```bash
npx react-native link react-native-device-info
npx react-native link @react-native-async-storage/async-storage
```

After install navigate to the ios library and install pods

```bash
cd ios && pod install
```

## Usage

### Initialization

Before using the SDK, you need to initialize it with your API key:

```javascript
import { initializeAudiencelab } from '@geeklab.app/audiencelab-sdk'
const apiKey = 'YOUR_API_KEY_HERE'
initializeAudiencelab(apiKey)
  .then(({ token, metrics }) => {
    console.log('SDK initialized successfully:', token, metrics)
  })
  .catch((error) => {
    console.error('Failed to initialize SDK:', error)
  })
```

### Sending Custom Events

#### Purchase Event

To send a custom purchase event, use the `sendCustomPurchaseEvent` function:

```javascript
import { sendCustomPurchaseEvent } from '@geeklab.app/audiencelab-sdk'
sendCustomPurchaseEvent(
  'item123',
  'Premium Subscription',
  9.99,
  'USD',
  'completed',
)
  .then((response) => {
    console.log('Purchase event sent successfully:', response)
  })
  .catch((error) => {
    console.error('Failed to send purchase event:', error)
  })
```

#### Ad Event

To send a custom ad event, use the `sendCustomAdEvent` function:

```javascript
import { sendCustomAdEvent } from '@geeklab.app/audiencelab-sdk'
sendCustomAdEvent(
  'ad456',
  'Video Ad',
  'YouTube',
  30,
  true,
  'YouTube',
  'Channel1',
  0.5,
  'USD',
)
  .then((response) => {
    console.log('Ad event sent successfully:', response)
  })
  .catch((error) => {
    console.error('Failed to send ad event:', error)
  })
```

## API Reference

### `initializeAudiencelab(apiKey: string): Promise<{ token: string, metrics: any }>`

Initializes the SDK with the provided API key.

- **apiKey**: Your API key for the Geeklab AudienceLab service.

### `sendCustomPurchaseEvent(id: string, name: string, value: number, currency: string, status: string): Promise<any>`

Sends a custom purchase event.

- **id**: The ID of the item purchased.
- **name**: The name of the item purchased.
- **value**: The value of the purchase.
- **currency**: The currency of the purchase.
- **status**: The status of the purchase (e.g., 'completed').

### `sendCustomAdEvent(adId: string, name: string, source: string, watchTime: number, reward: boolean, mediaSource: string, channel: string, value: number, currency: string): Promise<any>`

Sends a custom ad event.

- **adId**: The ID of the ad.
- **name**: The name of the ad.
- **source**: The source of the ad.
- **watchTime**: The watch time of the ad in seconds.
- **reward**: Whether the ad was rewarded.
- **mediaSource**: The media source of the ad.
- **channel**: The channel of the ad.
- **value**: The value associated with the ad.
- **currency**: The currency of the value.

## License

This SDK is licensed under the MIT License.

## Contributing

Contributions are welcome! Please open an issue or submit a pull request for any bugs or feature requests.

## Support

For support, please contact [support@geeklab.app](mailto:support@geeklab.app).