Search in sources :

Example 6 with AnalyticsConnector

use of com.google.firebase.analytics.connector.AnalyticsConnector in project firebase-android-sdk by firebase.

the class AnalyticsDeferredProxy method init.

private void init() {
    analyticsConnectorDeferred.whenAvailable(analyticsConnector -> {
        Logger.getLogger().d("AnalyticsConnector now available.");
        AnalyticsConnector connector = analyticsConnector.get();
        // If FA is available, create a logger to log events from the Crashlytics origin.
        final CrashlyticsOriginAnalyticsEventLogger directAnalyticsEventLogger = new CrashlyticsOriginAnalyticsEventLogger(connector);
        // Create a listener to register for events coming from FA, which supplies both
        // breadcrumbs
        // as well as Crashlytics-origin events through different streams.
        final CrashlyticsAnalyticsListener crashlyticsAnalyticsListener = new CrashlyticsAnalyticsListener();
        // Registering our listener with FA should return a "handle", in which case we know we've
        // registered successfully. Subsequent calls to register a listener will return null.
        final AnalyticsConnector.AnalyticsConnectorHandle analyticsConnectorHandle = subscribeToAnalyticsEvents(connector, crashlyticsAnalyticsListener);
        if (analyticsConnectorHandle != null) {
            Logger.getLogger().d("Registered Firebase Analytics listener.");
            // Create the event receiver which will supply breadcrumb events to Crashlytics
            final BreadcrumbAnalyticsEventReceiver breadcrumbReceiver = new BreadcrumbAnalyticsEventReceiver();
            // Logging events to FA is an asynchronous operation. This logger will send events to
            // FA and block until FA returns the same event back to us, from the Crashlytics origin.
            // However, in the case that data collection has been disabled on FA, we will not
            // receive
            // the event back (it will be silently dropped), so we set up a short timeout after
            // which
            // we will assume that FA data collection is disabled and move on.
            final BlockingAnalyticsEventLogger blockingAnalyticsEventLogger = new BlockingAnalyticsEventLogger(directAnalyticsEventLogger, APP_EXCEPTION_CALLBACK_TIMEOUT_MS, TimeUnit.MILLISECONDS);
            synchronized (this) {
                // objects.
                for (BreadcrumbHandler handler : breadcrumbHandlerList) {
                    breadcrumbReceiver.registerBreadcrumbHandler(handler);
                }
                // Set the appropriate event receivers to receive events from the FA listener
                crashlyticsAnalyticsListener.setBreadcrumbEventReceiver(breadcrumbReceiver);
                crashlyticsAnalyticsListener.setCrashlyticsOriginEventReceiver(blockingAnalyticsEventLogger);
                // Set the breadcrumb event receiver as the breadcrumb source for Crashlytics.
                breadcrumbSource = breadcrumbReceiver;
                // Set the blocking analytics event logger for Crashlytics.
                analyticsEventLogger = blockingAnalyticsEventLogger;
            }
        } else {
            Logger.getLogger().w("Could not register Firebase Analytics listener; a listener is already registered.");
        // FA is enabled, but the listener was not registered successfully.
        // We cannot listen for breadcrumbs. Since the default is already
        // `DisabledBreadcrumbSource` and `directAnalyticsEventLogger` there's nothing else to
        // do.
        }
    });
}
Also used : BlockingAnalyticsEventLogger(com.google.firebase.crashlytics.internal.analytics.BlockingAnalyticsEventLogger) BreadcrumbAnalyticsEventReceiver(com.google.firebase.crashlytics.internal.analytics.BreadcrumbAnalyticsEventReceiver) CrashlyticsOriginAnalyticsEventLogger(com.google.firebase.crashlytics.internal.analytics.CrashlyticsOriginAnalyticsEventLogger) BreadcrumbHandler(com.google.firebase.crashlytics.internal.breadcrumbs.BreadcrumbHandler) AnalyticsConnector(com.google.firebase.analytics.connector.AnalyticsConnector)

Example 7 with AnalyticsConnector

use of com.google.firebase.analytics.connector.AnalyticsConnector in project firebase-android-sdk by firebase.

the class ConfigFetchHandler method getUserProperties.

/**
 * Returns the list of custom user properties in Analytics. If the Analytics SDK is not available,
 * this method returns an empty list.
 */
