Display Page Views On Your Pages - Google Analytics

In my previous post, I discussed the importance of analytics on websites and how it can improve insights about any product or website. To setup Google Analytics on your website, please follow step by step process mentioned in this article Adding Google Analytics To Your Website.

Today, I am going to discuss a main feature of analytics that can enhance your user experience on your websites i.e. Page Views.

Page Views are really helpful in building up confidence amongst users as it ensures them that there are people who used/recommended this or atleast viewed this page.

NOTE: To implement page views, Google Analytics is being used in this example.

Prepare your website to send specific data

By so far, you must have implemented Google Analytics to your website by pasting tracking code. To log more information specific to pages, Google ask to send more information from your website. It is very simple and easy to implement. You must have already implemented if you used my previous post to setup.

ga('send', 'pageview'); //main method to send more details

To know more about this method, you can visit Google's page
Page Tracking

How to use this data

To use reported data, You need to implement an integration that can use Google Analytics API v3 or v4. By integrating, you can do one of following things:

Reports around your traffic

Page views for specific urls/pages

User management

Sessions information and so on.

In this example, I am specifically using Google Analytics Reporting v4 and NodeJS to securly implement server-server integration so that I can hit an endpoint and get all relevant information specific to a particular page like total number of page views.

Background about using NodeJS and server-server integration

Reporting APIs work with access token and to implement that I had to use OAuth2.0 for Google. To implement a secure connection without passing credentails, this is the best way wherein you can ask for a secure key from Google in form of JSON file and then store it securly on server to run integrations in background.

There is a good way to create and test your request before implementing it in your actual code by using Request Composer provided by Google. You can create your actual request APIs specific to your business here and see your response results as well.

Use of Google APIs to get page views - Actual Code

This server method asks url in a query parameter to get more insights about it from Google. In this particular example, we are asking for number of page views.

End-to-End

Actual website will hit this new server with url(as param) to get page view count.

In case of any queries/questions regarding its implementation, please leave a comment below. Happy to assist you as much as I can.