Thursday, November 10, 2016

Google Analytics Tracking for WSO2 App Manager

Google Analytics is a free Web analytics service that provides statistics and basic analytical tools. We can configure WSO2 App Manager to track web application and sites invocation statistics through Google Analytics.

First, let's see how to setup a google Analytic account.

1. Go to http://www.google.com/analytics/ and Click on Analytic tab.
2. Then, click on "Admin" tab and create a New Account.
3. Click on "Website" and give account information like in below. Here, you have to fill the information which you want to track.
4. Click on 'Get Tracking Id'. Then you will redirect to a page like below. From there you can get the Tracking Id.
5.  Configure WSO2 App Manager with received Tracking code. Enable google analytics and add TrackingID of <APPM_HOME>/repository/conf/app-manager.xml as shown below.
   
  <GoogleAnalyticsTracking>  
 <!--Enable/Disable Google Analytics Tracking-->  
      <Enabled>true</Enabled>  
      <!--Google Analytics Tracking ID-->  
      <TrackingID>UA-86711225-1</TrackingID>  
 </GoogleAnalyticsTracking>  
   
6. Restart server.
7. Place the below JavaScript code snippet into the pages that you need to track with your Google Analytics account.
   
 <script language="javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript">  
   function invokeStatistics(){      
   var tracking_code = ["<TRACKING_CODE>"];      
   var request = $.ajax({      
     url: "http://<AM_GATEWAY_URL>:8280/statistics/",      
     type: "GET",      
     headers: {        
       "trackingCode":tracking_code,      
       }         
     }  
   );    
 }  
 </script>  
   

Now we have successfully integrated WSO2 App Manager with Google Analytics. Let's see how we can see the statistics.

Real-time statistics


Then go to Google Analytics [http://www.google.com/analytics/] and select the created account above.

The following image shows an invocation of a specific Web application. The Google Analytics graphs and statistics are displayed at runtime in its Real-Time view. In below graphs, you will able to see a hit on "PageViews" per second and active users.


Reporting statistics

Google Analytics reporting statistics will take more than 24 hours from the time of invocation.

A sample dashboard with populated statistics is shown in below.


No comments:

Post a Comment