com.google.android.gms.analytics.GoogleAnalytics Java Examples

The following examples show how to use com.google.android.gms.analytics.GoogleAnalytics. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnalyticsUtil.java    From IndiaSatelliteWeather with GNU General Public License v2.0 6 votes vote down vote up
public void initializeGATracker() {

        // Set dryRun flag.
        GoogleAnalytics.getInstance(context).setDryRun(GA_IS_DRY_RUN);

        // Set the log level to verbose if dryRun.
        // DEFAULT is set to DRY RUN (only logging will happen)
        GoogleAnalytics.getInstance(context).getLogger()
                .setLogLevel(GA_IS_DRY_RUN ? Logger.LogLevel.VERBOSE : Logger.LogLevel.WARNING);

        // Set the opt out flag when user updates a tracking preference.
        /*
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        sp.registerOnSharedPreferenceChangeListener(
                new SharedPreferences.OnSharedPreferenceChangeListener() {
                    @Override
                    public void onSharedPreferenceChanged(SharedPreferences pref, String key) {
                        if (key.equals(TRACKING_PREF_KEY)) {
                            GoogleAnalytics.getInstance(getApplicationContext()).setAppOptOut(
                                    pref.getBoolean(key, false));
                        }
                    }
                });
                */
    }
 
Example #2
Source File: HomeActivity.java    From microbit with Apache License 2.0 6 votes vote down vote up
/**
 * Allows to turn on/off sharing statistics ability.
 */
private void toggleShareStatistics() {
    if(mShareStatsCheckBox == null) {
        return;
    }
    boolean shareStatistics = mShareStatsCheckBox.isChecked();

    if(shareStatistics) {
        GoogleAnalytics.getInstance(this).reportActivityStart(this);
    } else {
        GoogleAnalytics.getInstance(this).reportActivityStop(this);
    }

    mPrefs.edit().putBoolean(getString(R.string.prefs_share_stats_status), shareStatistics).apply();
    logi("shareStatistics = " + shareStatistics);
    GoogleAnalyticsManager.getInstance().setShareStatistic(shareStatistics);
    GoogleAnalyticsManager.getInstance().
            sendStatSharing(HomeActivity.class.getSimpleName(), shareStatistics);
}
 
Example #3
Source File: MyApplication.java    From GAlette with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    GoogleAnalytics ga = GoogleAnalytics.getInstance(this);
    ga.setLocalDispatchPeriod(1);

    // To enable debug logging on a device run:
    // adb shell setprop log.tag.GAv4 DEBUG
    // adb logcat -s GAv4

    // Logger is deprecated. To enable debug logging, please run:
    // adb shell setprop log.tag.GAv4 DEBUG
    // ga.getLogger().setLogLevel(Logger.LogLevel.VERBOSE);

    mTracker = ga.newTracker("SET-YOUR-TRACKING-ID");
}
 
Example #4
Source File: MyApp.java    From hello-world-android-app with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    analytics = GoogleAnalytics.getInstance(this);

    // TODO: Replace the tracker-id with your app one from https://www.google.com/analytics/web/
    tracker = analytics.newTracker("UA-54478999-1");

    // Provide unhandled exceptions reports. Do that first after creating the tracker
    tracker.enableExceptionReporting(true);

    // Enable Remarketing, Demographics & Interests reports
    // https://developers.google.com/analytics/devguides/collection/android/display-features
    tracker.enableAdvertisingIdCollection(true);

    // Enable automatic activity tracking for your app
    tracker.enableAutoActivityTracking(true);
}
 
Example #5
Source File: GoogleAnalyticsManager.java    From barterli_android with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the tracker
 */
private void initTracker() {

    final Context context = BarterLiApplication.getStaticContext();

    if (!BuildConfig.REPORT_GOOGLE_ANALYTICS) {
        GoogleAnalytics.getInstance(context).setDryRun(true);
        GoogleAnalytics.getInstance(context).getLogger()
                .setLogLevel(Logger.LogLevel.VERBOSE);
    } else {
        GoogleAnalytics.getInstance(context).setDryRun(false);
        GoogleAnalytics.getInstance(context).getLogger()
                .setLogLevel(Logger.LogLevel.ERROR);
    }
    mApplicationTracker = GoogleAnalytics.getInstance(context)
            .newTracker(context.getString(R.string.ga_tracking_id));

    //We will track manually since we use Fragments
    mApplicationTracker.enableAutoActivityTracking(false);
    mApplicationTracker.setSessionTimeout(SESSION_TIMEOUT);

}
 
