Introduction
We often see in many of the sites that the total page view count is shown. I have come across one of the use cases where I wanted to show how many times that page was visited by any user. In another use case, we will see how many view requests with details are posted means how many entries are made for any requests.
Scenario
We will see two scenarios in the article.
Objective
The objective of this requirement is very demanding as it is often seen total number of views on the page and how many people provided their views on any article. We will keep patching the latest count to a list row and keep showing on the powerapps.
Step 1. The list structure would look like below.
The list structure could be designed as per our needs. Here for a demo, I have created 3 different lists and shown the data with its list structure.
Article list structure
Article list content
PostViewsOnArticle list structure
PostViewsOnArticle Content
The third list will save data from powerapps and the list structure looks like below.
Step 2. Design screen and form as per requirement.
The below screenshot shows all the articles that are entered, on clicking on articles, we can see the details of the article and all the views that we got on that article. To show all articles, I have taken gallery control.
Below is the display form, which shows the variable View value. Variable View value shows gallery-selected item details.
Step 3. Save the Logged User in a Global variable.
We keep logged-in user details in a global variable for performance improvement. Otherwise, User().Email could directly be used wherever required.
Step 4. Add a list of DataSource from SharePoint.
Add PageViewCountItemWise List from SharePoint as DataSource.
So that the patch function can use this datasource to store the views and show them back on the PowerApp.
Step 5. Patch the count on the OnVisible Property of the page. Show total views on a page on power apps or view on page load.
We will patch on OnVisible property. If it first a time entry, then the patch function will create a new record, or other it will update the existing one.
Note. The onVisible property only runs after the screen is loaded. We have to manually load the screen for the first time. Go to any other screen and come back to this screen to run the OnVisible property.
Step 6. Must run the App’s Run OnStart.
We must run the below property in case we are not seeing the values.
Step 7. Add a Label and show it on the screen.
Add a label and show the count on that label. To look better we can have an icon with attractive visuals.
Container we use to enhance the UI by selecting.
Step 8. Add a Label and show it on the screen.
Add a label and show the count on that label. To look better we can have an icon with attractive visuals. We container as shown above to make the glossy look.
Here I am extracting the row count that is submitted for that particular article from the list.
Conclusion
In the above example, we saw how we could represent total views, opinions, or ideas submitted for an article. We also saw how to show page hit count.