.thenReturn(mMockSharedPreferencesEditor); Mockito.when(GoogleAnalytics.builder()) .thenReturn(new SpyGoogleAnalyticsBuilder());
/** * 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(); }
/** * 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(); } }
/** * 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()); }
private void forcePost(GoogleAnalyticsRequest request) { ga.postAsync(request); } }
@Override public void initComponent() { applicationInfo = ApplicationInfo.getInstance(); AnalyticsListener.init(); ga = new CustomGoogleAnalytics(TRACKING_ID); ga.getConfig().setValidate(GraphConstants.IS_DEVELOPMENT); sessionStart(); ApplicationManager.getApplication().addApplicationListener(new ApplicationAdapter() { @Override public void applicationExiting() { sessionEnd(); } }); }
@Override public void disposeComponent() { ga.close(); }
protected ThreadPoolExecutor getExecutor() { if (executor == null) { executor = createExecutor(config); } return executor; }
private AnalyticsReporting(IPermission permission) { if (permission.check()) this.ga = new GoogleAnalytics("UA-57580474-6"); else this.ga = null; this.appname = GlobalConf.APPLICATION_NAME; this.languagetag = I18n.locale.toLanguageTag().toLowerCase(); this.version = GlobalConf.version.version + "." + GlobalConf.version.build; this.permission = permission; }
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); }
private void post(GoogleAnalyticsRequest request) { if (SettingsComponent.getInstance().isAnalyticEnabled()) { ga.postAsync(request); } }
@Override public void close() { try { getExecutor().awaitTermination(2, TimeUnit.SECONDS); } catch (InterruptedException e) { // ignore } super.close(); } }
.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)
@Override public void sendMicroserviceStopped(IMicroservice<?> microservice) throws SiteWhereException { try { getGoogleAnalytics().event().eventCategory("Microservice_" + microservice.getIdentifier().getShortName()) .eventAction("Stopped").eventLabel(microservice.getVersion().getVersionIdentifier()).send(); } catch (Throwable t) { microservice.getLogger().warn("Unable to send Google Analytics stopped event.", t); } }
public Future<GoogleAnalyticsResponse> sendStartAppReport() { if (!permission.check()) return null; PageViewHit pvh = new PageViewHit("http://gaiasky.com", appname + " start"); pvh.applicationName(appname); pvh.applicationVersion(version); pvh.userLanguage(languagetag); pvh.documentPath("/start"); startTimeMs = TimeUtils.millis(); return ga.postAsync(pvh); }
public MicroserviceAnalytics() { googleAnalytics = GoogleAnalytics.builder().withTrackingId(SITEWHERE_RUNTIME_TRACKING).build(); }
@Override public void sendMicroserviceStarted(IMicroservice<?> microservice) throws SiteWhereException { try { getGoogleAnalytics().event().eventCategory("Microservice_" + microservice.getIdentifier().getShortName()) .eventAction("Started").eventLabel(microservice.getVersion().getVersionIdentifier()).send(); } catch (Throwable t) { microservice.getLogger().warn("Unable to send Google Analytics started event.", t); } }
public Future<GoogleAnalyticsResponse> sendTimingAppReport() { if (!permission.check()) return null; TimingHit th = new TimingHit(); th.applicationName(appname); th.applicationVersion(version); th.userLanguage(languagetag); th.pageLoadTime((int) (TimeUtils.millis() - startTimeMs)); return ga.postAsync(th); }
@Override public void sendMicroserviceUptime(IMicroservice<?> microservice) throws SiteWhereException { try { getGoogleAnalytics().event().eventCategory("Microservice_" + microservice.getIdentifier().getShortName()) .eventAction("Uptime").eventLabel(microservice.getVersion().getVersionIdentifier()) .eventValue((int) microservice.getCurrentState().getUptime()).send(); } catch (Throwable t) { microservice.getLogger().warn("Unable to send Google Analytics uptime event.", t); } }