Analytics Client iOS
Core iOS Client
Setup
CocoaPods
-
You need CocoaPods installed.
-
Create a file called
Podfile
in your project and add the following line:pod 'liferay-analytics-ios'
-
Run
$ pod install
. -
This will download the latest version of the SDK and create a .xcworkspace file, use that file to open your project in Xcode.
How to use ?
Initialize the library
You should initialize the library providing your analytics key, it is recommended to add the command on applicationDidFinishLaunching
method in your AppDelegate
. If you don't initialize the library, you will get an error .analyticsNotInitialized
or .analyticsAlreadyInitialized
if the library is already initialized.
Parameters:
- analyticsKey: String (required)
- flushInterval: Int (optional)
try Analytics.configure(analyticsKey: "YOUR_ANALYTICS_KEY", flushInterval: 50)
How to set your identity ?
It is recomended to call when the user is logged in, necessary to bind the next events for this user. The name parameter is optional.
Parameters:
- email: String (required)
- name: String (optional)
Analytics.setIdentity(email: "user email", name: "user name")
How to clear the identity ?
It is recomended to call when the user is logged out, necessary to unbind the next events of the previous user.
Analytics.clearSession()
How to send custom events ?
Method to send any custom event.
Parameters:
- eventId: String (required)
- applicationId: String (required)
- properties: [String: String] (optional). For additional properties
Analytics.send(
eventId: "PageView",
applicationId: "MYSAMPLE",
properties: ["custom1": "value 1",
"custom2": "value 2"])
Forms plugin
Setup
CocoaPods
-
You need CocoaPods installed.
-
Create a file called
Podfile
in your project and add the following line:pod 'liferay-analytics-forms-ios'
-
Run
$ pod install
. -
This will download the latest version of the SDK and create a .xcworkspace file, use that file to open your project in Xcode.
How to use ?
Forms Attributes
It is a struct to contextualize forms events.
Parameters:
- formId: String (required)
- formTitle: String (optional)
let formAttributes = FormAttributes(formId: "10", formTitle: "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(attributes: formAttributes)
Field Attributes
It is a struct to contextualize field events.
Parameters:
- name: String (required)
- title: String (optional)
- formAttributes: FormAttributes (required)
let fieldNameAttributes = FieldAttributes(name: "nameField", title: "Name", formAttributes: formAttributes)
Tracking Fields
Method to track all events from the Field, like (Focus and Blur).
Parameters:
- field: (UITextField || UITextView) (required)
- fieldAttributes: FieldAttributes (required)
Forms.trackField(field: field, fieldAttributes: fieldAttributes)