Skip to content

User Profiling & Opt-out

NearIT creates an anonymous profile for every user of your app. You can choose to add data to user profile. This data will be available inside recipes to allow the creation of user targets.

Define your Data Mappings

First, you need to define data mappings in the "Settings> Data Mapping" section of NearIT web interface.

Once you defined your mappings, you can start adding data to user profile:

Add user-data to NearIT

You can set user data with this method:

nearit.setUserData('name', 'John');
nearit.setUserData('name', 'John');

All values (even booleans and numbers) must be provided as strings.

If you want to set a date as a value, you have to use the format "MM-dd-yyyy".

If your data mapping is of type List (multiple choice) you can set data as follows:

nearit.setMultichoiceUserData('interests', {'food': true, 'drink': true, 'exercise': false});
nearit.setMultichoiceUserData('interests', { food: true, drink: true, exercise: false });

WARNING: With multiple choice data you should always provide an object with values for all the keys, even keys whose value did not change. Keys missing from the object will have their value overridden by false.

You can delete the value for a certain user data, passing null as the value for its key:

nearit.setUserData('gender', null);
nearit.setMultichoiceUserData('interests', null);
nearit.setUserData('gender', null);
nearit.setMultichoiceUserData('interests', null);

Fetch User-data from NearIT

You can get the current user data with this method:

nearit.getUserData(
    function(userData) {
        // SUCCESS: you got userData
    },
    function(errorMsg) {
        // ERROR: failed fetching userData
    }
)
nearit.getUserData(
    userData => console.log(userData),
    errorMsg => console.log(errorMsg)
);

Save the profile ID!

If you can, we recommend you to store the NearIT profileID in your CRM database for two main reasons:

  • it allows you to link our analytics to your users
  • it allows to associate all the devices of an user to the same NearIT profile.

You probably have a sign in system in your app, you should request the profile ID from NearIT before the user signs in:

nearit.getProfileId(
    function(profileId) {
        // SUCCESS: you got user profileId
    }, function(error) {
        // ERROR: failed fetching profileId
});
nearit.getProfileId(
    profileId => { /* SUCCESS: you got user profileId */ },
    errorMsg => { /* ERROR: failed fetching profileId */ }
);

If you detect that your user already has a NearIT profile ID in your CRM database (i.e. after a sign in), you should pass the profile ID to NearIT:

nearit.setProfileId(profileId);
nearit.setProfileId(profileId);

Whenever a user signs out from your app, you should reset the NearIT profileID:

nearit.resetProfileId(
    function(newProfileId) {
        // SUCCESS: you got the new profileId
    }, function(error) {
        // ERROR: failed resetting profileId
    });
nearit.resetProfileId(
    newProfileId => { /* SUCCESS: you got the new profileId */},
    error => { /* ERROR: failed resetting profileId */ }
);

Opt-out

You can opt-out a profile and its devices:

nearit.optOut(
    function() {
        // SUCCESS: user successfully opted-out
    },
    function(error) {
        // ERROR: failed opting-out user
    });
nearit.optOut(
    () => { /* SUCCESS: user successfully opted-out */ },
    error => { /* ERROR: failed opting-out user */ }
);

If the opt-out call is successful all the user-data and trackings will be deleted and the SDK will cease to work (the user's devices will not receive further notifications).