Skip to content

Firebase Integration

Utilities to subscribe to push notification services (Firebase) and register the device token in the backend ("notypo").

This package utilizes Firebase Cloud Messaging (FCM) and may require some updates through Unity's editor post-processing. For reference, see "iOSNotificationPostProcessor.cs."

Installation

To install Firebase, used by this package, please refer to its documentation: Firebase Unity Setup

Usage

This package provides two approaches to initialize push notifications; only one is required:

  1. Component-Based Approach Create the PushNotificationInitComponent during initialization and add the PushNotificationModule to the persistent world.

  2. State Machine-Based Approach Add the SendPushTokenRequestState to your app loading FSM to define the step where push notification registration will be triggered.

Choose the method that best aligns with your game’s architecture.

Remote Config

Remote Config and A/B testing support is split into two assemblies under Runtime/RemoteConfig/, because this package is shared with projects (e.g. S1914) that do not have the Firebase Remote Config SDK installed:

  1. Stratkit.FirebaseIntegration.RemoteConfig (Runtime/RemoteConfig/) — unconstrained, no Firebase reference. Holds the keys, the registry, the snapshot, resolution, JSON decoding, the cohort-reporter interface, a defaults-only source and the settings scriptable. Compiles everywhere, including projects without the SDK, giving defaults-only Remote Config with no opt-in required.
  2. Stratkit.FirebaseIntegration.RemoteConfig.Firebase (Runtime/RemoteConfig/Firebase/) — holds only the Firebase-backed source, and only exists on Android, iOS and in the Editor: defineConstraints: ["STRATKIT_FIREBASE_REMOTE_CONFIG"] gates it on the opt-in define, and includePlatforms gates it to the platforms Firebase Remote Config actually supports. Unity skips an assembly whose define constraints are unmet or whose platform list excludes the current target, so it simply does not exist in a project that has not opted in, and a missing SDK there cannot break that build.

Runtime/RemoteConfig/Keys/ holds the by-name lookup layer: RemoteConfigKeysAsset (the ScriptableObject a game edits to declare its tests and key assets), RemoteConfigKeys (a static facade over the registry RemoteConfigKeysAsset.Build() produces, initialized once from bootstrap), and the per-type key assets (RemoteConfigBoolKeyAsset, RemoteConfigIntKeyAsset, etc.) listed on it. All of it is unconstrained core, so a game with no Remote Config SDK can still declare keys and get defaults-only values. Picking the Firebase source over the defaults-only one is still a game-side decision — see RemoteConfigBootstrap in WHS for the one #if that does it.

Opting in: STRATKIT_FIREBASE_REMOTE_CONFIG

To bring in the Firebase-backed source, add STRATKIT_FIREBASE_REMOTE_CONFIG to the project's scripting define symbols. Be aware that the CI might overwrite those values when building for specific environments, so make sure to update the CI workflows accordingly.

Platform matrix

Define set Platform Source used
No any Defaults-only (registry defaults, cohort always "unassigned")
Yes Android / iOS Firebase-backed, real fetch and activation
Yes Windows Defaults-only — the Firebase assembly does not exist on that platform

Declaring a test and reading a value

Keys and tests are declared on a RemoteConfigKeysAsset.asset. Bootstrap builds the registry from it once (RemoteConfigKeys.Initialize), and RemoteConfigKeys exposes lookups by name:

RemoteConfigTest someTest = RemoteConfigKeys.GetTest("some_test");
RemoteConfigKey<bool> someTestShowBanner = RemoteConfigKeys.GetKey<bool>("some_test_show_banner");

Declaring a test auto-declares its cohort key (<test>_cohort), defaulting to "unassigned".

To read a value:

bool showBanner = RemoteConfig.Get(someTestShowBanner);

Code that only reads a key should reference its key asset (for example a RemoteConfigBoolKeyAsset field) and call RemoteConfig.Get(keyAsset), so the parameter name only lives in the asset. The key asset must also be listed on RemoteConfigKeysAsset; RemoteConfigKeysAsset.IsDeclared lets an editor validation check that.

Get<T> never throws and never returns null for a JSON key: a missing, malformed or wrong-typed remote value resolves to the registry default.

Snapshot

Remote Config is fetched and resolved once at bootstrap. The resolved snapshot does not change for the rest of the session — there is no realtime config-update listener, because a flag or cohort flipping mid-run would be a correctness problem. A fetch that completes late is still activated and cached by Firebase, so it is picked up on the next launch, not the current one.

Cohort reporting

A test's cohort is reported by the game's IRemoteConfigCohortReporter. The reporter decides the destinations and their gates, for example consent or login. A reporter should send "unassigned" (with its source) only to destinations that tolerate it, so the offline/unreached population stays visible in analysis.