Class FirebaseModule
Wraps the Firebase Unity SDK, providing Analytics, Crashlytics, Remote Config, and Cloud Messaging. Not supported on WebGL — all methods return early with a warning when compiled for that platform.
public static class FirebaseModule
- Inheritance
-
FirebaseModule
- Inherited Members
Properties
- Config
The config used to initialize this module.
- IsInitialized
Whether the Firebase SDK has been initialized successfully.
Initialization
- InitializeAsync(FirebaseModuleConfig)
Initializes the Firebase SDK and enables Analytics collection. When UseRemoteConfig is enabled, the Remote Config fetch and activate complete before this returns, so
GetRemote*reads are reliable immediately after. Push notification setup (when enabled) is started in the background and not awaited. UnderMOCALIB2_USE_FIREBASE_APP_CHECK, registers the platform App Check provider before SDK init.
Methods
- GetAnalyticsInstanceIdAsync()
Returns the Firebase Analytics instance ID asynchronously. Useful for linking Firebase events to other attribution systems (e.g., AppsFlyer). Times out after 5 seconds and returns
nullon failure.
- GetRemoteBool(string, bool)
Returns a Remote Config bool value, or
defaultValueif not fetched from the server.
- GetRemoteDouble(string, double)
Returns a Remote Config double value, or
defaultValueif not fetched from the server.
- GetRemoteFloat(string, float)
Returns a Remote Config float value, or
defaultValueif not fetched from the server.
- GetRemoteInt(string, int)
Returns a Remote Config integer value, or
defaultValueif not fetched from the server.
- GetRemoteLong(string, long)
Returns a Remote Config long value, or
defaultValueif not fetched from the server.
- GetRemoteString(string, string)
Returns a Remote Config string value. Falls back to
defaultValueif the key has not been fetched from the server (i.e., source is StaticValue) or is empty.
- LogAdRevenue(AdImpressionData, string, Dictionary<string, string>, string, int, string)
Logs an
ad_impressionevent to Firebase Analytics. UnderMOCALIB2_USE_COST_CENTER, also logs anad_revenue_sdkevent that includes value in micros, lifetime revenue, and gameplay context.
- LogEvent(string)
Logs a named Firebase Analytics event with no parameters.
- LogEvent(string, params Parameter[])
Logs a named Firebase Analytics event with one or more
Parameterinstances.
- LogEvent(string, Dictionary<string, object>)
Logs a named Firebase Analytics event with mixed-type key-value parameters.
long,int,double, andfloatvalues are forwarded as their native numeric types; all other values are converted to strings.
- LogEvent(string, Dictionary<string, string>)
Logs a named Firebase Analytics event with string key-value parameters.
- LogEvent(string, string, double)
Logs a named Firebase Analytics event with a single double parameter.
- LogEvent(string, string, long)
Logs a named Firebase Analytics event with a single long parameter.
- LogEvent(string, string, string)
Logs a named Firebase Analytics event with a single string parameter.
- LogPurchase(Product, string, int)
Under
MOCALIB2_USE_COST_CENTER, logs aniap_sdkevent with price, currency, product ID, and gameplay context. Firebase auto-tracks the standard purchase event via Unity IAP; this method adds the COST_CENTER-specific extended fields only.
- RefreshRemoteConfigAsync()
Re-fetches and activates Remote Config at runtime (e.g. after the app resumes from background), then returns whether it succeeded. Also raises OnRemoteConfigFetched. Read the updated values with the
GetRemote*methods afterwards. The initial fetch already runs during InitializeAsync(FirebaseModuleConfig); use this only to pull fresh values without restarting.
- RegisterForPushNotifications(Action, Action)
Starts listening for FCM push tokens and incoming messages. On iOS, also enables token registration on SDK init. Can be called at any time after InitializeAsync(FirebaseModuleConfig) to request permission. The
onGrantedcallback fires once when the FCM token is received.
- SetUserProperty(string, string)
Sets a Firebase Analytics user property for audience segmentation.
Events
- OnRemoteConfigFetched
Fired after Remote Config has been fetched and activated. The
boolparameter istrueon success,falseon failure.