Example #6
Source File: MyApp.java    From cute-pets-example-android-app with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    analytics = GoogleAnalytics.getInstance(this);

    // TODO: Replace the tracker-id with your app one from https://www.google.com/analytics/web/
    tracker = analytics.newTracker("UA-54478999-3");

    // Provide unhandled exceptions reports. Do that first after creating the tracker
    tracker.enableExceptionReporting(true);

    // Enable Remarketing, Demographics & Interests reports
    // https://developers.google.com/analytics/devguides/collection/android/display-features
    tracker.enableAdvertisingIdCollection(true);

    // Enable automatic activity tracking for your app
    tracker.enableAutoActivityTracking(true);

    tracker.send(new HitBuilders.ScreenViewBuilder().setCustomDimension(1, null).build());
}
 
Example #7
Source File: Analytics.java    From matrix-android-console with Apache License 2.0 6 votes vote down vote up
/**
 * Initialise Google Analytics immediately so it will catch all sorts of errors prior to EasyTracker onStart. Also makes sensible
 * exception stack traces if you want.
 * @param context App context
 * @param trackerId The tracker ID to use.
 * @return A GoogleAnalytics reference
 */
public static GoogleAnalytics initialiseGoogleAnalytics(Context context, String trackerId, final ExceptionParser callback) {
    mAnalytics = GoogleAnalytics.getInstance(context);
    mAnalytics.setLocalDispatchPeriod(1800);

    mTracker = mAnalytics.newTracker(trackerId);
    mTracker.enableExceptionReporting(true);
    //mTracker.enableAdvertisingIdCollection(true);
    mTracker.enableAutoActivityTracking(true);

    // overwrite the exception parser to be more useful.
    Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
    if (handler != null && handler instanceof ExceptionReporter) { // this handler is the GA one
        ExceptionReporter exceptionReporter = (ExceptionReporter)handler;
        exceptionReporter.setExceptionParser(callback);
        Thread.setDefaultUncaughtExceptionHandler(exceptionReporter);

        Log.d(LOG_TAG, "Analytics active.");
    }
    else {
        Log.e(LOG_TAG, "Cannot set custom exception parser.");
    }

    return mAnalytics;
}
 
Example #8
Source File: MainApplication.java    From android_gisapp with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public void onCreate() {
        if (!BuildConfig.DEBUG)
            Sentry.init(this, BuildConfig.SENTRY_DSN);
//        Sentry.captureMessage("NGM2 Sentry is init.", Sentry.SentryEventLevel.DEBUG);

        mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

        GoogleAnalytics.getInstance(this).setAppOptOut(!mSharedPreferences.getBoolean(KEY_PREF_GA, true));
        GoogleAnalytics.getInstance(this).setDryRun(DEBUG_MODE);
        getTracker();
        setExceptionHandler();

        super.onCreate();
        updateFromOldVersion();
    }
 
Example #9
Source File: ShadowsocksApplication.java    From ShadowsocksRR with Apache License 2.0 6 votes vote down vote up
/**
 * /// xhao: init variable
 */
private void initVariable() {
    tracker = GoogleAnalytics.getInstance(this).newTracker(R.xml.tracker);
    settings = PreferenceManager.getDefaultSharedPreferences(this);
    editor = settings.edit();

    profileManager = new ProfileManager(new DBHelper(this));
    ssrsubManager = new SSRSubManager(new DBHelper(this));
    resources = getResources();

    mThreadPool = new ScheduledThreadPoolExecutor(10, new ThreadFactory() {
        @Override
        public Thread newThread(@NonNull Runnable r) {
            Thread thread = new Thread(r);
            thread.setName("shadowsocks-thread");
            return thread;
        }
    });
}
 
