-
Notifications
You must be signed in to change notification settings - Fork 6
Crashlytics
Firebase Crashlytics is a lightweight, real-time crash reporter that helps you track, prioritize, and fix stability issues that erode your app quality. Crashlytics saves you troubleshooting time by intelligently grouping crashes and highlighting the circumstances that lead up to them. Find out if a particular crash is impacting a lot of users. Get alerts when an issue suddenly increases in severity. Figure out which lines of code are causing crashes. All this information gets delivered to you through the online Firebase Console. Crashlytics also easily integrates into your Android, iOS, macOS, tvOS, and watchOS apps. Check the official page for more information.
Before starting to use any Firebase extensions, you are required to follow some general configuration steps; however the Crashlytics extension has some specific requirements which you can read in the pages below:
The following functions are given for working with Firebase Crashlytics extension:
- FirebaseCrashlytics_Crash
- FirebaseCrashlytics_CrashlyticsCollectionEnabled_Check
- FirebaseCrashlytics_CrashlyticsCollectionEnabled_Set
- FirebaseCrashlytics_DidCrashOnPreviousExecution
- FirebaseCrashlytics_Log
- FirebaseCrashlytics_RecordException
- FirebaseCrashlytics_SetCustomKey
- FirebaseCrashlytics_SetCustomKeys
- FirebaseCrashlytics_SetUserIdentifier
- FirebaseCrashlytics_UnsentReports_Check
- FirebaseCrashlytics_UnsentReports_Delete
- FirebaseCrashlytics_UnsentReports_Send
The following constants are given for working with Firebase Crashlytics extension:
This function throws an error that crashes the app and creates a fatal report to be sent to Crashlytics server. A crash created using this function can be tracked during the next application execution using the method FirebaseCrashlytics_DidCrashOnPreviousExecution.
Warning
This function needs to be called at least once to enable Crashlytics for the first time.
Syntax:
FirebaseCrashlytics_Crash(errorMessage)
Argument | Type | Description |
---|---|---|
errorMessage | String | The error message to report (this will be a fatal report). |
Returns:
N/A
Example:
FirebaseCrashlytics_Crash("Test Crash");
The code above logs a fatal error report to the Crashlytics server. Another way to deal with error reporting would be to call the exception_unhandled_handler function and override the default error handling function with the example below.
exception_unhandled_handler(function(_exception) {
var _info = json_stringify(_exception);
FirebaseCrashlytics_Crash(_info);
show_debug_message(_info);
});
The code above catches all the exceptions and trigger a fatal error report with the information from the exception converted to a string (using the function json_stringify) and will also print the same information to the debug console.
This function returns whether automatic data collection is enabled or not. The function uses two ways to check whether automatic data collection is enabled, in order of priority:
- If FirebaseCrashlytics_CrashlyticsCollectionEnabled_Set was called, uses its value.
- If the
FirebaseCrashlyticsCollectionEnabled
key is in your app'sInfo.plist
, uses that.
Syntax:
FirebaseCrashlytics_CrashlyticsCollectionEnabled_Check()
Returns:
Example:
if (FirebaseCrashlytics_CrashlyticsCollectionEnabled_Check())
{
FirebaseCrashlytics_CrashlyticsCollectionEnabled_Set(false);
}
The code above checks if Crashlytics automatic data collection is enabled and if so it will disable it (using the function FirebaseCrashlytics_CrashlyticsCollectionEnabled_Set).
This function is used to enable or disable the automatic data collection configuration for Crashlytics. If this is set, it overrides any automatic data collection settings configured in the extension options as well as any Firebase-wide settings.
If automatic data collection is disabled for Crashlytics, crash reports are stored on the device. To check for unsent reports, use the FirebaseCrashlytics_UnsentReports_Check function. Use FirebaseCrashlytics_UnsentReports_Send to upload existing reports when automatic data collection is disabled. Use FirebaseCrashlytics_UnsentReports_Delete to delete any reports stored on the device without sending them to Crashlytics.
Syntax:
FirebaseCrashlytics_CrashlyticsCollectionEnabled_Set(enabled)
Argument | Type | Description |
---|---|---|
enabled | Boolean | Whether to enable automatic data collection. |
Returns:
N/A
Example:
if (FirebaseCrashlytics_CrashlyticsCollectionEnabled_Check())
{
FirebaseCrashlytics_CrashlyticsCollectionEnabled_Set(false);
}
The code above checks if automatic data collection is enabled (using FirebaseCrashlytics_CrashlyticsCollectionEnabled_Check) and if so it will disable it.
This function logs a message that is included in the next fatal or non-fatal report. Logs are visible in the session view on the Firebase Crashlytics console. Newline characters are stripped and extremely long messages are truncated. The maximum log size is 64k. If exceeded, the log rolls such that messages are removed, starting from the oldest.
Syntax:
FirebaseCrashlytics_Log(message)
Argument | Type | Description |
---|---|---|
message | String | The message to be logged. |
Returns:
Example:
FirebaseCrashlytics_Log("Entered the " + room_get_name(room) + " room");
The code example above will log a message that will be included in the next report; this might be useful for identifying the source of the error within the game (e.g. in the example above we log the name of the current room so we know which room the error originated in).
Records a non-fatal report to send to Crashlytics. Non-fatal reports are manually thrown by the developer and may not represent crashes that occurred during code execution.
Syntax:
FirebaseCrashlytics_RecordException(errorMessage)
Argument | Type | Description |
---|---|---|
errorMessage | String | Error message to include in the report. |
Returns:
Example:
switch (characterClass)
{
case "hero":
// Do something
break;
case "enemy":
// Do something else
break;
default:
// There are no more classes, so we shouldn't be hitting this line
FirebaseCrashlytics_RecordException("characterClass has an unknown value of :" + characterClass);
break;
}
In the code above we have a switch statement where the variable (characterClass
) is expected to only be equal to either "hero"
or "enemy"
. If it happens to be none of these then we might want to report this even though it's not a fatal error.
This function sets a custom key-value pair that is associated with subsequent fatal and non-fatal reports. Calling this function with an existing key will simply update the value for that key. The value of any key at the time of a fatal or non-fatal event is associated with that event. Keys and associated values are visible in the session view on the Firebase Crashlytics console.
Crashlytics supports a maximum of 64 key/value pairs. New keys beyond that limit are ignored. Keys or values that exceed 1024 characters are truncated.
Syntax:
FirebaseCrashlytics_SetCustomKey(key, value)
Argument | Type | Description |
---|---|---|
key | String | A unique key. |
value | Real or String | The value to be associated with the given key. |
Returns:
Example:
FirebaseCrashlytics_SetCustomKey("level", room_get_name(room));
The code above sets the custom key "level"
to be included in subsequent reports, which can help the developer know which room caused a certain crash.
Sets multiple custom key-value pairs for Crashlytics using a JSON-formatted string. Each key-value pair will be associated with subsequent fatal and non-fatal crash reports. If a key already exists, its value will be updated. The values of these keys at the time of a crash or non-fatal event are logged with that event and are visible in the session view on the Firebase Crashlytics console.
Crashlytics supports a maximum of 64 key/value pairs. New keys beyond that limit are ignored. Keys or values that exceed 1024 characters are truncated.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Social Async Event.
Syntax:
FirebaseCrashlytics_SetCustomKeys(key_values)
Argument | Type | Description |
---|---|---|
key_values | String | A json formatted string with key value pairs. |
Returns:
Triggers:
Key | Type | Description |
---|---|---|
type | String | The string "FirebaseCrashlytics_SetCustomKeys"
|
success | Boolean | Whether or not the operation succeeded. |
Example:
var _data = { player: global.playerName, level: global.playerLevel };
FirebaseCrashlytics_SetCustomKeys(json_stringify(_data));
The example above sets custom keys "player"
and "level"
to be included in subsequent crash reports. This can help developers understand the state of the game and identify which player and game level were active when a crash occurred.
This function records a user ID (identifier) that is associated with subsequent fatal and non-fatal reports. The user ID is visible in the session view on the Firebase Crashlytics console. Identifiers longer than 1024 characters will be truncated.
Syntax:
FirebaseCrashlytics_SetUserIdentifier(identifier)
Argument | Type | Description |
---|---|---|
identifier | String | A unique identifier for the current user. |
Returns:
Example:
FirebaseCrashlytics_SetUserIdentifier("MyUser1234567");
The code above will add additional user information to the any subsequent reports.
This function checks the device for any fatal or non-fatal crash reports that haven't yet been sent to Crashlytics. If automatic data collection is enabled, then reports are uploaded automatically and this always returns false in its Async event. If automatic data collection is disabled, this function can be used to check whether the user opted in to send crash reports from their device.
Warning
If there are any unsent reports, this function will only (asynchronously) return true
for the first time it is called in each game execution.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Social Async Event.
Syntax:
FirebaseCrashlytics_UnsentReports_Check()
Returns:
Triggers:
Key | Type | Description |
---|---|---|
type | String | The string "FirebaseCrashlytics_UnsentReports_Check"
|
value | Boolean | Whether or not there are unsent reports. |
Example:
FirebaseCrashlytics_UnsentReports_Check();
In the code above we are checking for collected unsent reports. The function callback can be caught inside a Social Async Event.
if (async_load[? "type"] == "FirebaseCrashlytics_UnsentReports_Check")
{
if (async_load[? "value"])
{
FirebaseCrashlytics_UnsentReports_Send();
}
}
The code above matches the response against the correct event type, and if there are unsent reports we proceed to send them to the Crashlytics servers (using the function FirebaseCrashlytics_UnsentReports_Send).
If automatic data collection is disabled, this function queues up any unsent reports on the device for deletion. Otherwise, it does nothing.
Syntax:
FirebaseCrashlytics_UnsentReports_Delete()
Returns:
Example:
if (async_load[? "type"] == "FirebaseCrashlytics_UnsentReports_Check")
{
if (async_load[? "value"])
{
FirebaseCrashlytics_UnsentReports_Delete();
}
}
The code above exists in the Social Async Event as a callback for the FirebaseCrashlytics_UnsentReports_Check function, and checks if there are any unsent reports on the device; in that case, it deletes them.
If automatic data collection is disabled, this function queues up any unsent reports on the device to be sent to Crashlytics. Otherwise, it does nothing.
Syntax:
FirebaseCrashlytics_UnsentReports_Send()
Returns:
Example:
if (async_load[? "type"] == "FirebaseCrashlytics_UnsentReports_Check")
{
if (async_load[? "value"])
{
FirebaseCrashlytics_UnsentReports_Send();
}
}
The code above exists in the Social Async Event as a callback for the FirebaseCrashlytics_UnsentReports_Check function, and checks if there are any unsent reports on the device; in that case, it proceeds to send them to the Crashlytics server.
This function returns whether the app crashed during its previous run (any errors handled by the FirebaseCrashlytics_Crash function are considered to be crashes by this function).
Syntax:
FirebaseCrashlytics_DidCrashOnPreviousExecution()
Returns:
Example:
if (FirebaseCrashlytics_DidCrashOnPreviousExecution())
{
FirebaseCrashlytics_UnsentReports_Send();
}
The code above checks if the application crashed on its previous execution and in that case, sends all the unsent reports to the Crashlytics servers (using the function FirebaseCrashlytics_UnsentReports_Send).
Represents the possible results for operations in the Crashlytics module.
These constants are referenced by the following functions:
- FirebaseCrashlytics_Log
- FirebaseCrashlytics_RecordException
- FirebaseCrashlytics_SetCustomKey
- FirebaseCrashlytics_SetCustomKeys
- FirebaseCrashlytics_SetUserIdentifier
- FirebaseCrashlytics_UnsentReports_Check
- FirebaseCrashlytics_UnsentReports_Delete
- FirebaseCrashlytics_UnsentReports_Send
Member | Description |
---|---|
FIREBASE_CRASHLYTICS_SUCCESS |
Indicates the operation was completed successfully. |
FIREBASE_CRASHLYTICS_ERROR_INVALID_PARAMETERS |
Indicates the operation failed due to invalid input parameters. |
GameMaker 2024