Show Top 15 Pages/Posts on website - Google Analytics

Google Jul 29, 2018

This post is an extension of my Google Analytics solution which I posted in my previous posts:

Server Integration With Google Analytics

Display Page Views On Your Pages - Google Analytics

In this post, I will talk about one more useful thing that is very common to website especially blog sites that we can do with Google Analytics i.e Showing top visited pages on your website. This is simple with the Google Analytics response with list of all pages with their corresponding page views. To know more about integration with Google Analytics, please visit my previous posts.

To accomplish this, we need to do following things:

  1. Get the response from google analytics
  2. Re-arrange it to create a map of all pages with their title and total pageviews like below:
    {"/path/to/page" : { "title" : "page title", "count": 200}}
  3. Re-order this response in descending order by reading count attribute to get most viewed/visited pages on top.
  4. Use this response to make anchor tags with title as label, key as href on your website


Below is code written in NodeJS:

Happy Coding!!

Related Tags:

Google   JavaScript   OAuth   Integration   NodeJS   Analytics   PageViews