Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. private final static String ANALYTICS_PROPERTY_ID = "UA-42710658-18";
  2.  
  3. /**
  4. * Enum used to identify the tracker that needs to be used for tracking.
  5. *
  6. * A single tracker is usually enough for most purposes. In case you do need multiple trackers,
  7. * storing them all in Application object helps ensure that they are created only once per
  8. * application instance.
  9. */
  10. public enum TrackerName {
  11. APP_TRACKER, // Tracker used only in this app.
  12. GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
  13. ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a company.
  14. }
  15.  
  16. HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
  17.  
  18. synchronized Tracker getTracker(TrackerName trackerId) {
  19. if (!mTrackers.containsKey(trackerId)) {
  20.  
  21. GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
  22. Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID)
  23. : (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.global_tracker)
  24. : analytics.newTracker(R.xml.ecommerce_tracker);
  25. mTrackers.put(trackerId, t);
  26.  
  27. }
  28. return mTrackers.get(trackerId);
  29. }
  30.  
  31. // Get tracker.
  32. Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
  33. TrackerName.APP_TRACKER);
  34.  
  35. // Set screen name.
  36. // Where path is a String representing the screen name.
  37. t.setScreenName(path);
  38.  
  39. // Send a screen view.
  40. t.send(new HitBuilders.AppViewBuilder().build());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement