// simple convenience function for when a fragment wants to log a URL // don't need to worry about making sure it only happens once, because Fragments manage their own // state // in a way that activities do not. public static void track(Fragment fragment, String url) { if (fragment.isAdded()) { GoogleAnalyticsTracker tracker = start(fragment.getActivity()); page(fragment.getActivity(), tracker, url); stop(tracker); } }
public static TrackerFragment track(FragmentActivity activity, String url) { if (analyticsEnabled(activity)) { // I initialize the tracker here and call start(), instead of inside the fragment using // callbacks, // so that we can log the inaugural pageview here, where we know whether it's the first time // it happened FragmentManager manager = activity.getSupportFragmentManager(); TrackerFragment fragment = (TrackerFragment) manager.findFragmentByTag(FRAGMENT_TAG); if (fragment == null) { fragment = new TrackerFragment(); fragment.setRetainInstance(true); manager.beginTransaction().add(fragment, FRAGMENT_TAG).commit(); // initialize the tracker immediately, so it can be used by the caller fragment.tracker = start(activity); // if this was used as a convenience function in an activity, // log the pageview only once, when the fragment is first created if (url != null) page(activity, fragment.tracker, url); } // if this was used as a convenience function in an activity, reassign and restart // the tracker since we'll assume that this is the first call after the activity was restarted else if (url != null) fragment.tracker = start(activity); // otherwise, leave the fragment alone, nothing to do here return fragment; } else return null; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_titled_fastscroll); inflater = LayoutInflater.from(this); database = new Database(this); database.open(); peopleCursor = database.getLegislators(); startManagingCursor(peopleCursor); Bundle extras = getIntent().getExtras(); id = extras.getString("id"); roll = (Roll) extras.getSerializable("roll"); setupControls(); RollInfoHolder holder = (RollInfoHolder) getLastNonConfigurationInstance(); if (holder != null) { this.loadRollTask = holder.loadRollTask; this.roll = holder.roll; this.loadVotersTask = holder.loadVotersTask; this.voters = holder.voters; this.loadPhotoTasks = holder.loadPhotoTasks; this.currentTab = holder.currentTab; this.tracked = holder.tracked; if (loadPhotoTasks != null) { Iterator<LoadPhotoTask> iterator = loadPhotoTasks.values().iterator(); while (iterator.hasNext()) iterator.next().onScreenLoad(this); } } tracker = Analytics.start(this); if (!tracked) { Analytics.page(this, tracker, "/vote/roll/" + id); tracked = true; } loadRoll(); }
public static void page(Activity activity, GoogleAnalyticsTracker tracker, String page) { page(activity, tracker, page, true); }
public static void page(FragmentActivity activity, String page, boolean checkEntry) { page(activity, trackerFor(activity), page, checkEntry); }
public static void page(FragmentActivity activity, String page) { page(activity, page, true); }