Troubleshooting Guide topic
Troubleshooting Guide
Common issues and solutions when using analytics_gen.
CLI Errors
AnalyticsParseException: Domain name "..." is invalid
Cause: The top-level key in your YAML file does not match the configured naming strategy (default: snake_case).
Fix: Rename the key in YAML or checking analytics_gen.yaml:
# Correct (snake_case)
user_profile:
events: ...
AnalyticsParseException: Parameter "..." is defined in event "..." but requires central definition
Cause: rules: enforce_centrally_defined_parameters: true is enabled.
Fix: Move the parameter definition to a file listed in shared_parameters or disable the rule.
Exit code 255 or Stack Overflow
Cause: Extremely deep YAML nesting, malformed YAML, or very large single files.
Fix: Split domains into multiple files and keep structures shallow (domains → events → parameters). Re-run with --verbose to capture the failing file/line.
Generated Code Issues
The method 'log...' isn't defined for the type 'Analytics'
Cause:
- You haven't run the generator:
dart run analytics_gen:generate - You're importing the wrong
Analyticstype (the package exports runtime helpers, not your app's generatedAnalyticsclass). - You generated to a different output directory than you are importing. Fix:
- Run generation and ensure it writes code (
--no-codedisables code output):
dart run analytics_gen:generate --docs --exports
- Import the generated file from your project output (example path):
import 'package:your_app/src/analytics/generated/analytics.dart';
- Verify
analytics_gen.outputs.dartinanalytics_gen.yamlmatches your import.
Analytics.initialize(...) must be called before logging events
Cause: You are using the singleton API without initialization.
Fix: Call Analytics.initialize(yourProvider) once during bootstrap (and Analytics.reset() in tests).
Syntax Error: Expected to find ')'
Cause: Rarely, complex regex strings or unescaped quotes in descriptions can break generation.
Fix: Ensure quotes in YAML descriptions are escaped or use block strings (|).
description: |
User's "display" name.
IDE / Editor Issues
Analysis Errors in Generated Files
Cause: analyzer hasn't refreshed the file system.
Fix:
- Run
dart analyze. - Restart Dart Analysis Server in your IDE.
Getting Help
If you encounter a bug:
- Run with
--verboseto get full stack traces. - Open an issue on GitHub with the verbose output and the reproduction YAML.
Libraries
- analytics_gen Project Overview Getting Started Schema Reference Validation & Naming Naming & Configuration Analytics Capabilities Performance Guide Testing Guide Migration Guides Scalability & Performance Code Review Troubleshooting Guide Prompt Guide API Reference
- Analytics Gen - Type-safe analytics event tracking with code generation.