Class FirebaseModule
Wraps the Firebase Unity SDK, providing Analytics, Crashlytics, Remote Config, and Cloud Messaging. Supported on Android, iOS, and the Unity Editor; on any other platform every method logs its entry and no-ops, returning its default value.
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>)
Logs an
ad_impressionevent to Firebase Analytics.Do not call this when AdMob is your ad network. Once an AdMob app is linked to Firebase/Analytics, the Firebase SDK logs
ad_impressionautomatically for every impression; calling this on top of that double-counts every impression and inflates ad revenue in Analytics. Use it only for mediation SDKs that expose impression-level revenue but have no such automatic integration — AppLovin MAX, ironSource, and similar.Attribution SDKs are unaffected:
https://firebase.google.com/docs/analytics/measure-ad-revenue#unityAppsFlyerModule.LogAdRevenue/AdjustModule.LogAdRevenuestill need to be wired for AdMob, since nothing forwards revenue to them automatically.
- 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.
- 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.