use of com.google.firebase.analytics.connector.AnalyticsConnector in project firebase-android-sdk by firebase.
the class ConfigFetchHandlerTest method fetch_hasAnalyticsSdk_sendsUserPropertiesAndFirstOpenTime.
@Test
public void fetch_hasAnalyticsSdk_sendsUserPropertiesAndFirstOpenTime() throws Exception {
// Provide the mock Analytics SDK.
AnalyticsConnector mockAnalyticsConnector = mock(AnalyticsConnector.class);
fetchHandler = getNewFetchHandler(mockAnalyticsConnector);
long firstOpenTime = 1636146000000L;
Map<String, String> customUserProperties = ImmutableMap.of("up_key1", "up_val1", "up_key2", "up_val2");
Map<String, Object> allUserProperties = ImmutableMap.of("up_key1", "up_val1", "up_key2", "up_val2", FIRST_OPEN_TIME_KEY, firstOpenTime);
when(mockAnalyticsConnector.getUserProperties(/*includeInternal=*/
false)).thenReturn(ImmutableMap.copyOf(customUserProperties));
when(mockAnalyticsConnector.getUserProperties(/*includeInternal=*/
true)).thenReturn(ImmutableMap.copyOf(allUserProperties));
fetchCallToHttpClientUpdatesClockAndReturnsConfig(firstFetchedContainer);
assertWithMessage("Fetch() failed!").that(fetchHandler.fetch().isSuccessful()).isTrue();
verifyBackendIsCalled(customUserProperties, firstOpenTime);
}
use of com.google.firebase.analytics.connector.AnalyticsConnector in project firebase-android-sdk by firebase.
the class ProxyAnalyticsConnectorTest method registerListener_whenConnectorLoadsAfterRegistration_shouldPropagateRegistrationAndEventNames.
@Test
public void registerListener_whenConnectorLoadsAfterRegistration_shouldPropagateRegistrationAndEventNames() {
TestDeferred<AnalyticsConnector> testDeferred = new TestDeferred<>();
ProxyAnalyticsConnector proxy = new ProxyAnalyticsConnector(testDeferred);
AnalyticsConnectorListener listener = (i, bundle) -> {
};
AnalyticsConnectorHandle handle = proxy.registerAnalyticsConnectorListener("fiam", listener);
handle.registerEventNames(Collections.singleton("hello"));
testDeferred.provide(mockConnector);
verify(mockConnector).registerAnalyticsConnectorListener("fiam", listener);
verify(mockHandle, times(1)).registerEventNames(Collections.singleton("hello"));
}
use of com.google.firebase.analytics.connector.AnalyticsConnector in project firebase-android-sdk by firebase.
the class ProxyAnalyticsConnectorTest method registerListener_whenConnectorLoadsAfterUnRegistration_shouldNotPropagateRegistrationAndEventNames.
@Test
public void registerListener_whenConnectorLoadsAfterUnRegistration_shouldNotPropagateRegistrationAndEventNames() {
TestDeferred<AnalyticsConnector> testDeferred = new TestDeferred<>();
ProxyAnalyticsConnector proxy = new ProxyAnalyticsConnector(testDeferred);
AnalyticsConnectorListener listener = (i, bundle) -> {
};
AnalyticsConnectorHandle handle = proxy.registerAnalyticsConnectorListener("fiam", listener);
handle.unregister();
handle.registerEventNames(Collections.singleton("hello"));
testDeferred.provide(mockConnector);
verify(mockConnector, never()).registerAnalyticsConnectorListener("fiam", listener);
verify(mockHandle, never()).registerEventNames(Collections.singleton("hello"));
}
use of com.google.firebase.analytics.connector.AnalyticsConnector in project firebase-android-sdk by firebase.
the class ProxyAnalyticsConnectorTest method logEvent_whenConnectorIsAvailable_shouldDelegateToIt.
@Test
public void logEvent_whenConnectorIsAvailable_shouldDelegateToIt() {
TestDeferred<AnalyticsConnector> testDeferred = new TestDeferred<>();
ProxyAnalyticsConnector proxy = new ProxyAnalyticsConnector(testDeferred);
testDeferred.provide(mockConnector);
String s = "s";
String s1 = "s1";
Bundle b = new Bundle();
proxy.logEvent(s, s1, b);
verify(mockConnector, times(1)).logEvent(s, s1, b);
}
use of com.google.firebase.analytics.connector.AnalyticsConnector in project firebase-android-sdk by firebase.
the class MessagingAnalytics method setUserPropertyIfRequired.
/**
* Set the FIREBASE_LAST_NOTIFICATION user-property in Scion for conversion tracking.
*/
private static void setUserPropertyIfRequired(Bundle extras) {
if (extras == null) {
return;
}
// If the user requested to track conversions, set the user property.
String shouldTrackConversions = extras.getString(Constants.AnalyticsKeys.TRACK_CONVERSIONS);
if ("1".equals(shouldTrackConversions)) {
// TODO(b/78465387) Use components dependency framework to get analyticsConnector obj
@SuppressWarnings("FirebaseUseExplicitDependencies") AnalyticsConnector analytics = FirebaseApp.getInstance().get(AnalyticsConnector.class);
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Received event with track-conversion=true." + " Setting user property and reengagement event");
}
if (analytics != null) {
String composerId = extras.getString(Constants.AnalyticsKeys.COMPOSER_ID);
analytics.setUserProperty(ScionAnalytics.ORIGIN_FCM, ScionAnalytics.USER_PROPERTY_FIREBASE_LAST_NOTIFICATION, composerId);
// Also set the reengagement attribution
Bundle params = new Bundle();
params.putString(ScionAnalytics.PARAM_SOURCE, REENGAGEMENT_SOURCE);
params.putString(ScionAnalytics.PARAM_MEDIUM, REENGAGEMENT_MEDIUM);
params.putString(ScionAnalytics.PARAM_CAMPAIGN, composerId);
analytics.logEvent(ScionAnalytics.ORIGIN_FCM, ScionAnalytics.EVENT_FIREBASE_CAMPAIGN, params);
} else {
// Client did not include the measurement library
Log.w(TAG, "Unable to set user property for conversion tracking: " + " analytics library is missing");
}
} else {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Received event with track-conversion=false. Do not set user property");
}
}
}
Aggregations