Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private final static String ANALYTICS_PROPERTY_ID = "UA-42710658-18";
- /**
- * Enum used to identify the tracker that needs to be used for tracking.
- *
- * A single tracker is usually enough for most purposes. In case you do need multiple trackers,
- * storing them all in Application object helps ensure that they are created only once per
- * application instance.
- */
- public enum TrackerName {
- APP_TRACKER, // Tracker used only in this app.
- GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
- ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a company.
- }
- HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
- synchronized Tracker getTracker(TrackerName trackerId) {
- if (!mTrackers.containsKey(trackerId)) {
- GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
- Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID)
- : (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.global_tracker)
- : analytics.newTracker(R.xml.ecommerce_tracker);
- mTrackers.put(trackerId, t);
- }
- return mTrackers.get(trackerId);
- }
- // Get tracker.
- Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
- TrackerName.APP_TRACKER);
- // Set screen name.
- // Where path is a String representing the screen name.
- t.setScreenName(path);
- // Send a screen view.
- t.send(new HitBuilders.AppViewBuilder().build());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement