I need to start and to stop a session at a specific hour.
In official documentation I have found only that I can start a new session :
// Called after a user successfully signs in to your app.
private void onSignIn() {
... // The rest of your onSignIn() code.
myTracker.setStartSession(true); // Where myTracker is an instance of Tracker.
myTracker.sendEvent("app_flow", "sign_in", "", null); // First activity of new session.
}
But I have no methods in API to stop the session or to change the session time out.
I already tried to set ga_sessionTimeout to 1 day but it didn't worked,after ~8 minutes the session was closed even when the activity was still on the screen.I saw it on my Google Analytics dashboard's real-time overview.
Other ideas will be appreciated.
By default, Google Analytics will group hits that are received within
30 minutes of one another into the same session.
My goal was to keep the session alive till some event happen,
therefore I decided to implement Heartbeat mechanism.
That will send event every X minutes to keep the session alive.
It solved my problem.
P.S. : I discovered another thread with same solution.
Related
I am using Firebase for just Analytics. I implemented yesterday Firebase successfully. In fact I did not get any runtime error but I noticed in Logcat.
After 2-3 seconds, this message is seen in Logcat.
V/FA: Inactivity, disconnecting from the service
Analytics data is very important for me. As a result, I want to make sure this Analytics data is completely correct. I don't want inaccurate data when it comes to analytics.
As you know, in Firebase Analytics session duration is important. If firebase is disconnected from the service, then session duration probably won't calculated correctly.
Finally, What do you think about this situation?
Should I continue to suspect? If so, how can I solve this problem?
or
Can we say no problem? Session duration and other metrics will be calculated perfectly.
That's just a verbose log message. It doesn't mean that you're losing any data.
If you have concerns about the way any Firebase SDKs are working, please contact Firebase support for help.
V/FA is Firebase info (verbose)
A session expires when there 30 minutes by default that none of the app's activities is the current activity. If the user exits the app for a shorter period than the session timeout and then restarts it, the session continues. If the user exits the app for longer than the session timeout, then the session ends.
doc , check setSessionTimeoutDuration
I'm trying to prevent creating new session, while firing a Google Analytics event, when app is in Background (or killed state). Events like "PushNotificationReceived" need to be fired when app is not opened (or in background). But these events would increase session count.
Though it is possible to make user segment and filter out these sessions in Google Analytics Dashboard. But I'm looking for alternate way.
What should be the best approach to track these type of events without impacting session count or active users, etc.
The whole idea of Google Analytics events is that they supposed to be part of a session so there is no obvious way to set a tracking like that.
Like google analytics has setSessionimeout where all the vents are grouped together and at the end events are dispatched.Is there anything similar for Flurry analytics,As flurry hits the flurry server instantly,I want it to bunch together all the events in a session (Suppose of 30 min ) and then disptach them.
It is not possible to force the Flurry SDK to report analytics session data at specified time. A Flurry session is defined by
"If the app pauses or moves to the background for more than 10 seconds, the next time the app runs, Flurry agent will automatically create a new session and end the previous session. Otherwise, Flurry agent will continue the same session. This can be updated via the setSessionContinueSeconds method. If the app is terminated, a new session will be created when the app runs again."
The only way to control the session reporting is through the app lifecycle. But generally I would expect all of the events to be reported in a single batch per session. You can observe this behavior by watching the event log in the Flurry UI as the app is closed and/or reopened.
setSessionContinueSeconds is really only useful for cases where you would want the Flurry session to continue for longer than 10 seconds while the app is in the background. For instance an app that plays music in the background.
I do Pedometer app for android. The principle of operation as follows:
When you first launch the app, runs a service that runs in the foreground mode. Program prompts the user for Google account to login. If everything is fine then created GoogleApiClient object. Then in case of successful connection is created Fitness.SensorsApi in which I ask only in the number of steps of the system. Since I keep a not a lot of data, instead of a database I use SharedPreferences, and write new data there. If application is running, mainActivity connect to SharedPreferences every second to display the new values on the screen. All work is not bad. But sometimes, cease come on the number of steps. This may occur during the day sometimes it happens after the reset counters every day at 00:00 and sometimes a few days to work without problems. Helps only a complete restart the application.
And several times was that the data is not displayed on the screen, but the service has worked and recorded data.
In this case, after application restart I immediately received the data for the entire period (hung screen). The service itself is 100% live, because I send a message in the log every 5 seconds.
If someone is faced with a similar, please help, what could be the reason. Can GoogleApiClient loses connection or something else. How to track down an error? I will be very grateful.
Check this documentation of Google Fit on how to connect your Android app in Google fit. Make sure you properly setup this guide in your project, especially the Step 5 in where you Connect to the fitness service. For more information, check this SO question.
Here is the sample code on how the Sensors API should be accessed from the Fitness entry point.
GoogleApiClient client = new GoogleApiClient.Builder(context)
.addApi(Fitness.SENSORS_API)
...
.build();
client.connect();
PendingResult<Status> pendingResult = Fitness.SensorsApi.add(
client,
new SensorRequest.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setSamplingDelay(1, TimeUnit.MINUTES) // sample once per minute
.build(),
myStepCountListener);
For additional information, check this links.
GoogleApiClient
FitnessSensorService
I try to send an event just before disabling the Google analytics in android. But, the event doesn't show up in the real-time GA console.
tracker.send(new HitBuilders.EventBuilder()
.setCategory(category)
.setAction(action)
.setLabel(label)
.build());
//disable GA
GoogleAnalytics.getInstance(this).setAppOptOut(true);
Thanks for any advice.
If you enable Google Analytics logging you can see that when you call setAppOptOut(true) Google Analytics will clear all queued hits since it last sent hits to the Google Analytics servers:
V/GAV4﹕ Thread[GAThread,5,main]: clearHits called
As you noticed yourself dispatchLocalHits() doesn't help since it does nothing with Google Play Services installed. What you need to do is to wait with calling setAppOptOut(true) until after your hits have been dispatched. However as you don't know when the hits are dispatched it's not an easy thing to do.
You can specify what dispatch period your app should have with the ga_dispatchPeriod setting (with the default being 30 minutes). If you wait for longer than the configured dispatch period you should be fairly certain that your event has been sent, however this is not guaranteed since GA may wait with sending the data even longer if you do not have any network connection at the moment.
If you would take this approach you must make sure that the wait works across sessions since Google Play services is a separate service on the device and it will hold on to your hits even if you restart your app. So opting out on next startup of your app will not work either.
However waiting with opting out for more than 30 minutes might not be very nice to your users since that gives a lot of time for data to be gathered and submitted after the user thinks that they have opted out.
A better approach might be to have your own internal Google Analytics wrapper class that all parts of your app calls to report data. Then each reporting method could have a check if Google Analytics is enabled, never call any of the real Google Analytics methods.
This way you can be sure that you final event is sent to Google Analytics while no more events are sent after that even though you don't call setAppOptOut(true).
Do note that this only works if you do not rely on any automatic tracking like automatic reporting of uncaught exceptions or automatic screen measurement.