Capillary SDK allows you to track events to gain insights into your app's usage patterns and categorise users based on their actions. For example, events such as signing in, launching an app, viewing a product, etc are used to track individual actions performed by users in your app or website.
There are 2 types of events:
- Standard events - These events are configured in the SDK and cannot be removed. With Capillary SDK, you can record user-specific information such as their username, first name, last name, email, mobile number, and other custom information, along with system information, in the events. This information can then be used to run campaigns based on user segregation at different levels.
- Behavioural events - The events resource also allows you to create behavioural events to track any other important user interactions for your business. For example, events such as forgot password, cart abandonment etc. These events can be further defined by event attributes such as price, quantity, and category. These events need to be configured in your org settings.
For behavioural events, you need to do configuration in the Hydraconfig and organisation settings.
Sending standard events to SDK
The SDK offers four event-tracking APIs for recording for reporting user action events. These APIs enable you to recognize visitors, monitor events, generate events dynamically, and track the activities of users, including any properties that describe their actions. This information can be used to gain insights into user behaviour and create campaigns based on user segmentation at different levels. For example, with the user event data, you can send welcome messages to customers through e-mail or offer different offers based on user age, gender etc.
The SDK has below standrad event tracking APIs:
- Sign In
- Sign Up
- User Update
- Sign Out
Each user in the app should have a unique identifier (cuid) associated with their account. Provide this identifier whenever a user signs up or signs in. This enables cross-device and cross-platform tracking, leading to improved behavioural and demographic data quality.
Sign In
This API enables reporting of a SignIn event to the SDK.
fun pushUserSignin(
cuid: String,
firstName: String? = null,
lastName: String? = null,
email: String? = null,
phone: String? = null,
customData: Map\<String, Any>? = null
)
public void pushUserSignin(String cuid, String firstName, String lastName, String email, String phone, Map<String, Object> customData) {
// Function body
}
Parameter | Type | Description | Optional/Mandatory |
---|---|---|---|
cuid | String | Identifier for the user, either phone/email/externalId | Mandatory |
firstName | String | First name of the user | Optional |
lastName | String | Last name of the user | Optional |
String | Email address of the user | Optional | |
phone | String | Phone number of the user | Optional |
customData | Map | Map of custom attributes for the user | Optional |
Example:
- User push sign-in event to SDK with optional details.
hydraAPI?.pushUserSignin( "9000090000", "Henry", "Williams", "[email protected]", "9000090000", mapOf("Age" to "25","Gender" to "Male"))
if (hydraAPI != null) { hydraAPI.pushUserSignin( "9000090000", "Henry", "Williams", "[email protected]", "9000090000", Map.of("Age", "25", "Gender", "Male") ); }
- User push sign-in event to SDK without optional details.
hydraAPI?.pushUserSignin( "9000090000", "", "", "", "", emptyMap() )
if (hydraAPI != null) { hydraAPI.pushUserSignin( "9000090000", "", "", "", "", Collections.emptyMap() ); }
Sign up
This API enables reporting of a SignUp (user registration) event to the SDK.
fun pushUserSignup(
cuid: String,
firstName: String,
lastName: String,
email: String,
phone: String,
customData: Map\<String, Any>?,
subscriptions: List<Any>?
)
public void pushUserSignup(String cuid, String firstName, String lastName, String email, String phone, Map<String, Object> customData) {
// Function body
}
Parameter | Type | Description | Optional/Mandatory |
---|---|---|---|
cuid | String | phone/email/externalId | Mandatory |
firstName | String | User first name | Mandatory |
lastName | String | User last Name | Mandatory |
String | User email address | Mandatory | |
phone | String | User mobile number | Mandatory |
customData | Map | The attribute map which needs to be set for the user. | Optional |
subscriptions | List | List of subscriptions which include channel, accountId, priority, type and sourcename. | Optional |
Example:
-
User push sign-up event to SDK with all optional details
hydraAPI?.pushUserSignup( "9000090000", "Henry", "Williams", "[email protected]", "9000090000", mapOf("Age" to "25","Gender" to "Male")
if (hydraAPI != null) { hydraAPI.pushUserSignup( "9000090000", "Henry", "Williams", "[email protected]", "9000090000", Map.of("Age", "25", "Gender", "Male") ); }
-
User push sign-up event to SDK without optional details
hydraAPI?.pushUserSignup( "9000090000", "", "", "", "", emptyMap() )
if (hydraAPI != null) { hydraAPI.pushUserSignup( "9000090000", "", "", "", "", Collections.emptyMap() ); }
User update
This API enables reporting of a user details update event to the SDK.
fun pushUserUpdate(
cuid: String,
firstName: String? = null,
lastName: String? = null,
email: String? = null,
phone: String? = null,
customData: Map\<String, Any>? = null
)
if (hydraAPI != null) {
hydraAPI.pushUserSignup(
"9000090000",
"",
"",
"",
"",
Collections.emptyMap()
);
}
Parameter | Type | Description | Optional/Mandatory |
---|---|---|---|
cuid | String | phone/email/externalId | Mandatory |
firstName | String | User first Name | Optional |
lastName | String | User Last Name | Optional |
String | User Email address | Optional | |
phone | String | User mobile number | Optional |
customData | Map | The attribute map which needs to be set for the user | Optional |
Example:
- User push update event to SDK with optional details
hydraAPI?.pushUserUpdate( "9000090000", "Henry", "Williams", "[email protected]", "9000090000", mapOf("Age" to "25","Gender" to "Male") )
if (hydraAPI != null) { hydraAPI.pushUserUpdate( "9000090000", "Henry", "Williams", "[email protected]", "9000090000", Map.of("Age", "25", "Gender", "Male") ); }
- User push update event to SDK without optional details
hydraAPI?.pushUserUpdate( "9000090000", "", "", "", "", emptyMap() )
if (hydraAPI != null) { hydraAPI.pushUserUpdate( "9000090000", "Henry", "Williams", "[email protected]", "9000090000", Map.of("Age", "25", "Gender", "Male") ); }
Sign out
This API enables reporting of a sign out event to the SDK.
To log sign-out events, only the cuid is required. You can use the cuid to erase all previously logged user information such as firstName, mobile, etc.
API function:
fun pushUserSignOut(
cuid: String
)
public void pushUserSignOut(String cuid) {
// Function body
}
Parameter | Type | Description | Optional/Mandatory |
---|---|---|---|
cuid | String | phone/email/externalId | Mandatory |
Example:
hydraAPI?.pushUserSignOut(
"9000090000",
)
if (hydraAPI != null) {
hydraAPI.pushUserSignOut("9000090000");
}
Pass user preferences
This API allows the application to track user preferences by passing settings in a User Preference object with the necessary information.
API function:
fun passUserPreferences(cuid: String, userPreference: UserPreferences)
**Example:**
hydraAPI?.passUserPreferences(
"9000090000", UserPreferences(promOpted, transOpted)
)
public void passUserPreferences(String cuid, UserPreferences userPreference) {
// Function body
}
Sending behavioural events to SDK
These events can be used to track user actions throughout the application. These events are valid only if the SDK receives the SignIn
or SignUp
events. Events are Invalid if they are called after a SignOut
event. In order to track these events, users have to pass event names (NotNull or NonEmpty) and attributes (optional).
Creating behavioural events
You need to create the desired behavioural events in the org settings.
- Navigate to Organisation settings > Master Data Management > Data Model > Behavioural events and create desired behaviour events. For more information, see Set behavioural events.
These events enable tracking user actions within the application and are only valid if the user has signed in or signed up with Capillary SDK.
Adding behavioural events in Hydraconfig
The events that you created in the org settings need to be configured in the HydraConfig
to send the events to the SDK.
API function:
fun pushEvent(
eventName: String,
attributes: Map\<String, Any>? = null
)
public void pushEvent(String eventName, Map<String, Object> attributes) {
// Function body
}
Parameter | Type | Description | Mandatory/Optional |
---|---|---|---|
event_name | String | Event name | Mandatory |
attributes | Map | The attribute map which needs to be set for the event | Optional |
Example:
-
Review events to the SDK
HydraAPI.getDefaultInstance(context = this)!!.pushEvent( "productReviewedMapp", mapOf( "event_name" to "productReviewedMapp", "customerId" to AppSharedPreferences.getInstance() .getStringSharedPreference(Constants.Pref.MOBILE_NUMBER, "null"), "customerReview" to review, "productName" to productName ) )
HydraAPI.getDefaultInstance(this).pushEvent( "productReviewedMapp", new HashMap<String, Object>() {{ put("event_name", "productReviewedMapp"); put("customerId", AppSharedPreferences.getInstance() .getStringSharedPreference(Constants.Pref.MOBILE_NUMBER, "null")); put("customerReview", review); put("productName", productName); }} );
-
Remove from cart event to SDK
HydraAPI.getDefaultInstance(this@CartPageActivity)?.pushEvent( "removedFromCart", mapOf( "price" to clickedItem.amount, "skuCode" to clickedItem.sku, "quantity" to clickedItem.qty, "customerId" to AppSharedPreferences.getInstance().getStringSharedPreference(Constants.Pref.MOBILE_NUMBER,"null"), "event_name" to "removedFromCart" ) )
HydraAPI.getDefaultInstance(this).pushEvent( "removedFromCart", new HashMap<String, Object>() {{ put("price", clickedItem.getAmount()); put("skuCode", clickedItem.getSku()); put("quantity", clickedItem.getQty()); put("customerId", AppSharedPreferences.getInstance().getStringSharedPreference(Constants.Pref.MOBILE_NUMBER, "null")); put("event_name", "removedFromCart"); }} );
-
Page/Activity events to SDK
hydraAPI?.pushEvent("Page/Activity successfully opened")
-
Click events with some attributes to SDK
hydraAPI?.pushEvent("button Click", mapOf("Username" to "Henry", "Age" to "25", "Gender" to "Male") )
if (hydraAPI != null) { hydraAPI.pushEvent("Page/Activity successfully opened"); }
-
Customer cart details to SDK
hydraAPI.pushEvent("add to cart", mapOf("Book" to "Rich Dad Poor Dad", "Phone" to "Realme 10", "Earphones" to "Sony Earbuds") )
hydraAPI.pushEvent( "add to cart", Map.of("Book", "Rich Dad Poor Dad", "Phone", "Realme 10", "Earphones", "Sony Earbuds") );