Learn CleverTap Integration In React Native

What Is CleverTap?

CleverTap is a platform for customer engagement and user retention that helps brands to increase user engagement in their application. CleverTap is basically an analytical platform that helps track user actions to understand how users use the product.

CleverTap

In this article, we will focus on CleverTap Features and will also learn CleverTap integration with react native.

Related Read: A Complete Guide To Build The First React Native App

CleverTap Features

  • User Profile: Once you integrate CleverTap SDK in your React Native application user profile is created for each user.
  • Events: CleverTap SDK tracks the user actions in your application and sends records to CleverTap for tracking user engagement and interests.
  • Segments: Above sent events and profile creation can be seen in Segments. This segment helps us understand the events and profile properties of particular users. We can create a report for user analysis. With segments, we can match multiple users having the same properties and filter them for campaigns.
  • Campaigns: Campaigns are used to communicate with the user by messaging channels.
  • Reports: CleverTap provides you the ability to build reports to analyze user engagement and campaign effects on users

 

Watch Our CleverTap Workshop Below 👇

CleverTap Integration In React Native

We will use clevertap-react-native library for CleverTap integration in React Native.

Install:

npm install --save clevertap-react-native

Cd ios && pod install   //for ios

For configuration please visit react-native-quick-start-guide

Create User Profile

First import CleverTap:

Create User Profile

To create a user profile we will use the CleverTap.profileSet() function. This function helps you create a user profile on CleverTap. This user profile is a very initial and important step as other core features like events, segments and campaigns depend on user creation on the dashboard. If no user profile is created we cannot send events to that particular user hence we cannot analyze user engagement in segments and can’t send campaigns (notifications/messages) to the particular user.

You can use this function on your signup or login screen to collect user information like name, mobile number, email etc and send it to CleverTap for profile creation.

creating clevertap user profile

Before creating a profile if you search your profile using email/CleverTapId you will get the below result. Which means your user is not created.

CleverTap user profile screenshot

After creating your profile successfully you can see your profile and the properties which you sent while creating the profile like name, email, dob etc, The DOB field calculates the age of the user.

Clevertap user profile screenshot

CleverTap Id you can see under the user name. This CleverTap id is created when the user profile is created and you can use this CleverTap id to search the user profile once his profile is created.

CleverTap User Profile screenshot

Hire React Native Developers

Other than creating profiles we can also use CleverTap.profileSet() function to update the user properties. For example, we will update/change the birthdate of the user as below:

Note: While updating the user properties Email is the main key with which you can update properties for that particular user. If you update the main key which is Email then a new profile will get created with a new CleverTap id while the existing profile will remain the same with the old mail id but no new events will be logged there.

Updating properties in clevertap

Updating properties in clevertap

Create User Events

Once a profile is created, the user can visit various sections in your application that he/she may be interested in or perform various actions like login, signup, button clicks, etc. We can capture the actions with events for analyzing user engagement, tracking user actions and knowing his interesting areas. This may help you understand user interests to improve your application and make it more user likable.

We can create user events using the CleverTap.recordEvent() function. You can add custom names and fields in the recordEvent function. For example “Login” is the name of the event and “Name, Email, Device, Country, DOB, etc” are fields of that event.

We can create various events based on user actions such as,

Create User Events In CleverTap

Create User Events In CleverTap

Create User Events In CleverTap

Create User Events In CleverTap

Create User Events In CleverTap

Create User Events In CleverTap

Create User Events In CleverTap

Segments

Above sent events and profile creation can be seen in Segments. This segment helps us understand the events and profile properties of particular users. We can create a report for user engagement analysis. With segments, we can match multiple users having the same properties and filter them for campaigns.

User Profile:

User Profile Segments In clevertap

User Events:

 

User Event In CleverTap

User Event In CleverTap

We can save this segment and also we can view his profile by clicking on sample people at the bottom. By saving the segment you can search it by name and view it anytime in the segments.

User Event Segment In CleverTap

In the above part, we saw three core concepts (User profile, Events and Segments) of CleverTap in detail. Now let’s see the other two core concepts, Campaigns and Reports, in detail.

  • Campaigns: Campaigns are used to communicate with the user by messaging channels.
  • Reports: CleverTap provides you the ability to build reports to analyze user engagement and campaign effects on users.

