Android
Getting Started
1. Install
- Add the dependency
- 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:
property | required | type | default value |
---|---|---|---|
captureAppLifecycleEvents | false | boolean | true |
flushAt | false | Int | 20 |
maxQueueSize | false | Int | 1000 |
maxBatchSize | false | Int | 50 |
flushIntervalSeconds | false | Long | 20 |
debug | false | Long | false |
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 Name | Description |
---|---|
USER_ID | UserId associated with the user |
PHONE | Phone number associated with the user |
Email ID associated with the user | |
DEVICE_TOKEN | FCM token for the device |
NAME | Name 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_name | Description |
---|---|
pi_os_name | Operating system name like iOS or Android |
pi_os_version | Operating system version "7.1.3" |
PI_SDK_NAME | PI sdk type such as Flutter or Android or Web |
PI_SDK_VERSION | PI sdk version |
Along with other platform specific device info
Events auto tracked by sdk
event name | initOptions key to control | description |
---|---|---|
App Opened | autoCaptureAppLifecycleEvents | Triggered when percept sdk is initialized |
Application Installed | autoCaptureAppLifecycleEvents | Triggered when app is installed for the first time |
Application Updated | autoCaptureAppLifecycleEvents | Triggered when app is updated |
Support
If you have any questions, issues, or need assistance with Percept, drop us an email at [email protected]