Target Audiences (with labels)
AppNavi allows to filter content for specific groups (Target Audiences). For example, certain content can be displayed only for certain groups or a specific user. To enable audience filtering for an object, one or more labels must be specified when publishing. When an object with labels is published, it is not initially displayed in the avatar. The object only becomes visible when one of the assigned labels has been set via the setTargetAudienceConditions API. The functionality is shown in the following code example.
var configuration = {labels:['Group1', 'Group2']}
window.appnaviApi.application.setTargetAudienceConditions(configuration);
console.log('Labels: '+ configuration.labels );
In this case, all objects with the label Group1 or Group2 would be displayed in the avatar view. It is also possible to use the setTargetAudienceConditions API asnychronously. This can be the case, for example, if the objects like routes are to be displayed with the results of an AJAX call or another asynchrounus event. In the example shown below, the two objects with the specified labels Group1 and Group2 would only become visible in the avatar after 5 seconds.
window.appnaviApi.application.resetCustomLabels();
window.setTimeout(function () {
window.appnaviApi.application.setTargetAudienceConditions({labels:['Group1', 'Group2']});
}, 5000);
Since the custom labels are stored in the local storage, it is necessary to reset the already set custom labels. This can be achieved by the method call resetCustomLabels(). The method call ensures that the custom labels are reset and a re-rendering of the corresponding view in the avatar takes place.
Updated almost 2 years ago