Android SDK native application instrumentation

The Android SDK for Marfeel allows tracking among others:

Setup

Add the following repository to your configuration(settings.gradle), for more info Declaring repositories

maven {
  url https://repositories.mrf.io/nexus/repository/mvn-marfeel-public/
}

and then add the following dependency in your build.gradle (dependencies section) if you’re using Jetpack Compose

dependencies {
  implementation ‘com.marfeel.compass:compose:1.0’
}

or include the following one if you’re using xml views

dependencies {
  implementation ‘com.marfeel.compass:views:1.0’
}

Initialization

Before starting to track pages the SDK needs to be initialized via it initialize method:

CompassTracking.initialize(context: Context, accountId: String)

The accountId parameter belong to your Marfeel organization account and can be found also on the Tracking code section.

Usage

All tracking features are made available through a CompassTracking instance:

val tracker = CompassTracking.getInstance()

Tracking pageviews

CompassTracker automatically tracks the time on page of a user. When a user starts reading a new page you must provide its url:

tracker.startPageView(url: String)

CompassTracker will track the reading time until the startPageView method is invoked again with a different url or if the the stopTracking() method is invoked explicitly by the developer.

tracker.stopTracking()

Scroll depth control

If you want to track the scroll depth you can provide the NestedScrollView to the startPageView method.​

tracker.startPageView(url: String, scrollView: NestedScrollView)

In case of using Jetpack Compose you must use startTracking(url: String) along with the composable function:

CompassScrollTrackerEffect(scrollState: ScrollState)

User Id

To track a userId instead of the default Marfeel one you can use the method setUserId.

setUserId(userId: String)

User Journey

You can provide the type of a user:

  • ANONYMOUS: for anonymous users
  • LOGGED: for registered users
  • PAID: for subscribers
  • CUSTOM. For custom types you must provide a numeric identifier declared on the Marfeel User Journey UI
tracker.setUserType(UserType.Anonymous)
tracker.setUserType(UserType.Logged)
tracker.setUserType(UserType.Paid)
tracker.setUserType(UserType.Custom(9))
TIP:
It's recommended that you first provide the user Id and the user journey before tracking the first pageview.​

Accessing RFV of user in session

If you want to use the RFV of the user in session you can get it through the getRFV method:

tracker.getRFV { rfv ->
    // callback
}

There’s a synchronous version of this fucntion. It should be called from a different thread.

Conversions tracking

You can track conversions calling the track(conversion: String) method:

tracker.track("subscription")