User & Attributes

Managing User Data

The NetmeraUser class allows you to send structured information about your application's users to Netmera. The ideal time to update user attributes is right after the user logs into your application.

User ID Management

For optimal performance and data integrity:

  • Update user information at login: It’s crucial to update the user information as soon as the user logs in.

  • Unique userId: Ensure that each user has a unique userId. Assigning the same userId to multiple users leads to data inconsistencies and is not recommended.

Updating User Information

After login, create a NetmeraUser object, set the attributes, and call Netmera.updateUser

val netmeraUser = NetmeraUser()
netmeraUser.setUserId("the_greatest")
netmeraUser.setMsisdn("001XXXXXXXXX")
netmeraUser.setEmail("clay@champion.com")
netmeraUser.setName("Muhammad Ali")
netmeraUser.setSurname("Clay")
netmeraUser.setExternalSegments(listOf("sports", "box"))
netmeraUser.setGender(NetmeraUser.GENDER_MALE)
netmeraUser.setDateOfBirth(GregorianCalendar(1942, 1, 17).time)
netmeraUser.setMaritalStatus(NetmeraUser.MARITAL_STATUS_MARRIED)
netmeraUser.setChildCount(9)
netmeraUser.setCountry("USA")
netmeraUser.setState("Arizona")
netmeraUser.setCity("Scottsdale")
netmeraUser.setDistrict("Old Town Scottsdale")
netmeraUser.setOccupation("Professional Boxer")
netmeraUser.setIndustry("Sports")
netmeraUser.setFavoriteTeam("My Team")
netmeraUser.setLanguage("English")
// Send data to Netmera
Netmera.updateUser(netmeraUser)

Important:

  • userId cannot be removed.

  • You should send a single user update request at a time.

Removing Attributes

To remove an attribute, set it to null:

val netmeraUser = NetmeraUser()
// This will remove previously set `email` value from Netmera
netmeraUser.email = null
Netmera.updateUser(netmeraUser)

Creating Custom Profile Attributes

Step 1: Navigate to the Developers section

Custom profile attributes must be created and configured in the Netmera Panel before they can be used in the application.

  • Go to Panel > Developers > Profile Attributes > Create New Attribute.

Step 2: Fill in Attribute Details

Define the following information:

  • Name: The unique identifier for the attribute.

  • Label: A user-friendly name for the attribute.

  • Description: A brief description of the attribute.

  • Data Type: Choose the appropriate data type for the attribute.

  • Is Array: Define whether the attribute can hold multiple values.

Step 3: Save the Attribute

After clicking Save, the custom attribute will be available for assignment to your users.

Step 4: Generated Code for Custom Attributes

Once the attribute is defined in the Netmera Panel, the generated code can be found at the bottom of the Profile Attribute page, under the Generate Code section. This code must be added to your Netmera Panel under Profile Attributes > User Class.

Private Information Considerations

Under the KVKK law, the sharing of private user data is prohibited. To ensure compliance:

  • Private Information Flag: When defining profile attributes or events, the Private Information feature must be selected to ensure that these attributes are not sent to the backend by the Netmera SDK.

  • SDK Enforcement: The SDK checks for the Private Information flag during the (Netmera.update(user)) call. If the flag is set, the request will not be sent to the backend.

Fetching Coupons

Retrieve and display user-earned coupons:

val page = 0
val max = 10

Netmera.fetchCoupons(page, max, object : NMFetchCouponsResultListener {
    override fun onSuccess(coupons: List<NMCouponDetail>?) {
        if (coupons.isNullOrEmpty()) {
            // No coupons exist
        } else {
            // Use coupons
        }
    }

    override fun onFailure(error: String?) {
        Toast.makeText(
            this@CouponActivity,
            error ?: "No error message",
            Toast.LENGTH_SHORT
        ).show()
    }
})

User Update with Listener

From version 3.11.1, you can track update results using a listener:

Netmera.updateUser(netmeraUser, new NMUpdateUserListener() {
    @Override
    public void onSuccess() {
        Log.i("NetmeraApp", "Netmera User was updated successfully");
        Toast.makeText(
            UpdateUserActivity.this,
            "Netmera User was successfully updated.",
            Toast.LENGTH_SHORT
        ).show();
    }

    @Override
    public void onFailure(@Nullable String error) {
        Log.i("NetmeraApp", "Netmera User couldn't be updated successfully :: " + error);
        Toast.makeText(
            UpdateUserActivity.this,
            "Netmera User couldn't be updated successfully :: " + error,
            Toast.LENGTH_LONG
        ).show();
    }
});

Last updated

Was this helpful?