Example #10
Source File: MiracastApplication.java    From miracast-widget with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the default {@link Tracker} for this {@link Application}.
 * @return tracker
 */
synchronized public Tracker getDefaultTracker() {
    if (mTracker == null) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
        mTracker = analytics.newTracker(R.xml.global_tracker);
    }
    return mTracker;
}
 
Example #11
Source File: BaseApplication.java    From example with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the default {@link Tracker} for this {@link Application}.
 *
 * @return tracker
 */
synchronized public Tracker getDefaultTracker() {
  if (mTracker == null) {
    GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
    // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
    mTracker = analytics.newTracker(R.xml.global_tracker);
  }
  return mTracker;
}
 
Example #12
Source File: OnesearchApp.java    From Onesearch with MIT License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    // Enabling Advertising Features in Google Analytics allows you to take advantage of
    // Remarketing, Demographics & Interests reports, and more.
    Tracker t = getTracker(TrackerName.APP_TRACKER);
    t.enableAdvertisingIdCollection(true);

    if(BuildConfig.DEBUG) {
        GoogleAnalytics.getInstance(this).getLogger().setLogLevel(Logger.LogLevel.VERBOSE);
        GoogleAnalytics.getInstance(this).setDryRun(true);
    }
}
 
Example #13
Source File: OnesearchApp.java    From Onesearch with MIT License 5 votes vote down vote up
public synchronized Tracker getTracker(TrackerName trackerId) {
    if (!mTrackers.containsKey(trackerId)) {

        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID)
                : analytics.newTracker(R.xml.global_tracker);
        mTrackers.put(trackerId, t);

    }
    return mTrackers.get(trackerId);
}
 
Example #14
Source File: NotificationSender.java    From PressureNet with GNU General Public License v3.0 5 votes vote down vote up
synchronized Tracker getTracker(TrackerName trackerId) {
  if (!mTrackers.containsKey(trackerId)) {

    GoogleAnalytics analytics = GoogleAnalytics.getInstance(mContext);
    Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PressureNETConfiguration.GA_TOKEN)
        : (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.global_tracker)
            : analytics.newTracker(R.xml.global_tracker);
    mTrackers.put(trackerId, t);

  }
  return mTrackers.get(trackerId);
}
 
Example #15
Source File: MainActivity.java    From Smartlab with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	
	GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
	Tracker t = analytics.newTracker("UA-43986081-2");	
	t.send(new HitBuilders.AppViewBuilder().build());
}
 
Example #16
Source File: GoogleAnalyticsHelper.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
public static void pushAnalyticsData(Context context, QBUser user, String action) {
    GoogleAnalytics analytics = GoogleAnalytics.getInstance(context);
    Tracker tracker = analytics.newTracker(context.getString(R.string.google_analytics_tracking_id));

    // You only need to set User ID on a tracker once. By setting it on the tracker, the ID will be
    // sent with all subsequent hits.
    tracker.set("&uid", String.valueOf(user.getId()));
    // This hit will be sent with the User ID value and be visible in User-ID-enabled views (profiles).
    tracker.send(new HitBuilders.EventBuilder().setCategory("UX").setAction(action).build());
}
 
Example #17
Source File: MiracastApplication.java    From miracast-widget with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the default {@link Tracker} for this {@link Application}.
 * @return tracker
 */
synchronized public Tracker getDefaultTracker() {
    if (mTracker == null) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
        mTracker = analytics.newTracker(R.xml.global_tracker);
    }
    return mTracker;
}
 
Example #18
Source File: TelecineModule.java    From Telecine with Apache License 2.0 5 votes vote down vote up
@Provides @Singleton static Analytics provideAnalytics(Application app) {
  if (BuildConfig.DEBUG) {
    return new Analytics() {
      @Override public void send(Map<String, String> params) {
        Timber.tag("Analytics").d(String.valueOf(params));
      }
    };
  }

  GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(app);
  Tracker tracker = googleAnalytics.newTracker(BuildConfig.ANALYTICS_KEY);
  tracker.setSessionTimeout(300); // ms? s? better be s.
  return new Analytics.GoogleAnalytics(tracker);
}
 
