Java Code Examples for com.google.android.gms.analytics.GoogleAnalytics#getInstance()
The following examples show how to use
com.google.android.gms.analytics.GoogleAnalytics#getInstance() .
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: Analytics.java From matrix-android-console with Apache License 2.0 | 6 votes |
/** * 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 2
Source File: MiracastApplication.java From miracast-widget with Apache License 2.0 | 5 votes |
/** * 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 3
Source File: GoogleAnalyticsHelper.java From q-municate-android with Apache License 2.0 | 5 votes |
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 4
Source File: AnalyticsUnitTest.java From openshop.io-android with MIT License | 5 votes |
@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 5
Source File: MiracastApplication.java From miracast-widget with Apache License 2.0 | 5 votes |
/** * 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 6
Source File: Analytics.java From openshop.io-android with MIT License | 5 votes |
/** * Prepare Google analytics trackers and Facebook events logger. * Send UTM campaign if exist. * * @param shop shop with app specific Google Ua or null, if global tracker is enough. * @param context application context. */ public static synchronized void prepareTrackersAndFbLogger(Shop shop, Context context) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(context); // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG if (shop == null) { deleteAppTrackers(); } else { if (!mTrackers.containsKey(TRACKER_APP) && analytics != null) { if (shop.getGoogleUa() != null && !shop.getGoogleUa().isEmpty()) { Timber.d("Set new app tracker with id: %s", shop.getGoogleUa()); // App tracker determined by shop Tracker appTracker = analytics.newTracker(shop.getGoogleUa()); appTracker.enableAutoActivityTracking(true); appTracker.enableExceptionReporting(false); appTracker.enableAdvertisingIdCollection(true); mTrackers.put(TRACKER_APP, appTracker); } else { Timber.e(new RuntimeException(), "Creating GA app tracker with empty Google UA"); } } else { Timber.e("Trackers for this app already exist."); } } // Add global tracker only one time. if (!mTrackers.containsKey(TRACKER_GLOBAL) && analytics != null) { Timber.d("Set new global tracker."); // Global app tracker Tracker appTrackerGlobal = analytics.newTracker(R.xml.global_tracker); appTrackerGlobal.enableAutoActivityTracking(true); appTrackerGlobal.enableExceptionReporting(true); appTrackerGlobal.enableAdvertisingIdCollection(true); mTrackers.put(TRACKER_GLOBAL, appTrackerGlobal); // Send camping info only once time. sendCampaignInfo(); } facebookLogger = AppEventsLogger.newLogger(MyApplication.getInstance()); }
Example 7
Source File: PressureNetApplication.java From PressureNet with GNU General Public License v3.0 | 5 votes |
synchronized Tracker getTracker(TrackerName trackerId) { if (!mTrackers.containsKey(trackerId)) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); 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 8
Source File: AnalyticsUtil.java From IndiaSatelliteWeather with GNU General Public License v2.0 | 5 votes |
public synchronized Tracker getTracker() { if (gaTracker == null) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(context); gaTracker = analytics.newTracker(GLOBAL_PROPERTY_ID); } return gaTracker; }
Example 9
Source File: PatrolApp.java From patrol-android with GNU General Public License v3.0 | 5 votes |
/** * Gets the default {@link Tracker} for this {@link Application}. * * @return tracker */ synchronized public Tracker getDefaultTracker() { try { if (mTracker == null) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG mTracker = analytics.newTracker("UA-44978148-14"); } } catch (Exception e){ e.printStackTrace(); } return mTracker; }
Example 10
Source File: GoogleProvider.java From android with Apache License 2.0 | 5 votes |
@Inject GoogleProvider(Context context) { GoogleAnalytics ga = GoogleAnalytics.getInstance(context); if (BuildConfig.DEBUG) { ga.setDryRun(true); } mTracker = ga.newTracker(context.getString(R.string.google_analytics_id)); mTracker.enableAdvertisingIdCollection(true); mTracker.enableAutoActivityTracking(false); }
Example 11
Source File: NavigationActivity.java From IdealMedia with Apache License 2.0 | 5 votes |
public synchronized Tracker getTracker(TrackerName trackerId) { if (!mTrackers.containsKey(trackerId)) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); Tracker t = analytics.newTracker(R.xml.global_tracker); mTrackers.put(trackerId, t); } return mTrackers.get(trackerId); }
Example 12
Source File: MovieCheckApplication.java From Movie-Check with Apache License 2.0 | 5 votes |
synchronized public Tracker getDefaultTracker() { if (mTracker == null) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); mTracker = analytics.newTracker(R.xml.global_tracker); } return mTracker; }
Example 13
Source File: NoyzeApp.java From Noyze with Apache License 2.0 | 5 votes |
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 14
Source File: G.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
synchronized public Tracker getDefaultTracker() { if (mTracker == null) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); mTracker = analytics.newTracker(R.xml.global_track); } return mTracker; }
Example 15
Source File: FiveCallsApplication.java From android with MIT License | 5 votes |
/** * 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 16
Source File: AppModule.java From droidkaigi2016 with Apache License 2.0 | 5 votes |
@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 17
Source File: SilentActivity.java From KUAS-AP-Material with MIT License | 4 votes |
public void initGA(String screenName) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); mTracker = analytics.newTracker(Constant.GA_ID); mTracker.setScreenName(screenName); mTracker.send(new HitBuilders.ScreenViewBuilder().build()); }
Example 18
Source File: AppModule.java From android-aop-analytics with Apache License 2.0 | 4 votes |
@Provides @Singleton public Tracker provideAnalyticsTracker() { GoogleAnalytics analytics = GoogleAnalytics.getInstance(context); return analytics.newTracker(R.xml.global_tracker); }
Example 19
Source File: AnalyticsTracker.java From AJShA with GNU General Public License v3.0 | 4 votes |
public AnalyticsTracker(Context ctx) { this.ctx = ctx; analytics = GoogleAnalytics.getInstance(ctx); tracker = analytics.newTracker(R.xml.analytics); }
Example 20
Source File: SilentActivity.java From KUAS-AP-Material with MIT License | 4 votes |
public void initGA(String screenName) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); mTracker = analytics.newTracker(Constant.GA_ID); mTracker.setScreenName(screenName); mTracker.send(new HitBuilders.ScreenViewBuilder().build()); }