Analytics extends AirshipComponent { public void addEvent(@NonNull final Event event) { if (event == null || !event.isValid()) { Logger.error("Analytics - Invalid event: %s", event); return; } if (!isEnabled() || !isDataCollectionEnabled()) { Logger.debug("Analytics - Disabled ignoring event: %s", event.getType()); return; } Logger.verbose("Analytics - Adding event: %s", event.getType()); executor.execute(new Runnable() { @Override public void run() { eventManager.addEvent(event, sessionId); } }); applyListeners(event); } Analytics(@NonNull Context context,
                     @NonNull PreferenceDataStore dataStore,
                     @NonNull AirshipRuntimeConfig runtimeConfig,
                     @NonNull AirshipChannel channel,
                     @NonNull LocaleManager localeManager); @VisibleForTesting  Analytics(@NonNull Context context,
              @NonNull PreferenceDataStore dataStore,
              @NonNull AirshipRuntimeConfig runtimeConfig,
              @NonNull AirshipChannel airshipChannel,
              @NonNull ActivityMonitor activityMonitor,
              @NonNull LocaleManager localeManager,
              @NonNull Executor executor,
              @NonNull EventManager eventManager); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void addHeaderDelegate(@NonNull AnalyticsHeaderDelegate headerDelegate); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void addEventListener(@NonNull EventListener eventListener); @Override @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @AirshipComponentGroups.Group int getComponentGroup(); @Override @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @JobInfo.JobResult int onPerformJob(@NonNull UAirship airship, @NonNull JobInfo jobInfo); boolean isAppInForeground(); void addEvent(@NonNull final Event event); @Nullable String getConversionSendId(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void setConversionSendId(@Nullable String sendId); @Nullable @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) String getConversionMetadata(); void setConversionMetadata(@Nullable String metadata); @NonNull String getSessionId(); void setEnabled(boolean enabled); boolean isEnabled(); @NonNull AssociatedIdentifiers.Editor editAssociatedIdentifiers(); @NonNull AssociatedIdentifiers getAssociatedIdentifiers(); void trackScreen(@Nullable String screen); void uploadEvents(); void addAnalyticsListener(@NonNull AnalyticsListener analyticsListener); void removeAnalyticsListener(@NonNull AnalyticsListener analyticsListener); void registerSDKExtension(@ExtensionName @NonNull String extension, @NonNull String version); @NonNull
    static final String EXTENSION_CORDOVA; @NonNull
    static final String EXTENSION_FLUTTER; @NonNull
    static final String EXTENSION_REACT_NATIVE; @NonNull
    static final String EXTENSION_UNITY; @NonNull
    static final String EXTENSION_XAMARIN; @NonNull
    static final String EXTENSION_TITANIUM; }
@Test public void testAddEvent() { CustomEvent event = CustomEvent.newBuilder("cool").build(); analytics.addEvent(event); verify(mockEventManager).addEvent(event, analytics.getSessionId()); }
@Test public void testAddEventDisabledAnalyticsConfig() { AirshipConfigOptions options = new AirshipConfigOptions.Builder() .setDevelopmentAppKey("appKey") .setDevelopmentAppSecret("appSecret") .setAnalyticsEnabled(false) .build(); runtimeConfig.setConfigOptions(options); analytics.addEvent(new AppForegroundEvent(100)); verifyZeroInteractions(mockEventManager); }
@Test public void testAddNullEvent() { analytics.addEvent(null); verifyZeroInteractions(mockEventManager); }
@Test public void testAddInvalidEvent() { Event event = Mockito.mock(Event.class); when(event.getEventId()).thenReturn("event-id"); when(event.getType()).thenReturn("event-type"); when(event.createEventPayload(Mockito.anyString())).thenReturn("event-data"); when(event.getEventId()).thenReturn("event-id"); when(event.getTime()).thenReturn("1000"); when(event.getPriority()).thenReturn(Event.HIGH_PRIORITY); when(event.isValid()).thenReturn(false); analytics.addEvent(event); verifyZeroInteractions(mockJobDispatcher); }