### Quick Start: Initialize and Track Events with Kromemo SDK
Source: https://www.npmjs.com/package/kromemo/v/2.0_activeTab=readme
A quick start guide for using the Kromemo SDK in JavaScript/TypeScript. It covers initialization with project and API keys, tracking views, custom events, and errors, along with an example of flushing pending events.
```javascript
import kromemo from 'kromemo'
kromemo.init({
projectId: 'pub_xxx',
apiKey: 'kro_abcdef...',
endpointBase: 'https://metrics.tu-dominio.com', // optional
// autoPageViews: true,
// autoErrors: true,
})
// View (you can pass name and/or url)
kromemo.trackView({ name: 'Home', url: '/home' })
// Custom event
kromemo.trackEvent({ name: 'clicked_buy', payload: { plan: 'pro' }, ts: Date.now() })
// Error
kromemo.trackError({ error: new Error('Boom'), payload: { area: 'checkout' } })
// Flush pending events (optional)
await kromemo.flush()
```
--------------------------------
### Install Kromemo SDK
Source: https://www.npmjs.com/package/kromemo/v/2.1_activeTab=readme
Instructions for installing the Kromemo SDK using npm, pnpm, or yarn. It also includes a UMD build example for direct script inclusion via CDN.
```bash
npm install kromemo
# or
pnpm add kromemo
# or
yarn add kromemo
```
```html
```
--------------------------------
### Quick Start: Initialize and Track Events with Kromemo SDK (JavaScript)
Source: https://www.npmjs.com/package/kromemo/v/2.0_activeTab=dependencies
A quick start guide for using the Kromemo SDK in JavaScript. It covers initialization with project and API keys, tracking views, custom events, and errors, as well as flushing pending events.
```javascript
import kromemo from 'kromemo'
kremo.init({
projectId: 'pub_xxx',
apiKey: 'kro_abcdef...',
endpointBase: 'https://metrics.tu-dominio.com', // optional
// autoPageViews: true,
// autoErrors: true,
})
// View (you can pass name and/or url)
kremo.trackView({ name: 'Home', url: '/home' })
// Custom event
kremo.trackEvent({ name: 'clicked_buy', payload: { plan: 'pro' }, ts: Date.now() })
// Error
kremo.trackError({ error: new Error('Boom'), payload: { area: 'checkout' } })
// Flush pending events (optional)
await kromemo.flush()
```
--------------------------------
### Example HTML Configuration for Projects Admin UI
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=dependencies
Shows how to configure the Kromemo Projects Admin UI by setting essential parameters directly in an HTML file. This includes the base URL of the metrics server, the API path for projects, and the authentication method (Bearer token or API Key).
```html
Open `examples/projects/index.html` directly in your browser and set:
* Base URL: e.g. `https://metrics.example.com`
* Projects path: e.g. `/api/projects`
* Auth: `Bearer` or `X-API-Key`
* Token/API Key
```
--------------------------------
### Initialization and Deduplication
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=dependencies
Configuration options for initializing the SDK, including deduplication settings.
```APIDOC
## Initialization with Deduplication
### Description
Initialize the Kromemo SDK with project details and configure client-side deduplication to prevent duplicate event submissions within a specified time window.
### Method
`kromemo.init({ projectId: string, apiKey: string, dedupeWindowMs?: number }): void`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
`init` (object) - Required. Initialization configuration.
- `projectId` (string) - Required. The project ID for your Kromemo project.
- `apiKey` (string) - Required. Your API key for authentication.
- `dedupeWindowMs` (number) - Optional. The time window in milliseconds during which duplicate events (same `type`, `name`, and `url`) will be dropped. Defaults to `0` (disabled).
### Request Example
```javascript
kromino.init({ projectId: 'pub_x', apiKey: 'kro_...', dedupeWindowMs: 800 })
```
### Response
No explicit response, method returns void.
```
--------------------------------
### Kromemo Initialization API
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=dependencies
Initializes the Kromemo SDK with project and API keys, and configures various tracking and batching options.
```APIDOC
## POST /api/init
### Description
Initializes the Kromemo SDK with project and API keys, and configures various tracking and batching options. This method must be called before any other tracking methods.
### Method
POST
### Endpoint
/api/init
### Parameters
#### Request Body
- **projectId** (string) - Required - Project/public identifier used to route events.
- **apiKey** (string) - Required - Secret API key sent via `X-API-Key`.
- **endpointBase** (string) - Optional - Origin for the ingest endpoint, e.g. `https://metrics.example.com`.
- **deviceId** (string) - Optional - If omitted, it is persisted in `localStorage`.
- **autoPageViews** (boolean) - Optional - Capture initial and SPA navigations. Defaults to `true`.
- **autoErrors** (boolean) - Optional - Capture `error` and `unhandledrejection`. Defaults to `true`.
- **maxBatchSize** (number) - Optional - Max events per request. Defaults to `100`.
- **maxQueueBytes** (number) - Optional - Max serialized bytes in memory queue. Defaults to `500000`.
- **flushIntervalMs** (number) - Optional - Automatic flush interval. Defaults to `5000`.
- **retryMaxAttempts** (number) - Optional - Max retry attempts on transient failures. Defaults to `3`.
- **os** (string) - Optional - Optional override for OS. If omitted, the SDK detects it automatically.
- **country** (string) - Optional - Optional country attached to each event. If omitted, the SDK will attempt a best-effort inference from the browser locale.
- **autoDetect** (object) - Optional - Control auto-detection of OS and country. Defaults to `{ os: true, country: true }`.
- **os** (boolean) - Optional - Enable/disable OS auto-detection.
- **country** (boolean) - Optional - Enable/disable country auto-detection.
- **dedupeWindowMs** (number) - Optional - Drop events with same type+name+url within this window (ms). Defaults to `0` (disabled).
### Request Example
```json
{
"projectId": "pub_xxx",
"apiKey": "kro_abcdef...",
"endpointBase": "https://metrics.tu-dominio.com",
"autoPageViews": true,
"autoErrors": true,
"maxBatchSize": 50,
"flushIntervalMs": 10000
}
```
### Response
#### Success Response (200)
- **deviceId** (string) - The unique identifier for the current device.
#### Response Example
```json
{
"deviceId": "generated-device-id-12345"
}
```
```
--------------------------------
### Quick Start: Initialize and Track Events with Kromemo SDK
Source: https://www.npmjs.com/package/kromemo/v/2.0
A quick start guide for integrating the Kromemo SDK in a JavaScript project. It covers initialization with various options, tracking page views, custom events, and errors, as well as flushing pending events.
```javascript
import kromemo from 'kromemo'
kromino.init({
projectId: 'pub_xxx',
apiKey: 'kro_abcdef...',
endpointBase: 'https://metrics.tu-dominio.com', // optional
// autoPageViews: true,
// autoErrors: true,
})
// View (you can pass name and/or url)
kromino.trackView({ name: 'Home', url: '/home' })
// Custom event
kromino.trackEvent({ name: 'clicked_buy', payload: { plan: 'pro' }, ts: Date.now() })
// Error
kromino.trackError({ error: new Error('Boom'), payload: { area: 'checkout' } })
// Flush pending events (optional)
await kromemo.flush()
```
--------------------------------
### Projects Admin UI Setup
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=readme
Instructions for setting up and using the Projects Admin UI.
```APIDOC
## Projects Admin UI Setup
### Description
This section provides instructions for setting up and using the bundled Projects Admin UI to interact with your server's REST API for project management.
### Setup
1. Open `examples/projects/index.html` directly in your browser.
2. Configure the following settings:
- **Base URL**: e.g., `https://metrics.example.com`
- **Projects path**: e.g., `/api/projects` (configurable)
- **Auth**: `Bearer` or `X-API-Key`
- **Token/API Key**: Your authentication token or API key.
### Features
- Test connection (using `GET /api/projects`)
- List projects (displays id/name and other fields)
- Create project (name, optional slug/description/allowedDomains)
### Notes
- CORS must allow `Content-Type`, `Authorization`, and/or `X-API-Key` as needed.
- The UI accepts array or `{ items: [...] }` responses for project lists.
- Adjust paths and request bodies in `examples/projects/main.js` if your API differs.
```
--------------------------------
### Initialize and Use Kromemo Browser SDK (JavaScript)
Source: https://www.npmjs.com/package/kromemo/index
Quick start guide for initializing the Kromemo SDK and tracking page views, custom events, and errors in a JavaScript application. Includes optional endpoint configuration.
```javascript
import kromemo from 'kromemo';
// Initialize the SDK
kromemo.init({
projectId: 'pub_xxx',
apiKey: 'kro_abcdef...',
endpointBase: 'https://metrics.your-domain.com', // Optional
});
// Track a page view
kromemo.trackView({ name: 'Home', url: '/home' });
// Track a custom event
kromemo.trackEvent({
name: 'clicked_buy',
payload: { plan: 'pro', value: 99 },
});
// Track an error
try {
throw new Error('Something went wrong');
} catch (err) {
kromemo.trackError({ error: err, payload: { context: 'checkout' } });
}
```
--------------------------------
### Install Kromemo Browser SDK
Source: https://www.npmjs.com/package/kromemo/index
Instructions for installing the Kromemo Browser SDK using various package managers.
```bash
npm install kromemo
# or
pnpm add kromemo
# or
yarn add kromemo
```
--------------------------------
### Projects Admin UI Configuration Example
Source: https://www.npmjs.com/package/kromemo/v/2.2
Example of how to configure the Projects Admin UI by setting base URL, projects path, and authentication details in `examples/projects/index.html`.
```html
* Base URL: e.g. `https://metrics.example.com`
* Projects path: e.g. `/api/projects`
* Auth: `Bearer` or `X-API-Key`
* Token/API Key
```
--------------------------------
### Kromemo SDK API: init Method Signature and Options
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=dependencies
Details the `init` method of the Kromemo Browser SDK, outlining its parameters, types, default values, and descriptions. This method is used to configure the SDK, setting up project IDs, API keys, and various tracking behaviors.
```typescript
init(options: {
projectId: string
apiKey: string
endpointBase?: string
deviceId?: string
autoPageViews?: boolean // default true
autoErrors?: boolean // default true
maxBatchSize?: number // default 100
maxQueueBytes?: number // default 500_000
flushIntervalMs?: number // default 5000
retryMaxAttempts?: number // default 3
os?: string
country?: string
autoDetect?: { os?: boolean; country?: boolean } // default true for each
dedupeWindowMs?: number // default 0 (disabled)
}): { deviceId: string }
```
--------------------------------
### Projects Admin UI Setup
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=code
Instructions on how to set up and use the Projects Admin UI, including required configuration and available features.
```APIDOC
## Projects Admin UI
### Description
This repo bundles a lightweight, build-less admin UI to list and create projects against your server’s REST API. It assumes you expose a `GET /api/projects` and `POST /api/projects` (configurable) that require either `Authorization: Bearer ` or `X-API-Key: `.
### Setup
1. Open `examples/projects/index.html` directly in your browser.
2. Configure the following settings:
* **Base URL**: e.g., `https://metrics.example.com`
* **Projects path**: e.g., `/api/projects`
* **Auth**: `Bearer` or `X-API-Key`
* **Token/API Key**: Your authentication token or API key.
### Features
* Test connection (via GET projects request).
* List projects (displays id/name and any public key fields if present).
* Create project (name, optional slug/description/allowedDomains).
### Notes
* CORS must allow `Content-Type`, `Authorization`, and/or `X-API-Key` as needed.
* Response shapes vary; the UI accepts arrays or `{ items: [...] }` responses.
* If your API differs, adjust the path and request body accordingly in `examples/projects/main.js`.
```
--------------------------------
### Projects Admin UI: Setup
Source: https://www.npmjs.com/package/kromemo/index_activeTab=dependencies
Instructions on how to set up and use the lightweight Projects Admin UI included in the repository. This involves opening an HTML file and configuring API credentials to manage projects.
```bash
1. Open `examples/projects/index.html` in your browser.
2. Configure your API endpoint and credentials.
3. Manage your projects directly.
```
--------------------------------
### Tracking API
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=dependencies
Methods for tracking user interactions and application errors.
```APIDOC
## trackView
### Description
Records a page view. If `url` is omitted, the current `location.href` is used. `input` is optional to allow for auto-capture of the initial view.
### Method
`trackView(input?: { name?: string, url?: string, payload?: Record }): void`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
`input` (object) - Optional. An object containing view details.
- `name` (string) - Optional. The name of the view.
- `url` (string) - Optional. The URL of the view. Defaults to `location.href`.
- `payload` (Record) - Optional. Additional data to associate with the view.
### Request Example
```javascript
kromino.trackView({ name: 'Pricing', url: '/pricing' })
```
### Response
No explicit response, method returns void.
```
```APIDOC
## trackError
### Description
Records an error that occurred in the application.
### Method
`trackError(input: { error: Error | string, payload?: Record }): void`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
`input` (object) - Required. An object containing error details.
- `error` (Error | string) - Required. The error object or a string representation of the error.
- `payload` (Record) - Optional. Additional data to associate with the error.
### Request Example
```javascript
kromino.trackError({ error: new Error('Boom'), payload: { area: 'checkout' } })
```
### Response
No explicit response, method returns void.
```
--------------------------------
### Projects Admin UI
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=dependencies
Information about the bundled Projects Admin UI for managing projects via a REST API.
```APIDOC
## Projects Admin UI
### Description
This repository includes a lightweight, build-less admin UI that interacts with your server's REST API to list and create projects. It requires the server to expose `GET /api/projects` and `POST /api/projects` endpoints.
### Usage
1. Open `examples/projects/index.html` in your browser.
2. Configure the following settings:
- **Base URL**: The base URL of your metrics server (e.g., `https://metrics.example.com`).
- **Projects Path**: The specific path for project-related API calls (e.g., `/api/projects`).
- **Auth**: The authentication method (`Bearer` or `X-API-Key`).
- **Token/API Key**: Your authentication token or API key.
### Features
- **Test Connection**: Verify connectivity by making a `GET` request to the projects endpoint.
- **List Projects**: Display a list of projects, including their ID, name, and any available public key fields.
- **Create Project**: Create new projects with options for name, slug, description, and allowed domains.
### Notes
- Ensure your CORS configuration allows `Content-Type`, `Authorization`, and/or `X-API-Key` as required by your API.
- The UI is flexible and can handle response shapes that are arrays or objects with an `items` field.
- Adjust the path and request body in `examples/projects/main.js` if your API deviates from the expected structure.
```
--------------------------------
### Projects Admin UI Configuration Example
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=versions
This example demonstrates how to configure the Projects Admin UI by setting essential parameters like the Base URL, Projects path, and authentication method (Bearer token or API Key). These settings are crucial for connecting the UI to your project's API.
```javascript
Base URL: e.g. https://metrics.example.com
Projects path: e.g. /api/projects
Auth: Bearer or X-API-Key
Token/API Key
```
--------------------------------
### HTTP Contract
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=dependencies
Defines the structure of requests sent to the Kromemo events endpoint and the expected responses.
```APIDOC
## HTTP Contract
### Method
`POST`
### Endpoint
`https://host/{projectId}/events`
### Headers
```
Content-Type: application/json
X-API-Key: kro_...
```
### Request Body Example
```json
{
"events": [
{
"name": "clicked_buy",
"type": "event",
"ts": 1730394050000,
"device_id": "dev_123",
"url": "https://app/page",
"referrer": "https://google.com",
"os": "iOS",
"payload": { "plan": "pro" }
}
]
}
```
### Response (200 OK)
```json
{ "ok": true, "eventCount": 1, "registeredCount": 1 }
```
```
--------------------------------
### Initialize SDK with Deduplication
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=readme
Example of initializing the Kromemo SDK with deduplication enabled.
```APIDOC
## Initialize SDK
### Description
This example shows how to initialize the Kromemo SDK, including the `dedupeWindowMs` option for client-side event deduplication.
### Method
`kromemo.init`
### Parameters
- **projectId** (string) - Required - Your project ID.
- **apiKey** (string) - Required - Your API key.
- **dedupeWindowMs** (number) - Optional - The time window in milliseconds to deduplicate events. Set to `0` to disable (default).
### Request Example
```javascript
kromemo.init({ projectId: 'pub_x', apiKey: 'kro_...', dedupeWindowMs: 800 })
```
```
--------------------------------
### Initialize and Track Events with Kromemo SDK (JavaScript)
Source: https://www.npmjs.com/package/kromemo/index_activeTab=dependents
A quick start guide showing how to initialize the Kromemo SDK with project details and track page views, custom events, and errors using the JavaScript API.
```javascript
import kromemo from 'kromemo';
// Initialize the SDK
kromino.init({
projectId: 'pub_xxx',
apiKey: 'kro_abcdef...',
endpointBase: 'https://metrics.your-domain.com', // Optional
});
// Track a page view
kromino.trackView({ name: 'Home', url: '/home' });
// Track a custom event
kromino.trackEvent({
name: 'clicked_buy',
payload: { plan: 'pro', value: 99 },
});
// Track an error
try {
throw new Error('Something went wrong');
} catch (err) {
kromemo.trackError({ error: err, payload: { context: 'checkout' } });
}
```
--------------------------------
### Install Kromemo via npm
Source: https://www.npmjs.com/package/kromemo/v/1.0_activeTab=readme
Installs the Kromemo package using npm. This command downloads and installs version 1.0.0 of the kromemo package into your project's node_modules directory.
```bash
npm i kromemo@1.0.0
```
--------------------------------
### Install Kromemo Package (npm)
Source: https://www.npmjs.com/package/kromemo/v/2.1_activeTab=code
Command to install version 2.1.0 of the kromemo NPM package using npm.
```bash
npm i kromemo@2.1.0
```
--------------------------------
### npm Installation Command
Source: https://www.npmjs.com/package/kromemo/v/2.0
Command to install the kromemo npm package version 2.0.0 using npm.
```bash
npm i kromemo@2.0.0
```
--------------------------------
### Install Kromemo with npm, pnpm, or yarn
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=readme
Instructions for installing the Kromemo package using popular Node.js package managers. This is the primary method for integrating the SDK into a project.
```bash
npm install kromemo
```
```bash
pnpm add kromemo
```
```bash
yarn add kromemo
```
--------------------------------
### Kromemo Admin UI Configuration Example
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=dependents
Configuration settings for the Kromemo Projects Admin UI, which can be set directly in `examples/projects/index.html`. These include the base URL of the metrics server, the API path for projects, and authentication details (type and token/key).
```html
```
--------------------------------
### Kromemo HTTP Response Example (200)
Source: https://www.npmjs.com/package/kromemo/v/2.2
Example of a successful response (HTTP 200) from the Kromemo server after events are processed.
```json
{ "ok": true, "eventCount": 1, "registeredCount": 1 }
```
--------------------------------
### Install Kromemo Package
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=code
Command to install the Kromemo package version 2.2.0 using npm. This is the primary method for integrating the SDK into a JavaScript project.
```bash
npm i kromemo@2.2.0
```
--------------------------------
### HTTP Response Example (200 OK)
Source: https://www.npmjs.com/package/kromemo/v/2.0
Example of a successful HTTP response (200 OK) from the events endpoint. It confirms the operation's success and provides counts of events processed and registered.
```json
{ "ok": true, "eventCount": 1, "registeredCount": 1 }
```
--------------------------------
### Kromemo Flush API
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=dependencies
Manually flushes any pending events in the queue.
```APIDOC
## POST /api/flush
### Description
Manually flushes any pending events in the queue. This is an asynchronous operation.
### Method
POST
### Endpoint
/api/flush
### Parameters
(No parameters required)
### Request Example
(No request body required)
### Response
#### Success Response (200)
This endpoint does not return a specific success response body, indicating the flush operation was initiated.
#### Response Example
(No specific response body for success)
```
--------------------------------
### Kromemo Track Error API
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=dependencies
Tracks an error event with an optional payload.
```APIDOC
## POST /api/trackError
### Description
Tracks an error event with an optional payload. This method can be called after `init`.
### Method
POST
### Endpoint
/api/trackError
### Parameters
#### Request Body
- **error** (Error object) - Required - The error object to track.
- **payload** (object) - Optional - Additional details about the error.
### Request Example
```json
{
"error": {
"message": "Boom",
"stack": "Error: Boom\n at ..."
},
"payload": {
"area": "checkout"
}
}
```
### Response
#### Success Response (200)
This endpoint does not return a specific success response body, indicating the event was accepted.
#### Response Example
(No specific response body for success)
```
--------------------------------
### Kromemo Shutdown API
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=dependencies
Shuts down the SDK, flushes any remaining events, and cleans up resources.
```APIDOC
## POST /api/shutdown
### Description
Shuts down the SDK, flushes any remaining events, and cleans up resources. This method should be called when the user is leaving the page or the application is closing.
### Method
POST
### Endpoint
/api/shutdown
### Parameters
(No parameters required)
### Request Example
(No request body required)
### Response
#### Success Response (200)
This endpoint does not return a specific success response body, indicating the shutdown operation was initiated.
#### Response Example
(No specific response body for success)
```
--------------------------------
### Kromemo Track Event API
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=dependencies
Tracks a custom event with an optional payload and timestamp.
```APIDOC
## POST /api/trackEvent
### Description
Tracks a custom event with an optional payload and timestamp. This method can be called after `init`.
### Method
POST
### Endpoint
/api/trackEvent
### Parameters
#### Request Body
- **name** (string) - Required - The name of the event.
- **payload** (object) - Optional - A record of key-value pairs to send with the event.
- **ts** (number | string) - Optional - The timestamp of the event in milliseconds or a string representation.
### Request Example
```json
{
"name": "signed_up",
"payload": {
"plan": "pro",
"userId": "user-123"
},
"ts": 1678886400000
}
```
### Response
#### Success Response (200)
This endpoint does not return a specific success response body, indicating the event was accepted.
#### Response Example
(No specific response body for success)
```
--------------------------------
### Kromemo Initialization API
Source: https://www.npmjs.com/package/kromemo/v/2.1_activeTab=readme
Initializes the Kromemo SDK with project and API keys, and configures various tracking and batching options.
```APIDOC
## init
### Description
Initializes the Kromemo SDK. This function must be called before any other SDK functions. It configures the SDK with essential project details and allows customization of tracking behavior and batching.
### Method
`init(options)`
### Parameters
#### Request Body
- **projectId** (string) - Required - Project/public identifier used to route events.
- **apiKey** (string) - Required - Secret API key sent via `X-API-Key`.
- **endpointBase** (string) - Optional - Origin for the ingest endpoint, e.g. `https://metrics.example.com`.
- **deviceId** (string) - Optional - If omitted, it is persisted in `localStorage`.
- **autoPageViews** (boolean) - Optional - Default: `true`. Capture initial and SPA navigations.
- **autoErrors** (boolean) - Optional - Default: `true`. Capture `error` and `unhandledrejection`.
- **maxBatchSize** (number) - Optional - Default: `100`. Max events per request.
- **maxQueueBytes** (number) - Optional - Default: `500000`. Max serialized bytes in memory queue.
- **flushIntervalMs** (number) - Optional - Default: `5000`. Automatic flush interval.
- **retryMaxAttempts** (number) - Optional - Default: `3`. Max retry attempts on transient failures.
- **os** (string) - Optional - Optional OS string attached to each event.
- **country** (string) - Optional - Optional country string attached to each event.
- **dedupeWindowMs** (number) - Optional - Default: `0` (disabled). Drop events with same type+name+url within this window (ms).
### Response
#### Success Response (void)
Returns an object containing the `deviceId` used for tracking.
### Request Example
```javascript
window.kromemo.init({
projectId: 'pub_xxx',
apiKey: 'kro_abcdef',
endpointBase: 'https://metrics.tu-dominio.com',
autoPageViews: true,
autoErrors: true,
maxBatchSize: 50,
flushIntervalMs: 10000
});
```
### Response Example
```json
{
"deviceId": "generated-device-id"
}
```
```
--------------------------------
### Kromemo Track View API
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=dependencies
Tracks a page view event, optionally with a name and URL.
```APIDOC
## POST /api/trackView
### Description
Tracks a page view event, optionally with a name and URL. This method can be called after `init`.
### Method
POST
### Endpoint
/api/trackView
### Parameters
#### Request Body
- **name** (string) - Optional - The name of the page view.
- **url** (string) - Optional - The URL of the page view.
### Request Example
```json
{
"name": "HomePage",
"url": "/"
}
```
### Response
#### Success Response (200)
This endpoint does not return a specific success response body, indicating the event was accepted.
#### Response Example
(No specific response body for success)
```
--------------------------------
### Kromemo SDK Initialization
Source: https://www.npmjs.com/package/kromemo/v/1.0_activeTab=dependencies
Initializes the Kromemo SDK with project and API keys, and optional configuration for endpoint, device ID, auto-capture, batching, and flushing.
```APIDOC
## `init` Function
### Description
Initializes the Kromemo SDK. Persists `device_id` in localStorage (`kro:device_id`) with a cookie fallback (`kro_device_id`).
### Method
`kromemo.init(options)`
### Parameters
#### Options Object
- **projectId** (string) - Required - Your Kromemo project ID.
- **apiKey** (string) - Required - Your Kromemo API key.
- **endpointBase** (string) - Optional - The base URL for your Kromemo server endpoint.
- **deviceId** (string) - Optional - A custom device ID to use.
- **autoPageViews** (boolean) - Optional - Automatically track page views. Defaults to `true`.
- **autoErrors** (boolean) - Optional - Automatically track errors. Defaults to `true`.
- **maxBatchSize** (number) - Optional - The maximum number of events in a batch. Defaults to `100`.
- **flushIntervalMs** (number) - Optional - The interval in milliseconds to flush events. Defaults to `5000`.
- **maxQueueBytes** (number) - Optional - The maximum size in bytes for the event queue. Defaults to `500000`.
### Returns
- `{ deviceId: string }` - An object containing the device ID.
### Example
```javascript
import kromemo from 'kromemo';
kromemo.init({
projectId: 'pub_xxx',
apiKey: 'kro_abcdef...',
endpointBase: 'https://metrics.tu-dominio.com',
});
```
```
--------------------------------
### Queue Management API
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=dependencies
Methods for controlling the event queue, including flushing pending events and shutting down the SDK.
```APIDOC
## flush
### Description
Forces the SDK to send any pending events in the queue immediately.
### Method
`flush(): Promise`
### Parameters
None
### Response
- `Promise`: A promise that resolves when all pending events have been sent.
```
```APIDOC
## shutdown
### Description
Detaches auto-capture hooks and stops the event queue. This method prefers using `navigator.sendBeacon` for small payloads and falls back to `fetch` with `keepalive: true` for larger payloads or when `sendBeacon` is unavailable, ensuring custom headers are sent.
### Method
`shutdown(): void`
### Parameters
None
### Response
No explicit response, method returns void.
```
--------------------------------
### Initialization
Source: https://www.npmjs.com/package/kromemo/v/3.0_activeTab=readme
Initializes the Kromemo SDK with project and API credentials. This must be called before tracking any events.
```APIDOC
## POST /websites/npmjs_package_kromemo/init
### Description
Initializes the SDK with project and API credentials. This must be called before tracking any events.
### Method
POST
### Endpoint
/websites/npmjs_package_kromemo/init
### Parameters
#### Query Parameters
- **projectId** (string) - Required - Your project's public identifier.
- **apiKey** (string) - Required - Public API key sent via `x-api-ingest-key`.
- **endpointBase** (string) - Optional - Base URL for the ingest endpoint.
- **maxBatchSize** (number) - Optional - Maximum number of events per batch. Default: 100.
- **maxQueueBytes** (number) - Optional - Maximum size of the memory queue in bytes. Default: 500,000.
- **flushIntervalMs** (number) - Optional - Interval in milliseconds to flush the queue. Default: 5000.
- **retryMaxAttempts** (number) - Optional - Maximum retry attempts for transient errors. Default: 3.
- **dedupeWindowMs** (number) - Optional - Time window (ms) to drop duplicate events (same type/name/url). Default: 0.
### Response
#### Success Response (200)
- **deviceId** (string) - The unique device identifier generated by the SDK.
#### Response Example
```json
{
"deviceId": "generated_uuid"
}
```
```
--------------------------------
### Initialization API
Source: https://www.npmjs.com/package/kromemo/v/3.0_activeTab=dependencies
Initializes the Kromemo SDK with project and API credentials. This must be called before tracking any events.
```APIDOC
## `init(options)`
### Description
Initializes the SDK. Must be called before tracking any events.
### Method
`init`
### Parameters
#### Options
- **projectId** (string) - Required - Your project's public identifier.
- **apiKey** (string) - Required - Public API key sent via `x-api-ingest-key`.
- **endpointBase** (string) - Optional - Base URL for the ingest endpoint.
- **maxBatchSize** (number) - Optional - Maximum number of events per batch. Default: `100`.
- **maxQueueBytes** (number) - Optional - Maximum size of the memory queue in bytes. Default: `500,000`.
- **flushIntervalMs** (number) - Optional - Interval in milliseconds to flush the queue. Default: `5000`.
- **retryMaxAttempts** (number) - Optional - Maximum retry attempts for transient errors. Default: `3`.
- **dedupeWindowMs** (number) - Optional - Time window (ms) to drop duplicate events (same type/name/url). Default: `0`.
### Returns
- **deviceId** (string) - The unique device ID generated for this session.
```
--------------------------------
### Kromemo Initialization API
Source: https://www.npmjs.com/package/kromemo/v/2.2
Initializes the Kromemo SDK with project and API keys, and various configuration options for event tracking and batching.
```APIDOC
## init
### Description
Initializes the Kromemo SDK with project and API keys, and various configuration options for event tracking and batching.
### Method
```
init(options: {
projectId: string
apiKey: string
endpointBase?: string
deviceId?: string
autoPageViews?: boolean // default true
autoErrors?: boolean // default true
maxBatchSize?: number // default 100
maxQueueBytes?: number // default 500_000
flushIntervalMs?: number // default 5000
retryMaxAttempts?: number // default 3
os?: string
country?: string
autoDetect?: { os?: boolean; country?: boolean } // default true for each
dedupeWindowMs?: number // default 0 (disabled)
}): { deviceId: string }
```
### Parameters
#### Request Body
- **projectId** (string) - Required - Project/public identifier used to route events.
- **apiKey** (string) - Required - Secret API key sent via `X-API-Key`.
- **endpointBase** (string) - Optional - Origin for the ingest endpoint, e.g. `https://metrics.example.com`.
- **deviceId** (string) - Optional - If omitted, it is persisted in `localStorage`.
- **autoPageViews** (boolean) - Optional - Capture initial and SPA navigations. Defaults to `true`.
- **autoErrors** (boolean) - Optional - Capture `error` and `unhandledrejection`. Defaults to `true`.
- **maxBatchSize** (number) - Optional - Max events per request. Defaults to `100`.
- **maxQueueBytes** (number) - Optional - Max serialized bytes in memory queue. Defaults to `500000`.
- **flushIntervalMs** (number) - Optional - Automatic flush interval. Defaults to `5000`.
- **retryMaxAttempts** (number) - Optional - Max retry attempts on transient failures. Defaults to `3`.
- **os** (string) - Optional - Optional override for OS. If omitted, the SDK detects it automatically.
- **country** (string) - Optional - Optional country attached to each event. If omitted, the SDK will attempt to infer it from the browser locale.
- **autoDetect** (object) - Optional - Control auto-detection of OS and country. `{ os?: boolean; country?: boolean }`. Defaults to `true` for each.
- **dedupeWindowMs** (number) - Optional - Drop events with same type+name+url within this window (ms). Defaults to `0` (disabled).
### Response
#### Success Response (200)
- **deviceId** (string) - The unique identifier for the device.
### Request Example
```json
{
"projectId": "pub_xxx",
"apiKey": "kro_abcdef...",
"endpointBase": "https://metrics.tu-dominio.com",
"autoPageViews": true,
"autoErrors": true,
"maxBatchSize": 100,
"maxQueueBytes": 500000,
"flushIntervalMs": 5000,
"retryMaxAttempts": 3,
"os": "Windows",
"country": "US",
"autoDetect": {
"os": true,
"country": true
},
"dedupeWindowMs": 0
}
```
### Response Example
```json
{
"deviceId": "generated-device-id-123"
}
```
```
--------------------------------
### Kromemo Initialization API
Source: https://www.npmjs.com/package/kromemo/v/2.1_activeTab=code
Initializes the Kromemo SDK with project and API credentials, and configures various tracking and batching options.
```APIDOC
## init
### Description
Initializes the Kromemo SDK. This method must be called before any other SDK methods. It configures the SDK with necessary credentials and optional settings for event tracking, batching, and retries.
### Method
`init(options)`
### Parameters
#### Request Body
- **projectId** (string) - Required - Project/public identifier used to route events.
- **apiKey** (string) - Required - Secret API key sent via `X-API-Key` header.
- **endpointBase** (string) - Optional - Origin for the ingest endpoint, e.g. `https://metrics.example.com`.
- **deviceId** (string) - Optional - If omitted, it is persisted in `localStorage`.
- **autoPageViews** (boolean) - Optional - Default: `true`. Capture initial and SPA navigations.
- **autoErrors** (boolean) - Optional - Default: `true`. Capture `error` and `unhandledrejection` events.
- **maxBatchSize** (number) - Optional - Default: `100`. Maximum number of events per request.
- **maxQueueBytes** (number) - Optional - Default: `500000`. Maximum serialized bytes in the in-memory queue.
- **flushIntervalMs** (number) - Optional - Default: `5000`. Automatic flush interval in milliseconds.
- **retryMaxAttempts** (number) - Optional - Default: `3`. Maximum retry attempts on transient failures.
- **os** (string) - Optional - Optional OS string attached to each event.
- **country** (string) - Optional - Optional country string attached to each event.
- **dedupeWindowMs** (number) - Optional - Default: `0` (disabled). Drop events with the same type, name, and URL within this window in milliseconds.
### Returns
- **deviceId** (string) - The unique identifier for the device.
### Request Example
```javascript
kromemo.init({
projectId: 'pub_xxx',
apiKey: 'kro_abcdef...',
endpointBase: 'https://metrics.tu-dominio.com',
autoPageViews: true,
autoErrors: true,
maxBatchSize: 50,
flushIntervalMs: 10000
})
```
```
--------------------------------
### API Initialization
Source: https://www.npmjs.com/package/kromemo/v/2.2_activeTab=versions
Initializes the Kromemo SDK with project and API keys, and other configuration options.
```APIDOC
## POST /api/init
### Description
Initializes the Kromemo SDK with project and API keys, and other configuration options.
### Method
POST
### Endpoint
/api/init
### Parameters
#### Request Body
- **projectId** (string) - Required - Project/public identifier used to route events
- **apiKey** (string) - Required - Secret API key sent via `X-API-Key`
- **endpointBase** (string) - Optional - Origin for the ingest endpoint, e.g. `https://metrics.example.com`
- **deviceId** (string) - Optional - If omitted, it is persisted in `localStorage`
- **autoPageViews** (boolean) - Optional - Capture initial and SPA navigations (default: true)
- **autoErrors** (boolean) - Optional - Capture `error` and `unhandledrejection` (default: true)
- **maxBatchSize** (number) - Optional - Max events per request (default: 100)
- **maxQueueBytes** (number) - Optional - Max serialized bytes in memory queue (default: 500000)
- **flushIntervalMs** (number) - Optional - Automatic flush interval (default: 5000)
- **retryMaxAttempts** (number) - Optional - Max retry attempts on transient failures (default: 3)
- **os** (string) - Optional - Optional override for OS
- **country** (string) - Optional - Optional country attached to each event
- **autoDetect** (object) - Optional - Control auto-detection for OS and country (default: `{ os: true, country: true }`)
- **dedupeWindowMs** (number) - Optional - Drop events with same type+name+url within this window (ms) (default: 0)
### Request Example
```json
{
"projectId": "pub_xxx",
"apiKey": "kro_abcdef...",
"endpointBase": "https://metrics.tu-dominio.com",
"autoPageViews": true,
"autoErrors": true,
"maxBatchSize": 100,
"maxQueueBytes": 500000,
"flushIntervalMs": 5000,
"retryMaxAttempts": 3,
"os": "Windows",
"country": "US",
"autoDetect": {
"os": true,
"country": false
},
"dedupeWindowMs": 5000
}
```
### Response
#### Success Response (200)
- **deviceId** (string) - The generated or retrieved device ID.
#### Response Example
```json
{
"deviceId": "generated-device-id"
}
```
```
--------------------------------
### Kromemo SDK Initialization API
Source: https://www.npmjs.com/package/kromemo/v/2.1_activeTab=dependencies
Initializes the Kromemo SDK with project and API keys, and configures various tracking and batching options.
```APIDOC
## init
### Description
Initializes the Kromemo SDK with the provided options. This function must be called before any other SDK functions.
### Method
`init`
### Parameters
#### Options Object
- **projectId** (string) - Required - Project/public identifier used to route events.
- **apiKey** (string) - Required - Secret API key sent via `X-API-Key`.
- **endpointBase** (string) - Optional - Origin for the ingest endpoint, e.g. `https://metrics.example.com`.
- **deviceId** (string) - Optional - If omitted, it is persisted in `localStorage`.
- **autoPageViews** (boolean) - Optional - Default: `true`. Capture initial and SPA navigations.
- **autoErrors** (boolean) - Optional - Default: `true`. Capture `error` and `unhandledrejection`.
- **maxBatchSize** (number) - Optional - Default: `100`. Max events per request.
- **maxQueueBytes** (number) - Optional - Default: `500000`. Max serialized bytes in memory queue.
- **flushIntervalMs** (number) - Optional - Default: `5000`. Automatic flush interval.
- **retryMaxAttempts** (number) - Optional - Default: `3`. Max retry attempts on transient failures.
- **os** (string) - Optional - Optional OS string attached to each event.
- **country** (string) - Optional - Optional country string attached to each event.
- **dedupeWindowMs** (number) - Optional - Default: `0` (disabled). Drop events with same type+name+url within this window (ms).
### Returns
- **{ deviceId: string }** - An object containing the deviceId used for tracking.
```