/** * Allow users to enable or disable analytics * * @param optIn true allows collection of analytics information */ synchronized private static void setOptIn(boolean optIn) { Timber.i("setOptIn(): from %s to %s", sOptIn, optIn); sOptIn = optIn; sAnalytics.flush(); sAnalytics.getConfig().setEnabled(optIn); sAnalytics.performSamplingElection(); Timber.d("setOptIn() optIn / sAnalytics.config().enabled(): %s/%s", sOptIn, sAnalytics.getConfig().isEnabled()); }
/** * Send an exception event out for aggregation/analysis * * @param description API limited to 100 characters, truncated here to 100 if needed * @param fatal whether it was fatal or not */ @SuppressWarnings("WeakerAccess") public static void sendAnalyticsException(@NonNull String description, boolean fatal) { Timber.d("sendAnalyticsException() description/fatal: %s/%s", description, fatal); if (!sOptIn) { return; } sAnalytics.exception().exceptionDescription(description).exceptionFatal(fatal).sendAsync(); } }
/** * Submit a screen display with a synthetic name for aggregation / analysis * Intended for use if your class handles multiple screens you want to track separately * * @param screenName screenName the name to show in analysis reports */ public static void sendAnalyticsScreenView(String screenName) { Timber.d("sendAnalyticsScreenView(): %s", screenName); if (!getOptIn()) { return; } sAnalytics.screenView().screenName(screenName).sendAsync(); }
if (sAnalytics == null) { Timber.d("App tracking id 'tid' = %s", getAnalyticsTag(context)); GoogleAnalyticsConfig gaConfig = new GoogleAnalyticsConfig() .setBatchingEnabled(true) .setSamplePercentage(getAnalyticsSamplePercentage(context)) .setBatchSize(1); // until this handles application termination we will lose hits if batch>1 sAnalytics = GoogleAnalytics.builder() .withTrackingId(getAnalyticsTag(context)) .withConfig(gaConfig) .withDefaultRequest(new DefaultRequest() .applicationName(context.getString(R.string.app_name)) .applicationVersion(Integer.toString(BuildConfig.VERSION_CODE)) .applicationId(BuildConfig.APPLICATION_ID) .trackingId(getAnalyticsTag(context)) .clientId(Installation.id(context)) .anonymizeIp(context.getResources().getBoolean(R.bool.ga_anonymizeIp)) .withHttpClient(new OkHttpClientImpl(gaConfig)) .build();
/** * Send a detailed arbitrary analytics event, with noun/verb pairs and extra data if needed * * @param category the category of event, make your own but use a constant so reporting is good * @param action the action the user performed * @param value A value for the event, Integer.MIN_VALUE signifies caller shouldn't send the value * @param label A label for the event, may be null */ @SuppressWarnings("WeakerAccess") public static void sendAnalyticsEvent(@NonNull String category, @NonNull String action, int value, String label) { Timber.d("sendAnalyticsEvent() category/action/value/label: %s/%s/%s/%s", category, action, value, label); if (!getOptIn()) { return; } EventHit event = sAnalytics.event().eventCategory(category).eventAction(action); if (label != null) { event.eventLabel(label); } if (value > Integer.MIN_VALUE) { event.eventValue(value); } event.sendAsync(); }
ExceptionHit spyHit = Mockito.spy(new ExceptionHit()); Mockito.doReturn(spyHit).when(mAnalytics).exception(); Mockito.verify(parentException).getCause(); Mockito.verify(childException).getCause(); Mockito.verify(mAnalytics).exception(); Mockito.verify(spyHit).exceptionDescription(ArgumentMatchers.anyString()); Mockito.verify(spyHit).sendAsync(); Assert.assertEquals(spyHit.exceptionDescription(), "child exception toString()");
public GoogleAnalytics(GoogleAnalyticsConfig config, DefaultRequest defaultRequest) { if (config.isDiscoverRequestParameters() && config.getRequestParameterDiscoverer() != null) { config.getRequestParameterDiscoverer().discoverParameters(config, defaultRequest); } this.config = config; this.defaultRequest = defaultRequest; this.defaultRequest.userAgent(config.getUserAgent()); this.httpClient = createHttpClient(config); }
public GoogleAnalytics(String trackingId) { this(new GoogleAnalyticsConfig(), new DefaultRequest().trackingId(trackingId)); }
public MicroserviceAnalytics() { googleAnalytics = GoogleAnalytics.builder().withTrackingId(SITEWHERE_RUNTIME_TRACKING).build(); }
public GoogleAnalyticsServiceImpl() { super(new GoogleAnalyticsConfig(), new DefaultRequest()); }
public GoogleAnalytics build() { GoogleAnalytics analytics = super.build(); return Mockito.spy(analytics); } }
.thenReturn(mMockSharedPreferencesEditor); Mockito.when(GoogleAnalytics.builder()) .thenReturn(new SpyGoogleAnalyticsBuilder());
protected ThreadFactory createThreadFactory() { return new GoogleAnalyticsThreadFactory(config.getThreadNameFormat()); }
public PageViewHit(String url, String title, String description) { super("pageview"); documentUrl(url); documentTitle(title); contentDescription(description); } }
public ScreenViewHit(String applicationName, String applicationVersion, String contentDescription) { super("screenview"); applicationName(applicationName); applicationVersion(applicationVersion); contentDescription(contentDescription); }
public GoogleAnalyticsResponse call() throws Exception { try { @SuppressWarnings("rawtypes") GoogleAnalyticsRequest request = requestProvider.getRequest(); if (request != null) { return post(request); } } catch (Exception e) { // logger.warn("Request Provider (" + requestProvider + ") thrown exception " + e.toString() + " and hence nothing is posted to GA."); } return null; } });
public ExceptionHit(String exceptionDescription, Boolean fatal) { super("exception"); exceptionDescription(exceptionDescription); exceptionFatal(fatal); }
/** * @deprecated Use {@link #customDimension(int)} instead */ public String customDimention(int index) { return customDimension(index); }
/** * Re-Initialize the analytics provider */ synchronized public static void reInitialize() { // send any pending async hits, re-chain default exception handlers and re-init Timber.i("reInitialize()"); sAnalytics.flush(); sAnalytics = null; unInstallDefaultExceptionHandler(); initialize(AnkiDroidApp.getInstance().getApplicationContext()); }
/** * IP Override * parameter: uip * Should be a valid IP address. This will always be anonymized just as though &aip (anonymize IP) had been used. * example: &uip=1.2.3.4 */ public T userIp(String value) { setString(GoogleAnalyticsParameter.USER_IP, value); return (T) this; }