Campaigns

Campaigns are nothing but a marketing channel for sending deep link push notifications to users. Deeplink allows push notifications to redirect users to specific pages inside the app. Using campaigns, we can make users aware of new feature launches in the application and directly redirect them to that particular page.

Campaigns can help you engage by sending them notifications for new features, new posts or any update in the application. Deeplink is the perfect tool for driving user engagement and landing directly to a specific point in the app.

Here we will use universal links(http/https urls) for deep link notifications.

Syntax

https://<BASE_URL>/<ROUTENAME>?<PARAMS>=<param_value>
  • Route Name: Screen name to navigate
  • Params: Pass data as key-value pair while navigating

Configuration

For Configuration please follow react-native-push-notification. Here syntax for createNotificationChannel is,

cleverTapAPI.createNotificationChannel(getApplicationContext(),"YourChannelId","Your Channel Name","Your Channel Description",NotificationManager.IMPORTANCE_MAX,true);

Note:You have to place this CleverTapAPI.createNotificationChannel() function in your android MainActivity.java file under setInitialUrl() function.

Handling Deeplink

App in foreground
The foreground state is when the user actively uses the app and gets the notification. The app is already open in this case, and the Linking event is fired. To handle this event we use

Linking.addEventListener('url', callback)

 

App in foreground screenshot

 

App in foreground screenshot

App in the background
In this state, the app is not already open. In this case, we use CleverTap.getInitialUrl() function, and url is passed as the initial url. This function returns a promise that resolves to the url.
App in the background screenshot
App in the background ScreenshotIn both the states, we use the same _handleOpenUrl() function from which we will call the actual redirection function logic.

App in the background screenshot
We will send the url to getUrl() function and check for a particular string if it exists in the url and redirect it accordingly. For example, if the url is https://domain-name/Activity we are checking for the “Activity” keyword, and if it includes it, we will navigate it to the activity screen as follows.

App in the background screenshot

Note: You can place this code just after your App.js file which means the screen in which you hide your splash screen.

Looking To Develop A React Native App?

Sending Push Notifications

In the CleverTap dashboard, go to Campaigns from the left-hand menu and click on “+ Campaigns” button.

Sending Push Notifications in clevertap

Then select mobile push

selecting mobile push notification in clevertap

Then select notification behavior like one time, recurring etc. We will select one-time notification. You can choose according to your requirement.

selecting notification behavior in clevertap

Then select the time to send the notification that is sent it now or schedule it for later. For testing, we will select send notification now. And click on the Continue button.

Selecting notification time in clevertap

Now you have to select the segment/User to whom you want to send the notification or if you have not created/saved any segment you can create one by clicking on “+ Create an ad-hoc segment” button at the top. And click on continue.

selecting user/segment in clevertap

Select Segment/User and can filter it using user properties. For example, to send a notification to a particular user you can select the email property and type the email to which you want to send the notification. And for multiple users like sending notifications to people in the same age group you can select age property. And click on the Continue button. 

Then select a single message button to send the same message to all the users.

selecting message setting in clevertap

Then on the next screen add the title, and message and check advance checkout. In advance switch deep link toggle to ON state and paste deep link redirection url. For example https://domain-name/Activity.

Now select the notification channel, the one which we had set in the MainActivity.java file while configuration. And click on the “send a test push notification” button.

selecting notification channel in clevertap

Now type your email and search the user. Once found click on Add button and check the checkout for the particular user and send a notification.

selecting profile in clevetap

Finally, test the notification on your mobile device and click to redirect.

test notification screenshot

Reports

CleverTap allows you to build reports for understanding campaigns’ effect on users. This report is used to analyze user engagement.

For more details, you can visit Reports

coma

Conclusion

In this article, we saw what is CleverTap, its features & CleverTap integration with react native. We also saw other core concepts in detail like campaigns and reports.

Keep Reading

Keep Reading

  • Service
  • Career
  • Let's create something together!

  • We’re looking for the best. Are you in?