Register a user

  • User will be registered anonymously right after SDK initialization. To set specific user attributes pass them using UserCom.getInstance().register() function. Usually we are registering client's information in LoginActivitiy when client pass some data in forms.

    You should copy registerUserComCustomer() method e.g. for example to LoginActivity(if you want to get client's attribute in this activity) and then call it in method in which you want to retrieve client's information.

    class LoginActivity{
        private void registerUserComCustomer() {
    
            Customer customer = new Customer()
                    .id("idfromyourdatabase") // id of your user
                    .firstName("John")
                    .lastName("Doe")
                    .email("myemail@example.com")
                    .attr("loyalCustomer", true)
                    .attr("age", 33)
    
            UserCom.getInstance()
                    .register(customer, new CustomerUpdateCallback() {
                        @Override
                        public void onSuccess(RegisterResponse response) {
                            Log.d(TAG, "onSuccess: " + response);
                            // user is registered and now you can send events via SDK
                        }
    
                        @Override
                        public void onFailure(Throwable throwable) {
                            Log.e(TAG, "onFailure: ", throwable);
                            // try again - something went wrong
                        }
                    });
        }
    }

    This will create a user in User.com with all the attributes you specify, or log in an existing one if data matches the record in User.com database.

    You can add any number of custom customer attributes, or use predefined, and combine them.

  • Logout

    To logout and clear all user-related resources withing SDK, invoke:

    UserCom.getInstance().logout();