CleverTap / clevertap-android-sdk

CleverTap Android SDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Profile merge issue in android

mehul7616 opened this issue · comments

I have faced when i logout and login again new user so profile getting merged but not at uninstall when I uninstall the application or clear data from mobile and then after I log in so it's works properly creating a new profile and setting data but when I logout the user from the application and after logout i can log in so id getting merged logout code and login code is bellow mentioned

logout:-
fun logoutUser() {

lifecycleScope.launch {
    Currently.instance.onAppBackgrounded()
    preferenceDataStoreHelper?.clearAllPreference<T>()
    Currently.mSocketUtils?.disconnectSocket()
    Currently.mSocket?.disconnect()
}

SharedPrefsManager.clearPreference(this)
val ai: ApplicationInfo = packageManager.getApplicationInfo(packageName, 0)

val cacheDir = cacheDir
val externalCacheDir = externalCacheDir
cacheDir?.let { clearDirectory(it) }
externalCacheDir?.let { clearDirectory(it) }

// Clear data
val dataDir = File(ai.dataDir)
clearDirectory(dataDir)

startIntentActivity<OnBoardingActivity<Any>>(true)

}

private fun clearDirectory(directory: File) {
if (directory.exists()) {
val files: Array? = directory.listFiles()
files?.let {
for (file in it) {
if (file.isDirectory) {
clearDirectory(file)
} else {
file.delete()
}
}
}
}
}

login ;-

val profileUpdate = HashMap<String, Any>()
profileUpdate["Identity"] =
loginData.second?.user?.phoneNumber.toString()
profileUpdate["Phone"] = viewModel?.etMobile?.get().toString().trim()
profileUpdate["Phone Number"] = ""
profileUpdate["Contact Permission"] = ""
profileUpdate["Notification Permission"] = ""
profileUpdate["Name"] = ""
profileUpdate["Email"] = ""
profileUpdate["User Id"] = ""
profileUpdate["@username"] = ""
profileUpdate["First Name"] = ""
profileUpdate["Last Name"] = ""
profileUpdate["Privacy"] = ""
profileUpdate["Gender"] = ""
profileUpdate["Date of Birth"] = ""
profileUpdate["User Bio"] = ""
profileUpdate["Photo"] = ""
profileUpdate["Nominated By"] = ""
profileUpdate["Followers"] = 0
profileUpdate["Following"] = 0
profileUpdate["Total Invites"] = 0
profileUpdate["Invites Pending"] = 0
profileUpdate["Nominated Count"] = 0
profileUpdate["MSG-email"] = false // Disable email notifications
profileUpdate["MSG-push"] = true // Enable push notifications
profileUpdate["MSG-sms"] = true // Disable SMS notifications
profileUpdate["MSG-whatsapp"] = true // Enable WhatsApp notifications
CleverTapAPI.getDefaultInstance(getBaseActivity())
?.onUserLogin(profileUpdate)

Hi @mehul7616

Thanks for reaching us out. To better understand the issue, please answer to following questions:

  1. Login related Confirmation:
    Could you confirm whether you are logging in with the same user credentials (same email or identity) during both the initial login and subsequent logins?

  2. Properties Sent during Login:
    If you could provide an example of the properties you are sending via the onUserLogin(map) API during the login?

