Skip to content

anonymous /Tracker.java
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Google analytics singleton wrapper, provides a second based split between application visits.
import android.content.Context;
import com.application.R;
import com.google.android.apps.analytics.GoogleAnalyticsTracker;
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;
newVisit();
}
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)
{
analytics.stopSession();
newVisit();
}
lastTime = now;
analytics.trackPageView(url);
}
}
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.