Using Flow for Page View Tracking

Using Flow for Page Vew Tracking

Screen Flow is a type of flow that can be seen on a page. It can be used to collect or show information. Even though it's usually visible, it can also be hidden on a Lightning page. When the user looks at the page, the flow will still work, but since it is an Invisible Screen Flow, the user will not notice it. This way, you can take actions based on page views. There are many use cases of invisible screen flows. One of them is page view tracking.

Let's build an invisible screen flow that can be used for page view tracking.

Building an Invisible Screen Flow for Page View Tracking

1- First of all, create a custom object called Page View. This object will store the page views related to any object that you want. In this example, let's build the page view tracking flow for account and opportunity objects.

Create 2 lookup fields for Account and Opportunity, a lookup field for the User, and a date/time field for the view date.

Object for Page View Tracking

2- Create a screen flow and then create an input text variable called recordId. Since you won't launch this flow from an action, it is not a must to name it as recordId. Therefore, you can give any name that you want.

3- Just because we want to make this flow available for more than one object (Account and Opportunity), we need to know the object name. So that we will know which lookup field to populate (Account or Opportunity). Read this post to learn how to find the object name from record Id prefix.

Create a text formula that returns the first 3 characters of the recordId. This shows the object prefix and it is a key to understand the object name.

Formula for Object Prefix

4- Add a get records element to find the Entity Definition record. This object stores the key prefix and the object names.

Get Entity Definition

5- Add a decision element to check the name of the object. In this example, we are using standard objects, so you could just check if the recordId is starting with 001 or 006. However, if you want to build this page view tracking flow for a custom object, it is crucial to get the entity definition.

Decision Element to Check the Object Name

6- Add two different create records elements. One is for creating a page view record related to the account, and the other one should be related to the opportunity.

Create Records Element for Account Page View Tracking
Create Records Element for Opportunity Page View Tracking

Make sure that you are populating the correct lookup field with the recordId variable. On the other hand, fill the user lookup field with the current user and view date time field with the current date/time. Therefore, you will be able to track which user viewed which record and when it happened.

7- Add a blank screen as the last element of the flow. So that the users will not see the flow. This step makes the flow invisible.

Blank Screen

8- Whatever happens, everything should go to this blank screen. Connect all the fault paths too. The point is to make the flow invisible, so the users shouldn't see an error message.

At the end, your flow should look like this.

Invisible Screen Flow for Page View Tracking

Adding the Flow to the Lightning Record Page

The flow is ready. Now it is time to put it to Account and Opportunity Lightning record pages.

Edit the Lightning record page, then drag and drop a flow component from the left side. In order to make it completely invisible, place it into a white region. Make sure that you are passing the record ID into the recordId variable of the flow.

Adding the Flow to Lightning Record Page

Let's see the flow in action.

Page View Tracking

Use Cases

This invisible screen flow for page view tracking can be used for many purposes. You can put this flow to an Experience page (Community) and track the page views of your customers. For instance, this can show you if they are interested in a specific product, so that you can take an action. Another example is for security purposes. If you see that a user is viewing many account records in a short period of time, you can consider this as a suspicious behavior. Since it is a flow and you have all the possibilities, you can notify the user's manager, display a toast message, or do anything that you want.


This flow creates a record whenever a user views a page. If the user refreshes the page, the flow runs again and creates another record. Therefore, after some point, there will be thousands or millions of records in your system. Consequently, you should delete the old records after some time. If you are using this flow for security purposes as mentioned before, you can immediately delete the unsuspicious records.

As you can see, it is a very simple flow. However, you can improve it using some custom logic. For instance, you may want to store the unique page views. In order to do this, find a page view record related to the current user and the account record. If it exists, do not create a new page view record. Optionally, you can have a view count field on the object and add 1 to this number field. So that one page view record will show you how many times a user viewed this account record.

Be the first to comment

Leave a Reply

Your email address will not be published.