@shivamsharma2710

  1. I'm using a different identity and different email for subsequent login

  2. I have shared 2 objects of users I'm using this for onuserLogin
    1."user": {
    "id": 6,
    "first_name": "Mehull",
    "last_name": "Kathiriya",
    "phone_number": "7383805893",
    "is_chat_requested": false,
    "last_activity_timestamp": "2023-12-20T05:35:22.000Z",
    "email": null,
    "close_friends_count": 0,
    "is_online": false,
    "gender": "male",
    "username": "mehul7616",
    "profile_pic": "https://eampleurl/170299016193373974332.jpg",
    "dob": "1999-11-16",
    "status": "active",
    "bio": "nothing t9sjshshhwwh",
    "notification_flag": true,
    "total_invite_credits": 25,
    "deactivated_by_type": null,
    "invite_credits_left": 24,
    "profile_visibility": "private",
    "followingCount": 76,
    "followersCount": 90,
    "invitesCount": 0,
    "invitedCount": 32,
    "nominated_by": "rinkushah",
    "nominated_by_id": 1,
    "nominatedCount": 6,
    "nominee_count": 218,
    "total_activities_count": 90,
    "isFollowingMe": false,
    "isInMyContact": false,
    "isCloseFriend": false,
    "isMutedByMe": true,
    "isFollowedByMe": false,
    "isRequested": false,
    "isBlockedByMe": false,
    "hasBlockedMe": false,
    "mutualFriendsCount": 0,
    "latest_chat": null,
    "unread_chats_count": 0,
    "createdAt": "2023-09-29T11:07:30.000Z",
    "updatedAt": "2023-12-20T06:08:14.000Z",
    "deletedAt": null
    }

    1. "user": {
      "id": 2,
      "first_name": "Vipin",
      "last_name": "Kumar",
      "phone_number": "9671753743",
      "is_chat_requested": false,
      "last_activity_timestamp": "2023-12-19T12:08:07.000Z",
      "email": null,
      "close_friends_count": 0,
      "is_online": false,
      "gender": "male",
      "username": "vipink",
      "profile_pic": "https://exampleurl/1702584642417390238896.jpg",
      "dob": "1990-11-10",
      "status": "active",
      "bio": "hi hello",
      "notification_flag": true,
      "total_invite_credits": 25,
      "deactivated_by_type": null,
      "invite_credits_left": 25,
      "profile_visibility": "public",
      "followingCount": 9,
      "followersCount": 71,
      "invitesCount": 1,
      "invitedCount": 19,
      "nominated_by": "rinkushah",
      "nominated_by_id": 1,
      "nominatedCount": 8,
      "nominee_count": 8,
      "total_activities_count": 165,
      "isFollowingMe": true,
      "isInMyContact": false,
      "isCloseFriend": false,
      "isMutedByMe": false,
      "isFollowedByMe": true,
      "isRequested": false,
      "isBlockedByMe": false,
      "hasBlockedMe": false,
      "mutualFriendsCount": 27,
      "latest_chat": null,
      "unread_chats_count": 0,
      "createdAt": "2023-09-29T11:05:01.000Z",
      "updatedAt": "2023-12-19T14:55:34.000Z",
      "deletedAt": null
      }

    I'm using phone_number as an Identity of clavertap....

@shivamsharma2710 I have a deadline today please reply if possible....

Hi @mehul7616,

We use the 'Identity' property as an identifier to decide whether to create a new profile or merge it. We don't use the 'Phone' property as an identifier. Therefore, please pass the value that makes your user unique to the 'Identity' key. This ensures that the profiles of each user are not merged.

@shivamsharma2710 you are getting wrong I'm using "phone_number": "9671753743" as a 'Identity' so phone number is everytime different

@mehul7616 that's fine, but it's important to note that our system relies on the 'Identity' key to distinguish between new and existing profile. So, please make sure to include the 'Identity' key besides the phone_number.

@shivamsharma2710 Okay. can you please tell me what is the actual problem here? I have gone through everything but couldn't find the issue.

@mehul7616 Could you please provide more specific and accurate details regarding the data you're sending in the onUserLogin()? The information in the ticket description seems to differ from what was mentioned here:(#521 (comment)).
In the shared example, you're not sending the 'Identity'. Please check that.

