Top
Segment Whatfix content using User Attributes and Google Sheets
  • 20 Aug 2025
  • 7 Minutes To Read
  • Dark
    Light
  • PDF

Segment Whatfix content using User Attributes and Google Sheets

  • Dark
    Light
  • PDF

Article summary

Whatfix enables you to use to segment content to show it to specific users using a Google Sheet integration. This method is useful when you want to display content to to a specific group of users.

What is a User Attribute?

Use Cases

Create a Google Sheet with User Data

Create a User Attribute

Create an Integration on the Dashboard

Run the integration

Use the User Attribute in Visibility Rules


What is a User Attribute?

Whatfix User Attributes enable you to fetch end-users' information such as role, signup date, department, and subscription plan, from your application and use them in Google Sheets for easy content segmentation and personalization.

For more information, see User Attributes.

Use Cases

  • A department-based Training Task List that contains the weekly training materials and tasks for that appears only to new joinees. You can segment the Whatfix content with your team members' names.

  • Pop-up embedded with the NPS survey to appear only to customers who haven’t yet filled out the survey. You can segment the content based on the email IDs.

Note:

  • To modify user-related data in Google Sheets for content segmentation, you need to update the file manually and rerun the integration for the changes to take effect.

  • To avoid manual updates, create Cohorts in Whatfix Product Analytics and use them as Visibility Rules. Cohorts refresh automatically whenever a user meets the Cohort criteria (for example, joins a new country, performs an action in the application, or interacts with Whatfix content), they’re added to the Cohort and immediately see the relevant Whatfix content. For more information, see Add Cohorts as Visibility Rules.

Create a Google Sheet with User Data

Use the following steps to create a Google Sheet with User Data (User Name and User Attribute):

Note:

The following example steps show how you can display content to a specific group of people in a department.

  1. Create a Google Sheet with end-user specific information available on the application. Here’s an example:

Info:

Name is the user information available in the application and insalesdepartment is the User Attribute. The User Attribute value is set to Yes. This means that when the value of the User Attribute is Yes; it fetches the team members' names and can be used to display content only to those who match the criteria.

  1. Click Share.

Note:

Whatfix must be granted the required access permissions to fetch data from the Google Sheet.

  1. Select Anyone with the link.

  1. Click Done.

Create a User Attribute

Use the following steps to create a user attribute to identify the users:

  1. On the Whatfix Guidance dashboard, click Settings.
    ia_left_nav_settings

  2. Click App integrations.
    ia_left%20nav_app%20integrations

  1. Under My Integrations, click Attributes.
    ia_db_integrations_attributes.png

  1. In the User Attributes tab, click + User Attribute.
    ia_db_add_user_attribute.png

  1. Enter the User Attribute Name and select its Variable Type. For example, the User Attribute Name is insalesdepartment and the Variable Type is string.Create_user_attribute

Info:

The following table lists the Variables Types and their description for a User Attribute:

Variable Type

Description

String

A user attribute that is an exact match of a string value, such as a username.

Encrypted_string

A String variable type, but the data is encrypted and stored in a database.

Double

Specify a single number. For example, employee number.

Boolean

A user attribute that has either true or false values. For example, whether or not the user had upgraded their plan or visited a specific section of the app.

Timestamp

Select this option to specify a single date and time, such as the user’s birth date or signup date.

User Attribute Name: The name cannot begin with numbers, include spaces, or contain special characters (except underscores).

  1. Click Save.

Create an Integration on the Whatfix Guidance Dashboard

Now, let’s create a Google Sheet Integration on the Whatfix Guidance Dashboard to fetch user data.

  1. On the Whatfix Guidance dashboard, click Settings.
    ia_left_nav_settings

  2. Click App integrations.
    ia_left%20nav_app%20integrations

  1. Click Dashboard.

  1. Click Advanced Integration.

  1. Enter an Integration Title, Integration Description, and then select Google Sheets as the Targeted Application.

  1. In STEP 1 of the integration, choose the Step Type as JAVASCRIPT from the drop-down menu, and then insert the following code in the Script field:

/*************** GoogleSheet Configuration ************/

// Replace spreadsheet id with Google spreadsheet id you have created.
attributes.google_spreadsheet_id = '1TIyldYVjw1a9RoD3jnTPizrKoxnc7bnLLaU9D4eM-pI';

// Replace sheet name
var google_sheet_name = encodeURI('Demo');

//Replace start cell number of your GSheet
var startCell = 'A2';

//Replace end column number of your GSheet
var endCell = 'B';

attributes.range = google_sheet_name + '!' + startCell + ':' + endCell;

/*************** Whatfix Configuration ************/

attributes.whatfixApiDomain = 'api.whatfix.com';

