Skip to content
Create a gist now

Instantly share code, notes, and snippets.

anonymous /
Created Sep 27, 2011

Google analytics singleton wrapper, provides a second based split between application visits.
import android.content.Context;
import com.application.R;
public class Tracker {
private static Tracker singletonTracker;
public static final int VISIT_IDLE_LIMIT = 900; //in seconds ... 15 minuttes
public static Tracker getInstance(Context ctx) {
if(singletonTracker == null)
singletonTracker = new Tracker(ctx);
return singletonTracker;
private GoogleAnalyticsTracker analytics;
private long lastTime;
private Context applicationContext;
public Tracker(Context ctx) {
applicationContext = ctx;
private void newVisit()
lastTime = System.currentTimeMillis();
analytics = GoogleAnalyticsTracker.getInstance();
analytics.startNewSession(applicationContext.getString(R.string.analytics_id), 20, applicationContext);
public void trackPageView(String url) {
long now = System.currentTimeMillis();
if((now - lastTime)/1000 > VISIT_IDLE_LIMIT)
lastTime = now;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.