@shivamsharma2710 i have to share response of clavertap after onloginuser() please check in both response Identity is diffrent

  1. [{"g":"__a40e5c2b73bb48aaa7fb0535a8e29b79","type":"meta","af":{"Build":"57","Version":"1.0.57","OS Version":"10","SDK Version":40609,"Make":"Xiaomi","Model":"Redmi K20","Carrier":"","useIP":true,"OS":"Android","wdt":2.68,"hgt":5.47,"dpi":440,"dt":1,"abckt":"active","cc":"in","wifi":true,"BluetoothVersion":"ble","Radio":"Unknown"},"id":"","tk":"","l_ts":1703149356,"f_ts":1703141843,"ct_pi":"Email,Identity","ddnd":false,"rtl":[],"rct":0,"ait":0,"frs":false,"arp":{"sv":40609,"dh":995705062,"wdt":2,"d_ts":1703141843,"hgt":5,"av":"1.0.57","v":2,"e_ts":0,"j_n":"ZG9iewY=","i_n":"Yw==","r_ts":1703149356,"id":"","k_n":"DHh5cgMGAgFvYmR4YG5naR4SBwdiYmp9ZG1mfhBt","j_s":"{}"},"imp":0,"tlc":[]}, {"profile":{"Email":"null","First Name":"Mehull","Photo":"
    ","Gender":"male","MSG-email":false,"MSG-sms":true,"Name":"Mehull Kathiriya","Privacy":"Private","@username":"@mehul7616","User Bio":"nothing t9sjshshhwwh","Phone":"7383805893","Nominated By":"@rinkushah","Identity":"7383805893","User Id":"6","Total Invites":0,"Invites Pending":0,"Following":0,"Notification Permission":"","Followers":0,"MSG-push":true,"MSG-whatsapp":true,"Nominated Count":0,"Date of Birth":"1999-11-16","Phone Number":"7383805893","Last Name":"Kathiriya","Contact Permission":"","cc":"in","tz":"Asia/Kolkata"},"s":1703149305,"pg":4,"type":"profile","ep":1703149354,"f":false,"lsl":64,"dsync":true}]

[{"g":"__a40e5c2b73bb48aaa7fb0535a8e29b79","type":"meta","af":{"Build":"57","Version":"1.0.57","OS Version":"10","SDK Version":40609,"Make":"Xiaomi","Model":"Redmi K20","Carrier":"","useIP":true,"OS":"Android","wdt":2.68,"hgt":5.47,"dpi":440,"dt":1,"abckt":"active","cc":"in","wifi":true,"BluetoothVersion":"ble","Radio":"Unknown"},"id":"","tk":"","l_ts":1703149660,"f_ts":1703141843,"ct_pi":"Email,Identity","ddnd":false,"rtl":[],"rct":0,"ait":0,"frs":false,"arp":{"sv":40609,"dh":995705062,"wdt":2,"d_ts":1703141843,"hgt":5,"av":"1.0.57","v":2,"e_ts":0,"j_n":"ZG9iewY=","i_n":"Yw==","r_ts":1703149661,"id":"","k_n":"DHh5cgMGAgFvYmR4YG5naR4SBwdiYmp9ZG1mfhAcEx9ua2V4b2lqewcICAd1dnB8ZGJhcwIFCQ1keA8=","j_s":"{}"},"imp":0,"tlc":[]}, {"profile":{"Email":"null","First Name":"Sagar","Photo":"","Gender":"male","MSG-email":false,"MSG-sms":true,"Name":"Sagar Nikam","Privacy":"Private","@username":"@sagar_1015","User Bio":"I am sagar test user\nhello\nrain rain come again\nrain rain come again","Phone":"8108289274","Nominated By":"@female","Identity":"8108289274","User Id":"8","Total Invites":0,"Invites Pending":0,"Following":0,"Notification Permission":"","Followers":0,"MSG-push":true,"MSG-whatsapp":true,"Nominated Count":0,"Date of Birth":"1995-05-15","Phone Number":"8108289274","Last Name":"Nikam","Contact Permission":"","cc":"in","tz":"Asia/Kolkata"},"s":1703149305,"pg":7,"type":"profile","ep":1703149658,"f":false,"lsl":64,"dsync":true}]

Hi @mehul7616,

I've identified the issue. You're passing "Email": "null" in every onUserLogin request, causing the profile to merge, and our system is considering the same profile since "Email" is also an identifier for us to distinguish between the new and existing profile.

So, I request you to please remove the "Email": "null" property from the map object. It will resolve the issue.

Please inform me once you've verified and share your findings.

@shivamsharma2710, The issue has been resolved thank you for your cooperation.