Example #19
Source File: AppModule.java    From droidkaigi2016 with Apache License 2.0 5 votes vote down vote up
@Singleton
@Provides
public Tracker provideGoogleAnalyticsTracker(Context context) {
    GoogleAnalytics ga = GoogleAnalytics.getInstance(context);
    Tracker tracker = ga.newTracker(BuildConfig.GA_TRACKING_ID);
    tracker.enableAdvertisingIdCollection(true);
    tracker.enableExceptionReporting(true);
    return tracker;
}
 
Example #20
Source File: AnalyticsUnitTest.java    From openshop.io-android with MIT License 5 votes vote down vote up
private void prepareMockedFields() throws Exception {
    // Mock responses
    PowerMockito.mockStatic(GoogleAnalytics.class);
    PowerMockito.mockStatic(AppEventsLogger.class);
    doReturn(mockAnalytics).when(GoogleAnalytics.class, "getInstance", mockContext);
    doReturn(mockAppEventsLogger).when(AppEventsLogger.class, "newLogger", anyObject());
    when(mockAnalytics.newTracker(R.xml.global_tracker)).thenReturn(mockTracker);
    when(mockAnalytics.newTracker(testShop.getGoogleUa())).thenReturn(mockTrackerApp);
}
 
Example #21
Source File: AnalyticsUtil.java    From IndiaSatelliteWeather with GNU General Public License v2.0 5 votes vote down vote up
public synchronized Tracker getTracker() {
    if (gaTracker == null) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(context);
        gaTracker = analytics.newTracker(GLOBAL_PROPERTY_ID);
    }
    return gaTracker;
}
 
Example #22
Source File: PrkngApp.java    From android with MIT License 5 votes vote down vote up
/**
 * Gets the default {@link Tracker} for this {@link Application}.
 *
 * @return tracker
 */
synchronized public Tracker getAnalyticsTracker() {
    if (mTracker == null) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        analytics.setDryRun(!BuildConfig.USE_ANALYTICS);
        mTracker = analytics.newTracker(getString(R.string.google_analytics_property));
        mTracker.enableAutoActivityTracking(false);
    }
    return mTracker;
}
 
Example #23
Source File: NoyzeApp.java    From Noyze with Apache License 2.0 5 votes vote down vote up
synchronized Tracker getTracker(TrackerName trackerId) {
    if (!mTrackers.containsKey(trackerId)) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker("UA-41252760-2")
                : (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.global_tracker)
                : analytics.newTracker(R.xml.global_tracker);
        t.enableAdvertisingIdCollection(false);
        t.setAnonymizeIp(true);
        t.setUseSecure(true);
        mTrackers.put(trackerId, t);

    }
    return mTrackers.get(trackerId);
}
 
Example #24
Source File: ClimbTrackerApplication.java    From climb-tracker with Apache License 2.0 5 votes vote down vote up
synchronized public Tracker getDefaultTracker() {
    if (mTracker == null) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        mTracker = analytics.newTracker(R.xml.global_tracker);
    }
    return mTracker;
}
 
Example #25
Source File: MovieCheckApplication.java    From Movie-Check with Apache License 2.0 5 votes vote down vote up
synchronized public Tracker getDefaultTracker() {
    if (mTracker == null) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        mTracker = analytics.newTracker(R.xml.global_tracker);
    }
    return mTracker;
}
 
Example #26
Source File: AppModule.java    From droidkaigi2016 with Apache License 2.0 5 votes vote down vote up
@Singleton
@Provides
public Tracker provideGoogleAnalyticsTracker(Context context) {
    GoogleAnalytics ga = GoogleAnalytics.getInstance(context);
    Tracker tracker = ga.newTracker(BuildConfig.GA_TRACKING_ID);
    tracker.enableAdvertisingIdCollection(true);
    tracker.enableExceptionReporting(true);
    return tracker;
}
 
Example #27
Source File: BaseApplication.java    From io16experiment-master with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the default {@link Tracker} for this {@link Application}.
 *
 * @return tracker
 */