@WorkerThread
private Map<String, String> getUserProperties() {
    Map<String, String> userPropertiesMap = new HashMap<>();
    AnalyticsConnector connector = this.analyticsConnector.get();
    if (connector == null) {
        return userPropertiesMap;
    }
    for (Map.Entry<String, Object> userPropertyEntry : connector.getUserProperties(/*includeInternal=*/
    false).entrySet()) {
        userPropertiesMap.put(userPropertyEntry.getKey(), userPropertyEntry.getValue().toString());
    }
    return userPropertiesMap;
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) AnalyticsConnector(com.google.firebase.analytics.connector.AnalyticsConnector) WorkerThread(androidx.annotation.WorkerThread)

Example 8 with AnalyticsConnector

use of com.google.firebase.analytics.connector.AnalyticsConnector in project firebase-android-sdk by firebase.

the class Personalization method logArmActive.

/**
 * Called when a Personalization parameter value (an arm) is retrieved, and uses Google Analytics
 * for Firebase to log metadata if it's a Personalization parameter.
 *
 * @param rcParameter Remote Config parameter
 * @param configContainer {@link ConfigContainer} containing Personalization metadata for {@code
 *     key}
 */
public void logArmActive(@NonNull String rcParameter, @NonNull ConfigContainer configContainer) {
    AnalyticsConnector connector = this.analyticsConnector.get();
    if (connector == null) {
        return;
    }
    JSONObject ids = configContainer.getPersonalizationMetadata();
    if (ids.length() < 1) {
        return;
    }
    JSONObject values = configContainer.getConfigs();
    if (values.length() < 1) {
        return;
    }
    JSONObject metadata = ids.optJSONObject(rcParameter);
    if (metadata == null) {
        return;
    }
    String choiceId = metadata.optString(CHOICE_ID);
    if (choiceId.isEmpty()) {
        return;
    }
    synchronized (loggedChoiceIds) {
        if (choiceId.equals(loggedChoiceIds.get(rcParameter))) {
            return;
        }
        loggedChoiceIds.put(rcParameter, choiceId);
    }
    Bundle logParams = new Bundle();
    logParams.putString(EXTERNAL_RC_PARAMETER_PARAM, rcParameter);
    logParams.putString(EXTERNAL_ARM_VALUE_PARAM, values.optString(rcParameter));
    logParams.putString(EXTERNAL_PERSONALIZATION_ID_PARAM, metadata.optString(PERSONALIZATION_ID));
    logParams.putInt(EXTERNAL_ARM_INDEX_PARAM, metadata.optInt(ARM_INDEX, -1));
    logParams.putString(EXTERNAL_GROUP_PARAM, metadata.optString(GROUP));
    connector.logEvent(ANALYTICS_ORIGIN_PERSONALIZATION, EXTERNAL_EVENT, logParams);
    Bundle internalLogParams = new Bundle();
    internalLogParams.putString(INTERNAL_CHOICE_ID_PARAM, choiceId);
    connector.logEvent(ANALYTICS_ORIGIN_PERSONALIZATION, INTERNAL_EVENT, internalLogParams);
}
Also used : JSONObject(org.json.JSONObject) Bundle(android.os.Bundle) AnalyticsConnector(com.google.firebase.analytics.connector.AnalyticsConnector)

Example 9 with AnalyticsConnector

use of com.google.firebase.analytics.connector.AnalyticsConnector in project firebase-android-sdk by firebase.

the class ProxyAnalyticsConnectorTest method setUserProperty_whenConnectorIsAvailable_shouldDelegateToIt.

@Test
public void setUserProperty_whenConnectorIsAvailable_shouldDelegateToIt() {
    TestDeferred<AnalyticsConnector> testDeferred = new TestDeferred<>();
    ProxyAnalyticsConnector proxy = new ProxyAnalyticsConnector(testDeferred);
    testDeferred.provide(mockConnector);
    String s = "s";
    String s1 = "s1";
    Object o = new Object();
    proxy.setUserProperty(s, s1, o);
    verify(mockConnector, times(1)).setUserProperty(s, s1, o);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) AnalyticsConnector(com.google.firebase.analytics.connector.AnalyticsConnector) Test(org.junit.Test)

Example 10 with AnalyticsConnector

use of com.google.firebase.analytics.connector.AnalyticsConnector in project firebase-android-sdk by firebase.

the class FirebaseInAppMessagingRegistrar method providesFirebaseInAppMessaging.

