Invalid APP_EVENTS warning log
andriishpek-sigma opened this issue · 0 comments
Checklist before submitting a bug report
- I've updated to the latest released version of the SDK
- I've searched for existing Github issues
- I've looked for existing answers on Stack Overflow, the Facebook Developer Community Forum and the Facebook Developers Group
- I've read the Code of Conduct
- This issue is not security related and can safely be disclosed publicly on GitHub
Java version
17.0.7
Android version
API 33
Android SDK version
16.2.0
Installation platform & version
Gradle 8.1
Package
Core & AppEvents
Goals
Fix invalid APP_EVENTS warning log for AppEventsLogger.activateApp(...) call.
Expected results
Fix invalid APP_EVENTS warning log for AppEventsLogger.activateApp(...) call.
Actual results
I'm using Facebook app events. When I frequently reopen the app, I get this log:
Warning: Please call AppEventsLogger.activateApp(...)from the long-lived activity's onResume() methodbefore logging other app events.
I use AppEventsLogger.newLogger(this) inside Application.onCreate() to initialize the SDK.
Having dug the code, I realized that:
- Warning is logged in
AppEventsLoggerImpl.logEvent(event: AppEvent, accessTokenAppId: AccessTokenAppIdPair)
- It happens because
isActivateAppEventRequested = false
isActivateAppEventRequested
is set totrue
when eventEVENT_NAME_ACTIVATED_APP
is loggedEVENT_NAME_ACTIVATED_APP
is logged fromSessionLogger.logActivateApp()
SessionLogger.logActivateApp()
is called fromActivityLifecycleTracker
insideonActivityResumed()
method when either there is no sessioncurrentSession = null
, orsuspendTime > sessionTimeoutInSeconds * 1000
Here's where the party comes. First of all, currentSession
is always fetched from storage as soon as activity is created:
@JvmStatic
fun onActivityCreated(activity: Activity?) {
singleThreadExecutor.execute {
if (currentSession == null) {
currentSession = getStoredSessionInfo()
}
}
}
When it comes to onActivityResumed()
, currentSession
is going to be null if and only if you've just installed the app. Otherwise, it'll be always loaded from storage inside onActivityCreated()
.
As per second condition: suspendTime > sessionTimeoutInSeconds * 1000
. The default value of sessionTimeoutInSeconds
is 60. suspendTime
seems to be a duration since the last event was logged. So we can say that SDK 'throttles' logActivateApp()
call if one was made during the last minute. Sounds legit: we want to treat current user session as the last one ended in past minute. However, that's where the issue happens: we've restored the previous session, but EVENT_NAME_ACTIVATED_APP
was not logged, and AppEventsLogger.isActivateAppEventRequested = false
, and logEvent() prints this warning.
It seems like if we throttle app activation, then we need to explicitly set AppEventsLogger.isActivateAppEventRequested
to true.
Steps to reproduce
Precondition: Enable APP_EVENTS
logging
- Open the app with Facebook app events enabled
- Give a few seconds for SDK to initialize; log some events; all works fine
- Close and open the app within one minute
- Log some more events
ER: There is no warning in logcat about app initialization.
AR: There is a warning in logcat: "Warning: Please call AppEventsLogger.activateApp(...)from the long-lived activity's onResume() methodbefore logging other app events.". It it logged right after each and every event is logged into SDK.
Code samples & details
No response