synchronized public Tracker getDefaultTracker() {
    if (mTracker == null) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        analytics.setLocalDispatchPeriod(60);
        analytics.setDryRun(BuildConfig.DEBUG);

        mTracker = analytics.newTracker(R.xml.app_tracker);
        mTracker.enableAdvertisingIdCollection(true);
        mTracker.enableAutoActivityTracking(true);
        mTracker.enableExceptionReporting(true);
    }

    return mTracker;
}
 
Example #28
Source File: AnalyticsUnitTest.java    From openshop.io-android with MIT License 5 votes vote down vote up
@Test
public void prepareTrackersAndFbLoggerTest() throws Exception {
    prepareMockedFields();

    // Tested method invocation
    Analytics.prepareTrackersAndFbLogger(testShop, mockContext);

    // Verify results
    verifyStatic(times(1));
    GoogleAnalytics.getInstance(mockContext);
    verifyStatic(never());
    Analytics.deleteAppTrackers();

    verify(mockAnalytics, times(1)).newTracker(testShop.getGoogleUa());
    verify(mockAnalytics, times(1)).newTracker(R.xml.global_tracker);

    verify(mockTrackerApp, times(1)).enableAutoActivityTracking(true);
    verify(mockTrackerApp, times(1)).enableExceptionReporting(false);
    verify(mockTrackerApp, times(1)).enableAdvertisingIdCollection(true);
    verifyNoMoreInteractions(mockTrackerApp);

    verify(mockTracker, times(1)).enableAutoActivityTracking(true);
    verify(mockTracker, times(1)).enableExceptionReporting(true);
    verify(mockTracker, times(1)).enableAdvertisingIdCollection(true);
    verifyNoMoreInteractions(mockTracker);

    HashMap<String, Tracker> trackersField = Whitebox.getInternalState(Analytics.class, "mTrackers");
    assertEquals(trackersField.size(), 2);
    AppEventsLogger appEventsLoggerField = Whitebox.getInternalState(Analytics.class, "facebookLogger");
    assertNotEquals(appEventsLoggerField, null);
}
 
Example #29
Source File: AnalyticsUnitTest.java    From openshop.io-android with MIT License 5 votes vote down vote up
@Test
public void prepareGlobalTrackerAndFbLoggerTest() throws Exception {
    // Mock responses
    PowerMockito.mockStatic(GoogleAnalytics.class);
    PowerMockito.mockStatic(AppEventsLogger.class);
    doReturn(mockAnalytics).when(GoogleAnalytics.class, "getInstance", mockContext);
    doReturn(mockAppEventsLogger).when(AppEventsLogger.class, "newLogger", anyObject());
    when(mockAnalytics.newTracker(R.xml.global_tracker)).thenReturn(mockTracker);

    // Tested method invocation
    Analytics.prepareTrackersAndFbLogger(null, mockContext);

    // Verify results
    verifyStatic(times(1));
    GoogleAnalytics.getInstance(mockContext);
    verifyStatic(times(1));
    Analytics.deleteAppTrackers();

    verify(mockAnalytics, times(1)).newTracker(R.xml.global_tracker);

    verify(mockTracker, times(1)).enableAutoActivityTracking(true);
    verify(mockTracker, times(1)).enableExceptionReporting(true);
    verify(mockTracker, times(1)).enableAdvertisingIdCollection(true);
    verifyNoMoreInteractions(mockTracker);

    HashMap<String, Tracker> trackersField = Whitebox.getInternalState(Analytics.class, "mTrackers");
    assertEquals(trackersField.size(), 1);
    AppEventsLogger appEventsLoggerField = Whitebox.getInternalState(Analytics.class, "facebookLogger");
    assertNotEquals(appEventsLoggerField, null);
}
 
Example #30
Source File: AnalyticsHelper.java    From friendlyping with Apache License 2.0 5 votes vote down vote up
/**
 * Get the default {@link Tracker} for this {@link Application}.
 *
 * @return tracker
 */
public static synchronized Tracker getDefaultTracker(Context context) {
    if (mTracker == null) {
        GoogleAnalytics analytics = GoogleAnalytics
                .getInstance(context.getApplicationContext());
        analytics.getLogger().setLogLevel(Logger.LogLevel.VERBOSE);
        mTracker = analytics.newTracker(R.xml.global_tracker);
    }
    return mTracker;
}