dependencies
section in app/build.gradle
, replacing the version number with the latest version listed here.app/src/main/AndroidManifest.xml
: setupTracker
function in your main activity, only when the app is in the foreground:app/src/main/java/com/example/app/MainActivity.java
. Usually, this should be done in onCreate. If you have multiple entry points into your app, you may call this from any of them, but only the first call will be acknowledged. chartbeatAccountId
and chartbeatSiteId
with your organization's Chartbeat account ID and site ID values.this
is the application-level Context.trackView()
:setUserPaid()
to specify a user as a paid subscriber.setUserLoggedIn()
to specify a user as a registered user.setUserAnonymous()
to specify a user as an unregistered guest user.trackView
code (below) to any view you want Chartbeat to track.viewId
that does not conflict with other page paths from your site. Traffic for this view will then be tracked a separate page in your dashboard. For example, you can track users in your app’s table of contents by setting the viewId
to something like /nativeapp/main-toc
.setSections
and setAuthors
with an array of strings for each after calling trackView
. Any sections and authors you set will stay set until you set a different set of values. If the user is navigating from a view with sections or authors to another view with no applicable sections or authors, you should set the sections or authors to an empty array.userInteracted
function whenever the user interacts with your view to accurately measure user engagement with your content. Our Recommendation is to call this from within the onUserInteraction
function of your activity. Register writing engagement by calling the userTyped
function whenever the user starts typing something.userLeftView
function (e.g. from your activities’ onPause functions) whenever the app leaves the foreground to stop the tracking for the current session.pauseTracker
function when the user navigates to a view you don’t want to track.trackView
again when the app returns to the foreground.