Top
Displaying content based on User Roles
  • 5 minutes to read
  • Print
  • Dark
    Light

Displaying content based on User Roles

  • Print
  • Dark
    Light

Whatfix enables you to show different content to different users with the use of Role tags. For example, an admin user can be shown more content and different content when compared to a basic user. This helps in targeting information based on what users can do on your application. Whatfix needs user information from your application to do this and one of the ways that the user's role is passed on to Whatfix is by using a window variable. Other ways to distinguish between users are also described below.

Step 1: Creating tags

Role specific tags have to be created for each role. For example, if you have 3 different roles (admin, editor, translator) you have to create tags for each role.

To create a role tag,

  1. Navigate to the Whatfix Dashboard.
    gotoDashboard(3)
  2. In the left panel, click Tags.
    dashboard_tags(2)
  3. On the top right, click Create Tag.
    tags_createTag(2)
  4. Enter a name and description for the tag.
    tags_name_Description(2)
  5. Click the Category drop-down menu and select Role Tag.
    tags_roleTag(2)
  6. Under Visibility Rules, select the desired criteria.
URL Hostname

The URL Hostname is the first part of any URL.
For example, the url https://www.example.com:888/x/y?z=a&b=c#d will return the hostname as www.example.com:888.

  • Set the visibility rule to URL Hostname.
  • Select the operator.
  • Enter the url hostname.

visibility_url_hostname(1)

URL Path

URL Pathname is the path section of the URL that comes after the host (domain) and before the query, including the initial slash if present.

For example, The url https://www.example.com:888/x/y?z=a&b=c#d will return the pathname as /x/y.

For this to work, a unique url path has to be established in the URL for each roles.

  • Set the visibility rule to URL Path.
  • Select the operator.
  • Enter the URL path.

visibility_url_path

URL Parameters

URL Hash can be used if you want to identify a role using the parameters value of your URL. Parameters values are usually present in the URL after the question mark "?".

For example, the url https://www.example.com:888/x/y?z=a&b=c#d will return the parameter as ?z.

For this to work, a unique parameter value has to be passed in the URL for each roles.

  • Set the visibility rule to URL Parameter.
  • Select the operator.
  • Enter the parameter value.

visibility_url_param

URL Hash

URL Hash can be used if you want to identify a role using the hash value of your URL. Hashes are usually present in Single page applications made using AngularJs or ReactJs. There are no page refreshes but only Hash changes.

For example, the url https://www.example.com:888/x/y?z=a&b=c#d will return the hash value as #d.

For this to work, a unique hash value has to be passed in the URL for each roles.

  • Set the visibility rule to URL Hash.
  • Select the operator.
  • Enter the hash value.

visibility_url_hash

Other element on page

You can identify and use elements on the page that are exclusive to a particular role. For example, if there is a tab that is visible only to admin users, then you can use that tab as the Other Element on Page variable.

  • Set the visibility rule to Other element on page.
  • Select the selector type.
  • Enter the selector value.

visibility_element_css_selector

Window Variable

Window Variable means that the variable is being declared at the global scope and is accessible to any JS code. If the user role in your application is not declared as a window variable this cannot be used. Developers can help in getting the relevant window variable name and its value.

Note: You don't need to add a window at the start for window variables.

  • Set the visibility rule to Window Variable.
  • Enter the variable name.
  • Select the operator.
  • Enter the variable value as mentioned in the code.

visibility_window_var

  1. Click Create.
  2. Similarly, follow the above steps to create tags for each role.

Step 2: Associating tags to content

Once you've created tags for each roles, all the Whatfix content has to be associated with a tag.

For example, if you want to show a Flow called 'creating leads' to all the users then add admin, editor, and translator tags to the content.

  1. Navigate to Whatfix Dashboard.
    gotoDashboard(3)
  2. Select the content you want to tag using the circular checkboxes at the top right corner of each tile.
    multiple_select_content_tile(1)
  3. Click the Manage Tags icon.
    manage_tags(1)
  4. In the popup, type the name of the tag and select from the list.
    manage_tags_settings_icon
  5. Click Done.
  6. Similarly, follow the above step to associate content to each role tags (editor, translator).

Step 3: Creating a segment

Creating segments ensures where your users will see content. A segment is created and configured with the necessary visibility rules so that relevant content is shown to the right role on the right page.

To create a segment,

  1. Navigate to the Whatfix Dashboard.
    gotoDashboard(3)
  2. Click Widgets.
    Dashboard_widgets(2)
  3. Select how you want to display the content. Here, the Self Help is selected.
    click_self_help
  4. Click New Segment.
    manage_tags(1)
  5. Enter the name for the segment.
  6. Click the + Select button.
    click_select(1)
  7. Click Select by Tags.
    select_by_tags
  8. Enter the tag name and click Okay.
    select_content_by_tags
  9. All the content associated to the tag is added.
  10. Now, under the Visibility section, select Role Tags.
  11. Select Exists and then select the tag (admin).
    visibility_role_tag_value
  12. Click the Plus icon to add where do you want to display the content.
    add_rule_icon
  13. Here, URL is selected. However, you can use different paramaters that match your criteria.
    additional_visibility_url_rule
  14. Click Save.
  15. Similarly, new segments have to be created for each role.

Was this article helpful?