private FirebaseInAppMessaging providesFirebaseInAppMessaging(ComponentContainer container) {
    FirebaseApp firebaseApp = container.get(FirebaseApp.class);
    FirebaseInstallationsApi firebaseInstallations = container.get(FirebaseInstallationsApi.class);
    Deferred<AnalyticsConnector> analyticsConnector = container.getDeferred(AnalyticsConnector.class);
    Subscriber firebaseEventsSubscriber = container.get(Subscriber.class);
    Application application = (Application) firebaseApp.getApplicationContext();
    UniversalComponent universalComponent = DaggerUniversalComponent.builder().applicationModule(new ApplicationModule(application)).appMeasurementModule(new AppMeasurementModule(analyticsConnector, firebaseEventsSubscriber)).analyticsEventsModule(new AnalyticsEventsModule()).programmaticContextualTriggerFlowableModule(new ProgrammaticContextualTriggerFlowableModule(new ProgramaticContextualTriggers())).build();
    AppComponent instance = DaggerAppComponent.builder().abtIntegrationHelper(new AbtIntegrationHelper(container.get(AbtComponent.class).get(FirebaseABTesting.OriginService.INAPP_MESSAGING))).apiClientModule(new ApiClientModule(firebaseApp, firebaseInstallations, universalComponent.clock())).grpcClientModule(new GrpcClientModule(firebaseApp)).universalComponent(universalComponent).transportFactory(container.get(TransportFactory.class)).build();
    return instance.providesFirebaseInAppMessaging();
}
Also used : ProgrammaticContextualTriggerFlowableModule(com.google.firebase.inappmessaging.internal.injection.modules.ProgrammaticContextualTriggerFlowableModule) ProgramaticContextualTriggers(com.google.firebase.inappmessaging.internal.ProgramaticContextualTriggers) AnalyticsEventsModule(com.google.firebase.inappmessaging.internal.injection.modules.AnalyticsEventsModule) AppMeasurementModule(com.google.firebase.inappmessaging.internal.injection.modules.AppMeasurementModule) ApiClientModule(com.google.firebase.inappmessaging.internal.injection.modules.ApiClientModule) GrpcClientModule(com.google.firebase.inappmessaging.internal.injection.modules.GrpcClientModule) AnalyticsConnector(com.google.firebase.analytics.connector.AnalyticsConnector) ApplicationModule(com.google.firebase.inappmessaging.internal.injection.modules.ApplicationModule) Subscriber(com.google.firebase.events.Subscriber) AppComponent(com.google.firebase.inappmessaging.internal.injection.components.AppComponent) DaggerAppComponent(com.google.firebase.inappmessaging.internal.injection.components.DaggerAppComponent) AbtIntegrationHelper(com.google.firebase.inappmessaging.internal.AbtIntegrationHelper) FirebaseInstallationsApi(com.google.firebase.installations.FirebaseInstallationsApi) Application(android.app.Application) DaggerUniversalComponent(com.google.firebase.inappmessaging.internal.injection.components.DaggerUniversalComponent) UniversalComponent(com.google.firebase.inappmessaging.internal.injection.components.UniversalComponent) FirebaseApp(com.google.firebase.FirebaseApp)

Aggregations

AnalyticsConnector (com.google.firebase.analytics.connector.AnalyticsConnector)16 Test (org.junit.Test)7 Bundle (android.os.Bundle)6 Matchers.anyString (org.mockito.Matchers.anyString)4 FirebaseApp (com.google.firebase.FirebaseApp)3 NonNull (androidx.annotation.NonNull)2 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)2 AnalyticsConnectorHandle (com.google.firebase.analytics.connector.AnalyticsConnector.AnalyticsConnectorHandle)2 AnalyticsConnectorListener (com.google.firebase.analytics.connector.AnalyticsConnector.AnalyticsConnectorListener)2 CrashlyticsNativeComponent (com.google.firebase.crashlytics.internal.CrashlyticsNativeComponent)2 Deferred (com.google.firebase.inject.Deferred)2 FirebaseInstallationsApi (com.google.firebase.installations.FirebaseInstallationsApi)2 Collections (java.util.Collections)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2 JSONObject (org.json.JSONObject)2 Before (org.junit.Before)2 RunWith (org.junit.runner.RunWith)2 Matchers.any (org.mockito.Matchers.any)2 Mockito.mock (org.mockito.Mockito.mock)2