AnalyticsKt

public final class AnalyticsKt


Summary

Public methods

static final @NonNull FirebaseAnalytics

Accessing this object for Kotlin apps has changed; see the migration guide.

static final void
logEvent(
    @NonNull FirebaseAnalytics receiver,
    @NonNull String name,
    @ExtensionFunctionType @NonNull Function1<@NonNull ParametersBuilderUnit> block
)

This method is deprecated. Migrate to use the KTX API from the main module: https://firebase.google.com/docs/android/kotlin-migration.

static final void
setConsent(
    @NonNull FirebaseAnalytics receiver,
    @ExtensionFunctionType @NonNull Function1<@NonNull ConsentBuilderUnit> block
)

This method is deprecated. Migrate to use the KTX API from the main module: https://firebase.google.com/docs/android/kotlin-migration.

Public methods

getAnalytics

public static final @NonNull FirebaseAnalytics getAnalytics(@NonNull Firebase receiver)

Accessing this object for Kotlin apps has changed; see the migration guide.

Returns the FirebaseAnalytics instance of the default FirebaseApp.

Important: In July 2025, we stopped releasing KTX modules and removed the KTX libraries from the Firebase Android BoM (v34.0.0). If you use KTX APIs from the KTX modules, we recommend that you migrate your app to use KTX APIs from the main modules instead. For details, see the FAQ about this initiative.

logEvent

public static final void logEvent(
    @NonNull FirebaseAnalytics receiver,
    @NonNull String name,
    @ExtensionFunctionType @NonNull Function1<@NonNull ParametersBuilderUnit> block
)

Fluent version of FirebaseAnalytics.logEvent.

Example use:

Firebase.analytics.logEvent("myEvent") {
param(Params.VALUE, 3.99)
param(Params.CURRENCY, "USD")
}

Important: In July 2025, we stopped releasing KTX modules and removed the KTX libraries from the Firebase Android BoM (v34.0.0). If you use KTX APIs from the KTX modules, we recommend that you migrate your app to use KTX APIs from the main modules instead. For details, see the FAQ about this initiative.

setConsent

public static final void setConsent(
    @NonNull FirebaseAnalytics receiver,
    @ExtensionFunctionType @NonNull Function1<@NonNull ConsentBuilderUnit> block
)

Fluent version of FirebaseAnalytics.setConsent.

Example use:

Firebase.analytics.setConsent {
adStorage = ConsentStatus.GRANTED
analyticsStorage = ConsentStatus.GRANTED
}

Important: In July 2025, we stopped releasing KTX modules and removed the KTX libraries from the Firebase Android BoM (v34.0.0). If you use KTX APIs from the KTX modules, we recommend that you migrate your app to use KTX APIs from the main modules instead. For details, see the FAQ about this initiative.