# Class AnalyticsService

java.lang.Object
com.codename1.analytics.AnalyticsService

public class AnalyticsService extends java.lang.Object

The analytics service allows an application to report its usage, it is seamlessly invoked by GUI builder applications if analytics is enabled for your application but can work just as well for handcoded apps!

To enable analytics just use the `java.lang.String)` method of the analytics service. For most typical usage you should also invoke the `#setAppsMode(boolean)` method with `true`. If you are not using the GUI builder invoke the visit method whenever you would like to log a page view event.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AnalyticsService()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `decorateVisitPageRequest(String page, String referer, ConnectionRequest request)`
  Decorates the ConnectionRequest to be sent to the server before the request is sent.
  `static void`
  `init(AnalyticsService i)`
  Allows installing an analytics service other than the default
  `static void`
  `init(String agent, String domain)`
  Initializes google analytics for this application
  `protected boolean`
  `isAnalyticsEnabled()`
  Indicates if the analytics is enabled, subclasses must override this method to process their information
  `static boolean`
  `isAppsMode()`
  Apps mode allows improved analytics using the newer google analytics API designed for apps
  `static boolean`
  `isEnabled()`
  Indicates whether analytics is enabled for this application
  `static boolean`
  `isFailSilently()`
  Indicates whether analytics server failures should brodcast an error event
  `static void`
  `sendCrashReport(Throwable t, String message, boolean fatal)`
  In apps mode we can send information about an exception to the analytics server
  `static void`
  `setAppsMode(boolean aAppsMode)`
  Apps mode allows improved analytics using the newer google analytics API designed for apps.
  `static void`
  `setFailSilently(boolean aFailSilently)`
  Indicates whether analytics server failures should brodcast an error event
  `static void`
  `setReadTimeout(int ms)`
  Sets read timeout for HTTP requests to Google Analytics services.
  `static void`
  `setTimeout(int ms)`
  Sets timeout for HTTP requests to Google Analytics service.
  `static void`
  `visit(String page, String referer)`
  Sends an asynchronous notice to the server regarding a page in the application being viewed, notice that you don't need to append the URL prefix to the page string.
  `protected void`
  `visitPage(String page, String referer)`
  Subclasses should override this method to track page visits

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### AnalyticsService

    public AnalyticsService()

- ## Method Details

  - ### isFailSilently

    public static boolean isFailSilently()

    Indicates whether analytics server failures should brodcast an error event

    ###### Returns

    the failSilently

  - ### setFailSilently

    public static void setFailSilently(boolean aFailSilently)

    Indicates whether analytics server failures should brodcast an error event

    ###### Parameters

    - `aFailSilently`: the failSilently to set

  - ### isAppsMode

    public static boolean isAppsMode()

    Apps mode allows improved analytics using the newer google analytics API designed for apps

    ###### Returns

    the appsMode

  - ### setAppsMode

    public static void setAppsMode(boolean aAppsMode)

    Apps mode allows improved analytics using the newer google analytics API designed for apps. Most developers should invoke this method with `true`.

    ###### Parameters

    - `aAppsMode`: the appsMode to set

  - ### setTimeout

    public static void setTimeout(int ms)

    Sets timeout for HTTP requests to Google Analytics service.

    ###### Parameters

    - `ms`: Milliseconds timeout.

    ###### Since

    7.0

  - ### setReadTimeout

    public static void setReadTimeout(int ms)

    Sets read timeout for HTTP requests to Google Analytics services.

    ###### Parameters

    - `ms`: Milliseconds read timeout.

    ###### Since

    7.0

  - ### isEnabled

    public static boolean isEnabled()

    Indicates whether analytics is enabled for this application

    ###### Returns

    true if analytics is enabled

  - ### init

    public static void init(String agent, String domain)

    Initializes google analytics for this application

    ###### Parameters

    - `agent`: the google analytics tracking agent

    - `domain`: @param domain a domain to represent your application, commonly you should use your package name as a URL (e.g. com.mycompany.myapp should become: myapp.mycompany.com)

  - ### init

    public static void init(AnalyticsService i)

    Allows installing an analytics service other than the default

    ###### Parameters

    - `i`: the analytics service implementation.

  - ### visit

    public static void visit(String page, String referer)

    Sends an asynchronous notice to the server regarding a page in the application being viewed, notice that you don't need to append the URL prefix to the page string.

    ###### Parameters

    - `page`: the page viewed

    - `referer`: the source page

  - ### sendCrashReport

    public static void sendCrashReport(Throwable t, String message, boolean fatal)

    In apps mode we can send information about an exception to the analytics server

    ###### Parameters

    - `t`: the exception

    - `message`: up to 150 character message,

    - `fatal`: is the exception fatal

  - ### isAnalyticsEnabled

    protected boolean isAnalyticsEnabled()

    Indicates if the analytics is enabled, subclasses must override this method to process their information

    ###### Returns

    true if analytics is enabled

  - ### decorateVisitPageRequest

    protected void decorateVisitPageRequest(String page, String referer, ConnectionRequest request)

    Decorates the ConnectionRequest to be sent to the server before the request is sent. This can be overridden to add additional request parameters to the service, and hence provide additional analytics data.

    If using Google Analytics, the current you can see the available POST parameters that the server accepts here.

    ###### Parameters

    - `page`: The page visited

    - `referer`: The page from which the user came.

    - `request`: The ConnectionRequest

    ###### Since

    7.0

  - ### visitPage

    protected void visitPage(String page, String referer)

    Subclasses should override this method to track page visits

    ###### Parameters

    - `page`: the page visited

    - `referer`: the page from which the user came