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:
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.
- Open your
app/res/values/strings.xml
file. - Add a
string
element with the name attributedata_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>
- Add a
string
element with the name attributeendpoint_url
and value as your Liferay Analytics Cloud Endpoint URL to the file. For example:
<string name="endpoint_url">https://myendpoint.liferay.com</string>
- Open
/app/manifests/AndroidManifest.xml
- Add a uses-permission element to the manifest:
<uses-permission android:name="android.permission.INTERNET"/>
- Add a
meta-data
element to theapplication
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)
}
}
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")
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()
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"))
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:
It is a struct to contextualize forms events.
Parameters:
- formId: String (required)
- formTitle: String (optional)
val formAttributes = FormAttributes("10", "People")
Method to send a form viewed event.
Parameters:
- attributes: FormAttributes (required)
Forms.formViewed(attributes: formAttributes)
Method to send a form submit event.
Parameters:
- attributes: FormAttributes (required)
Forms.formSubmitted(formAttributes)
It is a struct to contextualize field events.
Parameters:
- name: String (required)
- title: String (optional)
- formAttributes: FormAttributes (required)
val fieldNameAttributes = FieldAttributes("nameField", "Name", formAttributes)
Method to track all events from the Field, like (focus and blur).
Parameters:
- field: EditText (required)
- fieldAttributes: FieldAttributes (required)
Forms.trackField(field, fieldNameAttributes)