Skip to content

Instantly share code, notes, and snippets.

@willrust
Last active August 29, 2015 14:03
Show Gist options
  • Save willrust/16614ac542b5d947cdeb to your computer and use it in GitHub Desktop.
Save willrust/16614ac542b5d947cdeb to your computer and use it in GitHub Desktop.
Recording view duration as a property in KISSmetrics Android SDK
//In your Activities: (Replace "someViewDuration" with an appropriate name for each activity)
long appearedAtTime;
@Override
public void onResume() {
super.onResume();
appearedAtTime = System.currentTimeMillis();
}
@Override
public void onPause() {
super.onPause();
HashMap<String, String> properties = new HashMap<String, String>();
properties.put("someViewDuration", String.valueOf((System.currentTimeMillis() - appearedAtTime) / 1000));
KISSmetricsAPI.sharedAPI().set(properties);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment