pub struct Analytics { /* private fields */ }Implementations§
Source§impl Analytics
impl Analytics
pub fn app(&self) -> &FirebaseApp
pub async fn log_event( &self, name: &str, params: BTreeMap<String, String>, ) -> AnalyticsResult<()>
pub fn recorded_events(&self) -> Vec<AnalyticsEvent>
Sourcepub fn gtag_state(&self) -> GtagState
pub fn gtag_state(&self) -> GtagState
Returns a snapshot of the gtag bootstrap state collected so far.
Sourcepub async fn measurement_config(&self) -> AnalyticsResult<DynamicConfig>
pub async fn measurement_config(&self) -> AnalyticsResult<DynamicConfig>
Resolves the measurement configuration for this analytics instance. The value is derived from the Firebase app options when possible and otherwise fetched from the Firebase analytics REST endpoint. Results are cached for subsequent calls.
Sourcepub fn configure_measurement_protocol(
&self,
config: MeasurementProtocolConfig,
) -> AnalyticsResult<()>
pub fn configure_measurement_protocol( &self, config: MeasurementProtocolConfig, ) -> AnalyticsResult<()>
Configures the analytics instance to forward events using the GA4 Measurement Protocol.
The configuration requires a valid measurement ID and API secret generated from the associated Google Analytics property. If a dispatcher has already been configured it is replaced.
Sourcepub async fn configure_measurement_protocol_with_secret(
&self,
api_secret: impl Into<String>,
) -> AnalyticsResult<()>
pub async fn configure_measurement_protocol_with_secret( &self, api_secret: impl Into<String>, ) -> AnalyticsResult<()>
Convenience helper that resolves the measurement configuration and configures the measurement protocol using the provided API secret. The dispatcher targets the default GA4 collection endpoint.
Sourcepub async fn configure_measurement_protocol_with_secret_and_endpoint(
&self,
api_secret: impl Into<String>,
endpoint: MeasurementProtocolEndpoint,
) -> AnalyticsResult<()>
pub async fn configure_measurement_protocol_with_secret_and_endpoint( &self, api_secret: impl Into<String>, endpoint: MeasurementProtocolEndpoint, ) -> AnalyticsResult<()>
Convenience helper that resolves the measurement configuration and configures the measurement protocol using the provided API secret and custom endpoint. This is primarily intended for testing or emulator scenarios.
Sourcepub fn set_client_id(&self, client_id: impl Into<String>)
pub fn set_client_id(&self, client_id: impl Into<String>)
Overrides the client identifier reported to the measurement protocol. When unset the analytics instance falls back to a randomly generated identifier created during initialization.
Sourcepub fn set_default_event_parameters(&self, params: BTreeMap<String, String>)
pub fn set_default_event_parameters(&self, params: BTreeMap<String, String>)
Sets the default event parameters that should be merged into every logged event unless explicitly overridden.
Sourcepub fn set_consent_defaults(&self, consent: ConsentSettings)
pub fn set_consent_defaults(&self, consent: ConsentSettings)
Configures default consent settings that mirror the GA4 consent API. The values are cached so they can be applied once full gtag integration is implemented. Calling this replaces any previously stored consent state.
Sourcepub fn apply_settings(&self, settings: AnalyticsSettings)
pub fn apply_settings(&self, settings: AnalyticsSettings)
Applies analytics configuration options analogous to the JS AnalyticsSettings structure.
The configuration is cached and merged with any previously supplied settings.
Sourcepub fn set_collection_enabled(&self, enabled: bool)
pub fn set_collection_enabled(&self, enabled: bool)
Enables or disables analytics collection. When disabled, events are still recorded locally but are not dispatched through the configured transport.
Sourcepub fn collection_enabled(&self) -> bool
pub fn collection_enabled(&self) -> bool
Returns whether analytics collection is currently enabled.