Search in sources :

Example 11 with AnalyticsConnector

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);
}
Also used : JSONObject(org.json.JSONObject) AnalyticsConnector(com.google.firebase.analytics.connector.AnalyticsConnector) Test(org.junit.Test)

Example 12 with AnalyticsConnector

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"));
}
Also used : AnalyticsConnectorListener(com.google.firebase.analytics.connector.AnalyticsConnector.AnalyticsConnectorListener) Bundle(android.os.Bundle) AnalyticsConnectorHandle(com.google.firebase.analytics.connector.AnalyticsConnector.AnalyticsConnectorHandle) NonNull(androidx.annotation.NonNull) RunWith(org.junit.runner.RunWith) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) Matchers.anyString(org.mockito.Matchers.anyString) AnalyticsConnectorListener(com.google.firebase.analytics.connector.AnalyticsConnector.AnalyticsConnectorListener) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) Mockito.never(org.mockito.Mockito.never) AnalyticsConnector(com.google.firebase.analytics.connector.AnalyticsConnector) Deferred(com.google.firebase.inject.Deferred) Collections(java.util.Collections) LinkedHashSet(java.util.LinkedHashSet) Mockito.mock(org.mockito.Mockito.mock) Before(org.junit.Before) AnalyticsConnectorHandle(com.google.firebase.analytics.connector.AnalyticsConnector.AnalyticsConnectorHandle) AnalyticsConnector(com.google.firebase.analytics.connector.AnalyticsConnector) Test(org.junit.Test)

Example 13 with AnalyticsConnector

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"));
}
Also used : AnalyticsConnectorListener(com.google.firebase.analytics.connector.AnalyticsConnector.AnalyticsConnectorListener) Bundle(android.os.Bundle) AnalyticsConnectorHandle(com.google.firebase.analytics.connector.AnalyticsConnector.AnalyticsConnectorHandle) NonNull(androidx.annotation.NonNull) RunWith(org.junit.runner.RunWith) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) Matchers.anyString(org.mockito.Matchers.anyString) AnalyticsConnectorListener(com.google.firebase.analytics.connector.AnalyticsConnector.AnalyticsConnectorListener) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) Mockito.never(org.mockito.Mockito.never) AnalyticsConnector(com.google.firebase.analytics.connector.AnalyticsConnector) Deferred(com.google.firebase.inject.Deferred) Collections(java.util.Collections) LinkedHashSet(java.util.LinkedHashSet) Mockito.mock(org.mockito.Mockito.mock) Before(org.junit.Before) AnalyticsConnectorHandle(com.google.firebase.analytics.connector.AnalyticsConnector.AnalyticsConnectorHandle) AnalyticsConnector(com.google.firebase.analytics.connector.AnalyticsConnector) Test(org.junit.Test)

Example 14 with AnalyticsConnector

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);
}
Also used : Bundle(android.os.Bundle) Matchers.anyString(org.mockito.Matchers.anyString) AnalyticsConnector(com.google.firebase.analytics.connector.AnalyticsConnector) Test(org.junit.Test)

Example 15 with AnalyticsConnector

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");
        }
    }
}
Also used : Bundle(android.os.Bundle) AnalyticsConnector(com.google.firebase.analytics.connector.AnalyticsConnector)

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