Liferay Analytics Android Codacy Badge Codacy Badge Build Status

Analytics Core

Setup

In your app build.gradle add the dependency:

implementation 'com.liferay:liferay-analytics-android:x.x.x'

Change x.x.x for the latest version: Download

How to use?

Initialize the library

You should initialize the library providing your dataSourceId and endpointUrl. If you don't initialize your library properly you will receive a runtime exception when you try to send an event, also you can't initialize your library twice. This will also happen if you try to initialize the library twice.

Add Liferay Analytics Cloud configuration keys
  1. Open your app/res/values/strings.xml file.
  2. Add a string element with the name attribute data_source_id and value as your Liferay Analytics Cloud Data Source ID to the file. For example:
<string name="data_source_id">Liferay Analytics Cloud Data Source ID</string>
  1. Add a string element with the name attribute endpoint_url and value as your Liferay Analytics Cloud Endpoint URL to the file. For example:
<string name="endpoint_url">https://myendpoint.liferay.com</string>
  1. Open /app/manifests/AndroidManifest.xml
  2. Add a uses-permission element to the manifest:
<uses-permission android:name="android.permission.INTERNET"/>
  1. Add a meta-data element to the application element:
<application android:label="@string/app_name" ...>
    ...
    <meta-data android:name="com.liferay.analytics.DataSourceId" android:value="@string/data_source_id"/>
    <meta-data android:name="com.liferay.analytics.EndpointUrl" android:value="@string/endpoint_url"/>
    ...
</application>

Now your application is read to be initialized properly.

Parameters:

  • context: Context (required)
  • flushInterval: int (optional, default is 60)
Analytics.init(this, 90)

It is recomended to do that inside your Application singleton:

class MainApplication : Application() {

	override fun onCreate() {
		super.onCreate()

		Analytics.init(this, 90)
	}

}

Set identity

It is recommended identify your user after he logged in. This way, next events will be connected to his identity.

Parameters:

  • email: String (required)
  • name: String (optional)
 Analytics.setIdentity("ned.ludd@email.com", "Ned Ludd")

Clear the identity

It is recommended to clean the analytics session when the user logout. This is necessary to unbind the next events from the previous user.

Analytics.clearSession()

Send custom events

Method to send any custom event.

Parameters:

  • eventId: String (required)
  • applicationId: String (required)
  • properties: Map<String: String> (optional). For additional properties
Analytics.send("eventId", "applicationId", hashMapOf("property" to "value", 
                                                    "property2" to "value2"))

Analytics Forms Plugin

Setup

In your app build.gradle add the dependency:

implementation 'com.liferay:liferay-analytics-forms-android:x.x.x'
annotationProcessor "com.liferay:liferay-analytics-forms-android:x.x.x"

Change x.x.x for the latest version: Download

How to use?

Forms Attributes

It is a struct to contextualize forms events.

Parameters:

  • formId: String (required)
  • formTitle: String (optional)
 val formAttributes = FormAttributes("10", "People") 

Form Viewed

Method to send a form viewed event.

Parameters:

  • attributes: FormAttributes (required)
Forms.formViewed(attributes: formAttributes)

Form Submit

Method to send a form submit event.

Parameters:

  • attributes: FormAttributes (required)
Forms.formSubmitted(formAttributes)

Field Attributes

It is a struct to contextualize field events.

Parameters:

  • name: String (required)
  • title: String (optional)
  • formAttributes: FormAttributes (required)
val fieldNameAttributes = FieldAttributes("nameField", "Name", formAttributes)

Tracking Fields

Method to track all events from the Field, like (focus and blur).

Parameters:

  • field: EditText (required)
  • fieldAttributes: FieldAttributes (required)
Forms.trackField(field, fieldNameAttributes)