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:

Get the response from google analytics

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}}

Re-order this response in descending order by reading count attribute to get most viewed/visited pages on top.

Use this response to make anchor tags with title as label, key as href on your website

Screenshot

Below is code written in NodeJS:

Happy Coding!!

]]>https://blog.lkatney.com/2018/07/29/show-top-15-pagesposts-on-website-google-analytics/ba23adaa-cf0f-40df-8ec0-a5f7ddb6061dSun, 29 Jul 2018 00:06:03 GMTIn this tutorial, I will mention step by step process to implement integration with Google Analytics or any google product through APIs.

In this example, I will specifically integrate Google Analytics with NodeJS.

Prerequisite Setup

Should have Google Analytics account

Should be added to any website to track some data and get them in APIs.

Steps to create a server key from Google

Once reporting API is enabled, create a new server key under credentails

Download this server key in JSON format file. This file looks like this.

The last step is to create a user on Analytics with server key information. Under your Admin > your property > User Management, create a new user with client_email mentioned in server key.

Once all steps are done, you are ready to implement your integration.

NodeJS Example Code for integration

Request Composer

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.

In case of any questions/concerns, please feel free to leave a comment below.

Happy Coding ;)

Related Posts

]]>https://blog.lkatney.com/2018/03/10/server-integration-with-google-analytics/01971e93-0767-4702-8d87-5b07a836d554Sat, 10 Mar 2018 23:45:06 GMTIn 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.

Happy Coding!!

Related Posts

]]>https://blog.lkatney.com/2018/03/10/display-page-views-on-your-pages-google-analytics/0a744824-063d-43a7-854d-f8d1946dbeddSat, 10 Mar 2018 18:12:44 GMTEveryone knows the importance of analytics. It has become a necessity on websites specifically for blogs or new products on websites(a lot of many scenarios) to monitor the performance of brands/products/websites and gather information about how people are responding to it.

In this post, I am using Google Analytics as my analytics platform due to following reasons:

It's from Google so trustworthy.

It's free so no money problem.

Very easy to use and manageable. Don't need a big team to manage it.

Prerequisite Steps

To use Google Analytics, you need to complete following steps:

signup with Google Analytics with your personal or business Google credentials and it will

Create a property. The property will provide a unique key called Tracking Id that needs to be added to your website to start tracking. To do that, go to Admin > Create new property

Tracking Id looks like this UA-XXXXX-Y

How to add this tracking Id to your website

To add this tracking Id, google analytics create a generic code with your tracking id to be included anywhere on your website. You can find your tracking code by going into your newly created property then Tracking Info > Tracking Code. Just paste the code into your website or specific page and it will start sending your traffic details to Google. The code looks like below:

Today I am going to share my experience with google maps on Salesforce. First of all, I must tell you that working with google maps is very cool, interesting & addictive. You can spent hours and hours digging into this. Let's start this post.

There are many libraries available for Google Maps that can be directly embedded into anywhere like Native Android/IOS application or in any web page. You can find all libraries here.

In this tutorial, I am going to use Google Map JavaScript API as I have made a web demo. This app is sample demo app to search for nearby agents of a company and customers can contact their nearby agents for query. At the same time, Agents can locate their current position onto system for real time updates to customers/companies.

Screenshots below will make more sense:

Let's start building a page

To start off, you have to request an API key for Maps from google. That can be done by going to Google API Console and following steps:

Create or select a project.

Click Continue to enable the API and any related services.

On the Credentials page, get a Browser key (and set the API Credentials). Note: If you are using this page for Salesforce 1, You have to create two more keys i.e. Android key & IOS key to support Salesforce 1 otherwise maps won't behave properly

After creating a project & getting API Keys, you have to refer google maps on your page like below:

Now to make this page intuitive & dynamic, We can add some VF remoting methods that will get agents nearby & set location for agents on Salesforce. I am not going to list all things here, the detailed code can be simply seen at this github repo.