Skip to main content

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.

ParameterTypeRequiredDefaultRangeDescription
apiKeyStringYesYour B2Metric API key
baseUrlStringNohttps://tracker.b2metric.comAPI endpoint URL
batchSizeintNo201–100Events per batch before sending
flushIntervalSecondsintNo301–3600Seconds between automatic flushes
maxRetriesintNo31–10Retry attempts for failed requests
sessionTimeoutMinutesintNo301–10080Inactivity before a new session starts
maxQueueSizeintNo1000100–10000Maximum events held in queue
logLevelLogLevelNoLogLevel.offoff · error · warning · info · debugConsole 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.