- 23 Jul 2024
- 5 Minutes To Read
-
Print
-
DarkLight
-
PDF
Fetch and process information for Identification rules
- Updated On 23 Jul 2024
- 5 Minutes To Read
-
Print
-
DarkLight
-
PDF
Overview
It’s often necessary to be able to identify your users to show content that is relevant to them. When creating a custom rule to identify a user or language in your application, you need to define the following:
Where does Whatfix get unique identification data from?
How can Whatfix read the data?
A Sequence is a single set of instructions that tells Whatfix how to capture and identify data for the custom rule. It comprises a fetcher and processor.
The fetcher enables you to select from where you want to pull the value that defines the rule. For example, if each user has a unique identifier based on the cookie value, select From Cookie as fetcher.
The processor enables you to parse the fetched value using JSON or String Operations.
Your title goes here
Add multiple processors to parse the fetched value. Click + Add Processor to add another parsing method.
Click + Add Sequence to add more identifiers. This enables you to fetch a different value and parse it for another unique identification rule.
Capture information using Fetcher
Whatfix enables you to fetch data from various sources. Uniquely identify a user or locale based on what works best for your application. This lets Whatfix show analytics data based on User id, segment content for specific groups of users, identify users for Cohorts, and more.
Based on your requirements, pull identification values from different sources using the following fetcher options:
Fetcher option | Description |
---|---|
Fetch Cookie | Retrieves data from browser cookies. For example, if your application stores user id in the user_id cookie, enter user_id as the Key of the cookie from where you want to pull the value. |
Fetch Element Attribute | Retrieves data from attributes of HTML elements. Based on your requirements, choose a Selector Type (CSS or JQuery), enter Selector Value, Index, and Attribute Name. For example, consider that you have a CSS selector called user-id that contains all user id data. From this selector, you want to find each users’ unique id that is stored as data-userid at the 4th index position in the user-id attribute. Set Selector Type as CSS, Selector Value as data-userid, Index as 4, and Attribute Name as user-id. |
Fetch from Local Storage | Retrieves data stored in the browser's local storage. In the Key section, enter the value you want to retrieve from the local storage. For example, if your application stores user role data in the locale storage as user-role, enter user-role as the Key from where you want to pull the value. |
Fetch from Session Storage | Retrieves data stored in the browser's session storage. This is similar to local storage, but the data is stored for the duration of the browser session. In the Key section, enter the value you want to retrieve from the session storage. For example, if your application stores session usage data in the locale storage as section-count, enter session-count as the Key from where you want to pull the value. |
Fetch Element Text | Retrieves text data from attributes of HTML elements. Based on your requirements, choose a Selector Type (CSS or JQuery), enter Selector Value, and Index. For example, consider that you have a CSS selector called data-username that contains each users’ name that is stored at the 2nd index position. Set Selector Type as CSS, Selector Value as data-username, and Index as 2. |
Fetch from URL | Retrieves information directly from the URL. For example, if your URL is https://whatfix.com/user/123, Whatfix retrieves the entire URL. |
Fetch from URL Hostname | Retrieves the hostname from the URL. For example, for the URL https://subdomain.whatfix.com/path, Whatfix retrieves subdomain.whatfix.com. |
Fetch from URL Hash | Retrieves data from the URL hash. For example, if your URL is https://whatfix.com/page#section1, Whatfix retrieves section1 from the URL hash. |
Fetch from URL Path | Retrieves information from the URL path. For example, for the URL https://whatfix.com/user/123, Whatfix retrieves /user/123 from the URL path. |
Fetch from URL Parameter | Retrieves data from a specific parameter in the URL. For example, if your URL is https://example.com/page?param1=value1, and Whatfix can retrieve the value associated with the key param1 (i.e., value1). |
Return Value of Function | Allows the execution of a custom function, and the return value is used as the identification value. In the Function Name section, enter the JavaScript function whose return value you want. For example, you can have a JavaScript function getUserLogin() that returns a true or false value based on if the user is logged in. |
Window Variable | Retrieves data from a variable stored as a Window Variable. In the Key section, enter the name of the Window Variable. |
Parse captured information using Processor
Whatfix enables you to process the raw data obtained from the fetcher and extract the relevant information needed for your custom rule. The processor provides options for performing actions such as parsing JSON and applying string operations.
JSON Operations
If your fetched data is in JSON format, the processor can be configured to extract specific values from the JSON structure. This is useful when the data you need is nested within a larger JSON object.
Whatfix enables you to use the Read Key JSON operation, which means that the processor allows you to extract a specific value from a JSON structure based on a given key. Here's an example Sequence,
Fetch JSON data representing a user profile:
Where do you want to fetch the user from?: Fetch from Local Storage (Assuming the JSON data is stored in local storage)
Key: user_profile_data
Extract the user's email address from the fetched JSON object:
How do you want to process it?: JSON Operations
JSON Operations: Read Key
Select JSON: Output of Fetcher
Key Name: user.email
The JSON structure might look like: {"user": {"name": "John Doe", "email": "john.doe@whatfix.com"}}. The processor is set to read the key user.email
to extract the user's email address.
The processed result would be john.doe@whatfix.com. In this example, the fetcher retrieves the JSON data from local storage under the key user_profile_data. The processor is then configured to read the key user.email from this JSON structure, resulting in the extraction of the user's email address.
String Operations
If your data is in a string format, the processor enables you to perform string operations to extract the relevant information. This can include actions like splitting a string, finding a substring, and more.
Based on your requirements, you can process your data using the following String Operations:
String Operation | Description |
---|---|
Join | Concatenates multiple strings into a single string. For example, if you want to add a specific string before the fetcher output:
|
Split | Divides a string into an array of substrings based on a specified delimiter. You can also use the Index to specify which part of the split result to select. For example, you want to extract only the email address from a long string,
|
Substring | Extracts a portion of a string based on specified start and end positions. For example, you want to extract only the first 4 letters of the user name from a long string,
|
To Lowercase | Converts all characters in a string to lowercase. For example, you want to convert the entire output to lowercase:
|
Trim | Removes leading and trailing whitespaces from a string. For example, you want to remove any extra space preceding
|