Using Google Analytics v2 without activity / EasyTracker
When using EasyTracker:
@Override
protected void onStart() {
super.onStart();
EasyTracker.getInstance().activityStart(this);
}
It works great, the problem I am integrating from the old version of analytics and I am using it in the service and not in the activity, so I cannot use the activityStart method.
I tried using:
GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(getApplicationContext());
final Tracker tracker = googleAnalytics.getTracker("UA-xxxxxx-y");
tracker.setStartSession(true);
tracker.sendView("/page");
And I don't see anything in the analytics (even after GAServiceManager.getInstance (). Dispatch ()) ....
Can i use the new version of analytics without activity?
thank
+3
source to share
2 answers
Found a way not to use EasyTracker. It was actually on the official site: https://developers.google.com/analytics/devguides/collection/android/v2/advanced
This is basically what you need to do: First, enter the start tracker like this:
// Get the GoogleAnalytics singleton.
mGaInstance = GoogleAnalytics.getInstance(this);
// Use the GoogleAnalytics singleton to get two Trackers with
// unique property IDs.
mGaTracker = mGaInstance.getTracker("UA-XXXX-Y");
Then you can get the tracker like this:
mGoogleAnalytics.getDefaultTracker();
And use it like:
mGoogleAnalytics.sendEvent(.....);
mGaTracker.sendView(....);
+1
source to share