API Reference
Audiencelab React SDK API reference
API Reference
initializeAudiencelab(apiKey: string): Promise<{ token: string, metrics: any }>
Initializes the Audiencelab SDK with your API key.
| Parameter | Type | Description |
|---|---|---|
apiKey | string | Your API key for the Geeklab Audiencelab service |
Returns a Promise that resolves to an object containing:
token: the generated session tokenmetrics: initial metrics data
sendCustomPurchaseEvent(id: string, name: string, value: number, currency: string, status: string, tr_id?: string): Promise<any>
Sends a custom purchase event.
| Parameter | Type | Description |
|---|---|---|
id | string | The ID of the purchased item |
name | string | The name of the purchased item |
value | number | The value of the purchase |
currency | string | The currency code (e.g., "USD") |
status | string | The status of the purchase ("completed", "success", "failed") |
tr_id | string | Optional transaction ID for the purchase |
Returns a Promise that resolves when the event is sent.
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. Automatically tracks and includes total_ad_value (cumulative sum of all ad values) in the event payload.
| Parameter | Type | Description |
|---|---|---|
adId | string | The ID of the ad |
name | string | The name of the ad |
source | string | The source of the ad |
watchTime | number | Watch time in seconds |
reward | boolean | Whether the ad was rewarded |
mediaSource | string | The media source (e.g., "admob") |
channel | string | The channel (e.g., "paid") |
value | number | Value associated with the ad |
currency | string | Currency code (e.g., "USD") |
Returns a Promise that resolves when the event is sent.
The event payload automatically includes total_ad_value, representing the cumulative total of all ad values since app install. This value is stored using localStorage and persists across sessions.
sendCustomPurchaseEvent(id: string, name: string, value: number, currency: string, status: string, tr_id?: string): Promise<any>
Sends a custom purchase event. Automatically tracks and includes total_purchase_value (cumulative sum of all purchase values) in the event payload, but only increments when status is "completed" or "success".
| Parameter | Type | Description |
|---|---|---|
id | string | The ID of the purchased item |
name | string | The name of the purchased item |
value | number | The value of the purchase |
currency | string | The currency code (e.g., "USD") |
status | string | The status of the purchase ("completed", "success", "failed") |
tr_id | string | Optional transaction ID for the purchase |
Returns a Promise that resolves when the event is sent.
The event payload automatically includes total_purchase_value, representing the cumulative total of all purchase values since app install (only for completed/successful purchases). This value is stored using localStorage and persists across sessions.
sendCustomEvent(eventName: string, params: { value?: string; id?: string; [key: string]: string }): Promise<any>
Sends a custom event for tracking any user action or game event.
| Parameter | Type | Description |
|---|---|---|
eventName | string | A unique key or name that identifies this custom event (e.g., 'level_complete') |
params | object | An object containing additional parameters for the event |
The params object can include:
value(optional): The main value associated with the event (e.g., score, amount, outcome)id(optional): A unique identifier for the event, used for idempotency- Additional key-value pairs (optional, maximum of 2 allowed)
Returns a Promise that resolves when the event is sent.
getTotalAdValue(): Promise<number>
Retrieves the current cumulative ad value for the user.
Returns a Promise that resolves to a number representing the total value of all ads viewed by the user since app install.
getTotalPurchaseValue(): Promise<number>
Retrieves the current cumulative purchase value for the user.
Returns a Promise that resolves to a number representing the total value of all purchases made by the user since app install (only includes completed/successful purchases).