Friday 17 March 2017

Step to Integrate Flurry in Android

Flurry Analytics integration in Android
What is Flurry Analytics?
Analytics gives us change to get insights of user behaviour .It Shows us exactly how people are using the mobile applications. Analytics can play a vital part in application development process. It enables us to identify areas of improvement and maximize Success in market.

Why Flurry Analytics?
You can gain deep insight into your customer's behaviour very quickly and with little effort using Flurry's Analytics service. The SDK integration process is designed to be as easy as possible. It provide an effective and efficient process to discover new user and their relevant uses. It provide behavioural features like event tracking and can shows user interactions (Custom Event).  Check the loyalty and visit Frequency, provide a way to find app Crashes, Exceptions and much more.
Note:- Before Going forward, Be sure that your development environment (Eclipse, Android developer tools and JDK) are setup Correctly. To ensure that follow Android Developer
Set Up Flurry Analytics 
Step 1:-. Download the Flurry Android SDK
  • If you have Flurry Account Login otherwise  or  you need to Sign up and Create account
  • Create Your Application
  • Select your platform Android
  • Then provide you application details and category
  • Verify your mail and download SDK.  
The archive should contain these files:
FlurryAnalytics_ver.jar:- The library containing Flurry's analytic collection and reporting code. This contains all Classes and interface required. 
FlurryAds_ver.jar:- The optional library to incorporate Flurry's ads into your application (where ver denotes the latest version of Flurry SDK).This library provide way to Monetize your applications.
ProjectApiKey.txt:- This file contains the name of your project and your project's API key.
Analytics-README.pdf: These are Pdf files Contains useful information. It decribes Flurry Analytics bottom to top Content.  
Step 2:- Add the FlurryAnalytics_x.y.z.jar to your classpath 
If you're using Eclipse, modify your Java Build Path, and choose Add External JAR.
To use a Flurry Analyics  (JAR file) inside your Android project, you can simple copy the JAR file into the folder called libs in your application.
The Android tooling adds the JAR file automatically to the classpath of your project. During deployment the Android tooling compiles the .class files in the Android .dex file which contains the Android byte-code.

Step 3:- Configure your AndroidManifest.xml to:
Get Internet permission in Manifest.
Specify a versionName attribute in the manifest to have data reported under that version name
Declare min version of Android OS the application supports.

Note: Flurry Supports Android OS Version 10(Gingerbread 2.3.6) and above  
<manifest xmlns:android=""
    android:versionName="1.0" >

        android:targetSdkVersion="20" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Step 4:- Add calls to onStartSession and onEndSession 
The following lines of the code need to be added to the each Activity of your application to accurately capture duration of users' interaction with the application.


Import FlurryAgent classes from android package of flurry SDK.
protected void onStart(){
    FlurryAgent.onStartSession(this, "YOUR_API_KEY");
Insert a call to FlurryAgent.onStartSession(Context, String), passing it a reference to a Context object (such as an Activity or Service), and your project's API key. I recommend using  the onStart method of each Activity in your application, and passing the Activity (or Service) itself as the Context object - passing the global Application context is not recommended.

protected void onStop()

Insert a call to FlurryAgent.onEndSession(Context) when a session is complete. We recommend using the onStop method of each Activity in your application. Make sure to match up a call to onEndSession for each call of onStartSession, passing in the same Context object that was used to call onStartSession.
You can use single sessions throughout your applications by using single context. 

Context :  Context that has called onStartSession but not onEndSession, this allow session to continued. You should not call new sessions immedataly after session is end. Ther should be minimum 30 seconds difference between the onEndSession and next onStartSession. If this conditions happens last session will continued.

So my recomdention is use Events. 

you can modify time window during which a session can be resumed, call FlurryAgent.setContinueSessionMillis(long milliseconds) before the first call to FlurryAgent.onStartSession. This provide you simple approach to change time Window during the application.

STEP 2: Custom Events :- 

User Specific actions that user take in your applications are called Events. These Events describes user action in your applications.
Examples   of event
user Click on Share Button and share playlist of song. You can generate an event of Share. Every time user shared playlist of songs, Share event is generated.
This helps you understand how users interact with your app.

There are two level structure used in Custom Events. You can use each level separately in your applications.

1. Event
2. Event parameters

Events have a two-level structure. The highest level is the specific action, in this case the playing song  in media player.
For example User clicked on play button of media player
Only single line of code is required to track this Event:

 FlurryAgent.logEvent("Play Button");

Events Limit Per Applications is 300.
If events are added to your applicatiob , Flurry will automatically build User Paths based on this data so you can see how a user navigates through your application.

Event Parameters
The second level in the Event structure is the Event parameter – these are characteristics of the Event itself or the user performing it.
You can capture Event parameters (which include the Event itself) with two lines of code:

        Map<String, String> SongParams = new HashMap<String, String>();
        articleParams.put("Singer", "Eminem");
        articleParams.put("User_Status", "Liked");
        FlurryAgent.logEvent("Song_played", SongParams);

Each Event can have up to 10 parameters, and each parameter can have an infinite number of values associated with it.
Event Duration
Flurry provide a dimension of time(Event Duration), this dimension provide a way to  track  event time. Flurry will automatically record the duration of the Event and provide you metrics on average Event length overall, by session and by user.
You can capture Event duration (along with the Event and its parameters) with a single log following this pattern:

        // Capture author info & user status
        Map<String, String> MediaParam= new HashMap<String, String>();
        articleParams.put("PlayList", "Eminen");
        articleParams.put("Song", "Won't back down ");
        FlurryAgent.logEvent("Song Track", MediaParam, true);
        // In a function that captures when a user navigates away from article      
        FlurryAgent.endTimedEvent("Song Track");

Flurry offers a number of advanced features that allow you to gain even greater insight into your users. Use the following methods to report this data:
Track Geographic Location 
Add these permissions in your Manifest 


These Locations Permission is used by Flurry to extract user Locations. Flurry will provide you Tracked  User Locations. At the end ,Flurry will provide report to you about areas in which your application is used(City level).   
To disable detailed location reporting even when your app has permission, call FlurryAgent.setReportLocation(false) before calling FlurryAgent.onStartSession() and no detailed location information will be sent.
Track Age and Gender 

Use this to log the user's age. Valid inputs are between 1 and 109.


Use this to log the user's gender. Valid inputs are Constants.MALE or Constants.FEMALE.
Track User ID


String or arguments should be non personal can not send personal informations as a argument. This will directly Violates the Flurry's Aggrement. 

Track Errors 

FlurryAgent.onError(String errorId, String message, String errorClass)

Use onError to report application errors. Flurry will report the first 10 errors to occur in each session. The FlurryAgent will also notify you of uncaught exceptions in the same way.
To disable this behaviour ,
use setCaptureUncaughtExceptions(false) before onStartSession.

Track page Views


Use onPageView to report page view count. You should call this method whenever a new page is shown to the user to increment the total count. you can detect user interaction within your applications. This provides valuable apporach to count user movement in your applications.

  Page View method is different from Custom Events.

PageView provide you Counts whereas Custome Events provide you a way to track specific user actions at different level of description