This error occurs when you try to log a Firebase Analytics event with an invalid event name. Firebase enforces strict naming rules to maintain data quality and consistency across your analytics.
Firebase Analytics validates event names when they are logged to your analytics collection. Code 2 is a validation error that means the event name you provided doesn't meet Firebase's naming requirements. This validation happens at the client SDK level before the event is sent to Firebase servers. The error prevents malformed events from entering your analytics data, which protects the integrity of your analytics reports and dashboards. Firebase reserves certain event names for system events and enforces character restrictions to avoid conflicts with other analytics platforms and data processing pipelines.
Check that your event name follows Firebase's naming requirements:
- Must start with an alphabetic character (a-z or A-Z)
- Can only contain alphanumeric characters and underscores
- Must be 1-40 characters long
- Cannot start with firebase_, google_, or ga_ prefixes
Example of valid event names:
user_signup
button_click
purchase_complete
form_submission
page_viewExample of INVALID event names:
1_user_signup // Starts with number
_user_signup // Starts with underscore
user-signup // Contains hyphen
user signup // Contains space
user.signup // Contains period
firebase_custom_event // Starts with reserved prefix
very_long_event_name_that_exceeds_the_character_limit_of_forty // Too longOnce you've identified the invalid event name, update your code to use a compliant name. Replace the problematic event name with a valid one that meets Firebase's requirements.
For web (JavaScript):
// WRONG
firebase.analytics().logEvent("1st_purchase");
// CORRECT
firebase.analytics().logEvent("first_purchase");For mobile (Swift):
// WRONG
Analytics.logEvent("user-login", parameters: [:])
// CORRECT
Analytics.logEvent("user_login", parameters: [:])For mobile (Kotlin):
// WRONG
FirebaseAnalytics.getInstance(context).logEvent("purchase@checkout", null)
// CORRECT
FirebaseAnalytics.getInstance(context).logEvent("purchase_checkout", null)After updating your code, test that the event logs successfully. Enable Firebase Analytics DebugView to monitor events in real-time.
For Android:
adb shell setprop debug.firebase.analytics.app com.example.myappFor iOS, run your app in Xcode with -FIRAnalyticsDebugEnabled flag.
Once DebugView is enabled, trigger the event in your app and verify it appears in the Firebase Console under Analytics > DebugView. The event should appear with no error codes.
If your event name is valid but you're still seeing Code 2 errors, the problem might be in your custom parameters. Parameter names follow the same naming rules as event names:
- Must start with a letter
- Can contain alphanumeric characters and underscores only
- Must be 1-40 characters long
- Cannot use reserved prefixes
// Event name is valid, but parameter name has a hyphen
firebase.analytics().logEvent("user_login", {
"login-method": "google" // WRONG - hyphen not allowed
});
// Correct version
firebase.analytics().logEvent("user_login", {
"login_method": "google" // CORRECT
});Event name validation is case-sensitive, so "user_login" and "User_Login" are treated as different events. Firebase recommends using consistent lowercase snake_case naming across your entire application to avoid confusion.
If you're using Firebase Analytics on both web and mobile platforms, ensure event names are identical across platforms for consistent reporting. Cross-platform event naming makes it easier to analyze user behavior across different app versions.
Reserved event names like app_open, app_remove, app_clear_data, user_engagement, session_start, and session_end are automatically logged by Firebase SDKs and cannot be manually logged. Attempting to log these will result in validation errors.
For very large applications with many custom events, consider maintaining an event taxonomy document that lists all approved event and parameter names to prevent naming inconsistencies and validation errors.
messaging/UNSPECIFIED_ERROR: No additional information available
How to fix "messaging/UNSPECIFIED_ERROR: No additional information available" in Firebase Cloud Messaging
App Check: reCAPTCHA Score Too Low
App Check reCAPTCHA Score Too Low
storage/invalid-url: Invalid URL format for Cloud Storage reference
How to fix invalid URL format in Firebase Cloud Storage
auth/missing-uid: User ID identifier required
How to fix "auth/missing-uid: User ID identifier required" in Firebase
auth/invalid-argument: Invalid parameter passed to method
How to fix "auth/invalid-argument: Invalid parameter passed to method" in Firebase