// Replace it with your Whatfix enterprise ID.
attributes.accountId = 'ent_id'; 

// Replace it with your username.
attributes.username = 'john_doe@whatfix.com'; 

 // Replace it with Whatfix api token.
attributes.apiKey = 'API_key';

Note:

You can find instructions in the code commented with a double slash character where you need to enter values specific to the user and organization creating the Google Sheet Integration. Perform the following changes in the above code:

  • In the value var startCell = 'A2', replace A2 with the starting cell value of the data present in your Google Sheet (exclude the title).

  • In the value var endCell = 'B’, replace B with the ending cell value of the data present in your Google Sheet.

  • In the value attributes.accountId = 'ent_id', replace ent_id with the ENT ID of your account. To find the Enterprise ID of your account, see How do I find my account ID and account name?

  • In the value attributes.apiKey = 'API_key', replace API_key with your API Token value: To generate an API Token, see Generating the API Token.

  • In the value attributes.username = 'john_doe@whatfix.com’, replace john_doe@whatfix.com with your email id.

  1. In the above code, enter the Google Sheet ID of your sheet as shown below for the value attributes.google_spreadsheet_id.

  1. Enter the Name of the Google Sheet as the value for attributes.range google_sheet_name = '';.

  1. Click the + icon. In STEP 2 of integration, choose the Step Type as REQUEST. In the Connect App section, select Google Sheets.

  1. Click Add Connection and allow Whatfix permission to access Google Sheets.

  1. Select a connection; denoted by the time and date that you added the connection. You can choose to enter a Description.

  1. In the URL section, select GET from the drop-down menu and insert the following URL.

https://sheets.googleapis.com/v4/spreadsheets/${attributes.google_spreadsheet_id}/values/${attributes.range}
  1. Click the + icon. In STEP 3 of integration, choose the Step Type as JAVASCRIPT and enter your JavaScript code in the Script field. Here’s an example:

var endUsers = [];

if (input.values && input.values != null && input.values.length > 0) {
  // Form end user objects
  for (i = 0; i < input.values.length; i++) {
    if (input.values[i][0] && input.values[i][0] !== '') {
      // Make sure 'IsSMComplete' user attribute is already created.
      var eu = {
        'id': input.values[i][0],
        'custom': {
           'user_attribute': input.values[i][1]
        }
      };
      endUsers.push(eu);
    } else {
      console.log(
        'INFO: Invalid end user ID. Skipping this row data of sheet.'
      );
    }
  }
} else if (!(input.values) && input.range) {
  console.log(
    'ERROR: No data found in provided google sheet. Terminating integration run...'
  );
  sys.exit();
} else {
  console.log('SUCCESS: All end users created/updated successfully in Whatfix.');
  sys.exit();
}

/**************** CREATING/UPDATING END USERS IN CHUCK OF SIZE=2000 USERS *************************/

if (endUsers.length <= 0) {
  console.log('ERROR: INVALID_GOOGELSHEET - No valid end user data found.');
  sys.exit();
} else {
  var start = 0;
  var end = 2000;
  var offset = 2000;
  var links = [];
  var url = 'https://' + attributes.whatfixApiDomain + '/v1/accounts/' + attributes.accountId + '/endUsers';
  var reqHeader = {
    'x-whatfix-integration-key': attributes.apiKey,
    'x-whatfix-user': attributes.username,
    'Content-Type': 'application/json'
  };

  while (start <= endUsers.length) {
    var reqBody = endUsers.slice(start, end);
    var link = {
      method: 'PUT',
      URL: url,
      headers: reqHeader,
      body: reqBody
    };
    links.push(link);
    start += offset;
    end += offset;
  }
  output.nextLinks = links;
}

  1. Click Save.

Run the Google Sheet Integration

Use the following steps to run the integration:

  1. On the Whatfix Guidance dashboard, click Settings.
    ia_left_nav_settings

  2. Click App integrations.
    ia_left%20nav_app%20integrations

  1. Click the more icon for the Integration you have added.

  1. Click Run now.

Info:

For more information, see Scheduling an Integration.

Use the User Attribute in Visibility Rules

Use the following steps to add the user attribute as a Visibility rule to the widget you want to segment:

Note:
If you see the following UI, you have the Advanced Visibility Rules enabled for the account. For more information, see Understand Advanced Visibility Rules.
Visibility Rules 2.0 screenshot
  1. Edit the widget that you want to show only to the user part of the Sales department.

  1. In the Visibility tab, select User Attribute.

  1. Select the User Attribute you have created.

  1. Select the operator value Equals and enter the value Yes.

  1. Configure the other Visibility rules as required, and then click Save.

Note:

Once you have saved the widget, preview the changes using the Preview extension, and then publish the widget to Production so that the latest behavior reflects for your end users.


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.