Developer

Analytics for CLI apps

Tracking events for CLI with OpenTelemetry and Azure App Insights

Installation

dart pub add cli_analytics -u https://gitea.whitelabel.mobile.embedit.dev/api/packages/platform/pub/

!IMPORTANT You need access token for fetching from private pub repository. ELI add token automatically

Usage


final applicationInsightsKey =
    String.fromEnvironment('instrumentationKey', defaultValue: 'xyzx');

Future<void> main() async {
  Logger.root.level = Level.ALL; // defaults to Level.INFO
  Logger.root.onRecord.listen((record) {
    stdout.writeln('${record.level.name}: ${record.time}: ${record.message}');
  });
  final analytics = AnalyticsCLI(AnalyticsConfig(
    uid: 'test',
    version: '1.0.0-dev.0',
    instrumentationKey: applicationInsightsKey,
  ));
  analytics.trackCommand('run', 'test', {'test': 'test'});
  analytics.trackCommand('help', 'test', {'test': 'test'});
  analytics.trackCommand('usage', 'test', {'test': 'test'});
  analytics.trackCommand('runTemplate', 'test', {'test': 'test'});
}

Copyright © 2025. All rights reserved.