Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App Close Event not getting tracked when app is getting Closed #197

Open
nk-mohan opened this issue Jun 25, 2019 · 4 comments
Open

App Close Event not getting tracked when app is getting Closed #197

nk-mohan opened this issue Jun 25, 2019 · 4 comments

Comments

@nk-mohan
Copy link

I want to track App Open and App Closed events, Below code i have used. I'm getting App Open Event but i couldn't get App Close Event, is there anyone know how track app close event

class AppLifecycleTracker : Application.ActivityLifecycleCallbacks {
private var numActivitiesStarted = 0

override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) {
    if (numActivitiesStarted == 0) {
        // app launched
        Amplitude.getInstance().logEvent("APP_OPEN")
    }
    numActivitiesStarted++
}

override fun onActivitySaveInstanceState(activity: Activity?, outState: Bundle?) {
}

override fun onActivityDestroyed(activity: Activity?) {
    numActivitiesStarted--
    if (numActivitiesStarted == 0) {
        // app killed
        Amplitude.getInstance().logEvent("APP_CLOSE")
    }
}

override fun onActivityResumed(activity: Activity?) {
}

override fun onActivityPaused(activity: Activity?) {
}

override fun onActivityStarted(activity: Activity?) {
  
}

override fun onActivityStopped(activity: Activity?) {
 
}

}

@raghunandankavi2010
Copy link

raghunandankavi2010 commented Nov 3, 2021

Any update on this. Even in our app end session events are not getting tracked. Also if you reopen the app again there is no start session event logged. Below is the code

    sharedPref = getSharedPreferences(PREF_EMPLOYEE, PRIVATE_MODE)
    val empId =  sharedPref.getString("uuid","") //editor.putString("uuid", employeData.uuid)
    val client: AmplitudeClient = Amplitude.getInstance()
        .initialize(applicationContext, "APIKEY")
        .enableForegroundTracking(application)
        .trackSessionEvents(true)
        .setLogLevel(Log.VERBOSE)


    if(!empId.isNullOrBlank()) {
        client.userId = empId
    }

@qingzhuozhen
Copy link
Contributor

@raghunandankavi2010 How do you implement the app open and close events? For session events, if they are within a short time, we won't create new session events.

@raghunandankavi2010
Copy link

Got it. I was trying to open and close within 10 seconds. Also I see that when I open the app again the previous end session gets logged.

@qingzhuozhen
Copy link
Contributor

@raghunandankavi2010 Great to know. That's expected behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants