SDK

Tags

In this page you'll learn more about device segmentation. With tags you can categorize devices through your app. Tags can assume as many forms as you want and a device can have an unlimited number of tags. This will be extremely useful if your app doesn't have any means of authentication and your audience is mainly composed by anonymous devices.

Common use cases for tags involve creating categories that separated devices by device model, capabilities or properties, like tablet, hasCam or en-GB. You might also allow users to subscribe to a list of pre-defined tags you include in your app. Many use cases for tags, allow users to subscribed to categories like wants_news_for_music or subscribed_newslleter. You can also register tags upon events in your app, like bought_shoes or was_near_beacon_x.

Tags are only available after a device has been successfully registered in Notificare so the best place to access, add or remove them is after device registration. Add the following to retrieve the list of tags assigned to this device:

public class MyIntentReceiver extends DefaultIntentReceiver {

    @Override
    public void onDeviceRegistered(NotificareDevice device) {

        Notificare.shared().fetchDeviceTags(new NotificareCallback<List<String>>() {
            @Override
            public void onError(NotificareError error) {
                //Handle error
            }

            @Override
            public void onSuccess(List<String> tags) {
                //Handle the tags list
            }
        });

    }


}

//...more code
class MyIntentReceiver: DefaultIntentReceiver() {

    override fun onDeviceRegistered(device: NotificareDevice?) {
        Notificare.shared().fetchDeviceTags(object : NotificareCallback<List<String?>?> {
            override fun onError(error: NotificareError) {
                //Handle error
            }

            override fun onSuccess(tags: List<String?>?) {
                //Handle the tags list
            }
        })
    }


}

//...more code

To assign a tag to a device, invoke the method below:

//...more code

Notificare.shared().addDeviceTags(tags, new NotificareCallback<Boolean>() {
    @Override
    public void onError(NotificareError error) {
        //Handle error
    }

    @Override
    public void onSuccess(Boolean success) {
        //Handle success
    }
});

//...more code
//...more code

Notificare.shared().addDeviceTags(tags, object : NotificareCallback<Boolean?> {
    override fun onError(error: NotificareError) {
        //Handle error
    }

    override fun onSuccess(success: Boolean?) {
        //Handle success
    }
})

//...more code

Or remove a specific tag from a device:

Notificare.shared().removeDeviceTag("some_tag", new NotificareCallback<Boolean>() {
    @Override
    public void onError(NotificareError error) {
        //Handle error
    }

    @Override
    public void onSuccess(Boolean success) {
        //Handle success
    }
});
Notificare.shared().removeDeviceTag("some_tag", object : NotificareCallback<Boolean?> {
    override fun onError(error: NotificareError) {
        //Handle error
    }

    override fun onSuccess(success: Boolean?) {
        //Handle success
    }
})

Finally you can also remove all the tags from a device:

Notificare.shared().clearDeviceTags(new NotificareCallback<Boolean>() {
    @Override
    public void onError(NotificareError error) {
        //Handle error
    }

    @Override
    public void onSuccess(Boolean success) {
        //Handle success
    }
});
Notificare.shared().clearDeviceTags(object : NotificareCallback<Boolean?> {
    override fun onError(error: NotificareError) {
        //Handle error
    }

    override fun onSuccess(success: Boolean?) {
        //Handle success
    }
})

You have now successfully implemented device tags and can start sending push notifications based on these categories.