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.
}
});
}
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;
}
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);
}
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);
}
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();
}
Aggregations