Configuration
The SDK is configured through a single immutable B2MetricConfig object passed to init(). All configuration is applied once at initialization and cannot be changed afterwards without restarting the SDK. This design keeps the runtime behavior predictable: once the SDK is running, every event you log is processed with the same batching, retry, and session rules.
Only apiKey is required — every other field has a sensible default tuned for typical mobile workloads. You can adopt the SDK with a one-line config in development and tighten the parameters later as you measure event volume and network conditions in production. Any numeric value you supply that falls outside the documented range is silently clamped to the nearest valid value; the SDK never throws because of a bad config value.
await B2Metric.instance.init(
const B2MetricConfig(
apiKey: 'YOUR_API_KEY',
batchSize: 20,
flushIntervalSeconds: 30,
sessionTimeoutMinutes: 30,
logLevel: LogLevel.debug,
),
);
Configuration Options
The table below lists every configuration field, its type, whether it is required, the default value, the accepted range, and a short description of its purpose.
| Parameter | Type | Required | Default | Range | Description |
|---|---|---|---|---|---|
apiKey | String | Yes | — | — | Your B2Metric API key |
baseUrl | String | No | https://tracker.b2metric.com | — | API endpoint URL |
batchSize | int | No | 20 | 1–100 | Events per batch before sending |
flushIntervalSeconds | int | No | 30 | 1–3600 | Seconds between automatic flushes |
maxRetries | int | No | 3 | 1–10 | Retry attempts for failed requests |
sessionTimeoutMinutes | int | No | 30 | 1–10080 | Inactivity before a new session starts |
maxQueueSize | int | No | 1000 | 100–10000 | Maximum events held in queue |
logLevel | LogLevel | No | LogLevel.off | off · error · warning · info · debug | Console log verbosity |
Choosing the Right Values
The defaults work well for most applications. If you are running a high-volume app (more than a few events per second per user), consider lowering flushIntervalSeconds to deliver data faster, or raising batchSize to amortize the cost of each network request across more events. For low-volume apps, the defaults already minimize battery and bandwidth usage.
During development, set logLevel to LogLevel.debug so you can watch events flow through the SDK in your IDE console. Before shipping to production, switch back to LogLevel.off or LogLevel.error to keep the console clean and avoid leaking event payloads in logs.