Skip to main content

Android

Percept Android SDK

Getting Started​

1. Install​

  1. Add the dependency
  2. Sync project with gradle

2. Declare an instance of Percept​

    private lateinit var percept: Percept

3. Initialize and get instance​

    override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
percept = Percept.getInstance(
YOUR_APP_TOKEN,
PerceptConfig(),
applicationContext
)
}

NOTE: Token is the percept workspace token associated with your app.

getInstance method takes a PerceptConfig object param as second argument which can be used to configure different default behaviours PerceptConfig properties:

propertyrequiredtypedefault value
captureAppLifecycleEventsfalsebooleantrue
flushAtfalseInt20
maxQueueSizefalseInt1000
maxBatchSizefalseInt50
flushIntervalSecondsfalseLong20
debugfalseLongfalse

4. Set user​

After successfully initializing the SDK, On login set current User using the following function.

percept.setUser(
userId = "userId",
userProperties = mapOf(PerceptUserProperty.NAME to "TestUser"),
additionalProperties = mapOf("isVerifiedAccount" to true)
)

5. Set current user properties​

use setCurrentUserProperties method to set properties on the user profile created by setUser

// Don't forget to call percept.setUser() method at least once before using this method

// sets user `deviceToken` and `isPaidUser` property to true
percept.setCurrentUserProperties(userProperties = mapOf(PerceptUserProperty.DEVICE_TOKEN to "Token"), additionalProperties = mapOf("isPaidUser" to true))

UserProperties can only have keys present in the PerceptUserProperty enum which are as follows.

User Property NameDescription
USER_IDUserId associated with the user
PHONEPhone number associated with the user
EMAILEmail ID associated with the user
DEVICE_TOKENFCM token for the device
NAMEName of the user

6. Capture Event​

// Track only event-name
percept.capture("Referral Banner Click")

// Track event-name with property
percept.capture("Screen View", mapOf("ScreenName" to "Homepage"))

After initializing the library, Percept will automatically track some properties by default

7. Set Global Properties​

Set global properties which will be passed with all subsequent events

percept.setGlobalProperties(globalProperties = mapOf("global-property-key" to "value"))

8. Get all global properties​

Get all global properties

percept.getGlobalProperties()

9. Clear​

This will clear all user info and cached data. Call clear function on logout to delete all user related information

percept.clear()

Close the SDK​

percept.close()

Properties tracked by sdk​

Property_nameDescription
pi_os_nameOperating system name like iOS or Android
pi_os_versionOperating system version "7.1.3"
PI_SDK_NAMEPI sdk type such as Flutter or Android or Web
PI_SDK_VERSIONPI sdk version

Along with other platform specific device info

Events auto tracked by sdk​

event nameinitOptions key to controldescription
App OpenedautoCaptureAppLifecycleEventsTriggered when percept sdk is initialized
Application InstalledautoCaptureAppLifecycleEventsTriggered when app is installed for the first time
Application UpdatedautoCaptureAppLifecycleEventsTriggered when app is updated

Support​

If you have any questions, issues, or need assistance with Percept, drop us an email at [email protected]