# Titanium.Analytics
Used for transmitting developer-defined Analytics events to the Appcelerator Analytics product.
# Overview
The Analytics module can be used to supply additional context or application-specific information which can then be accessed during analysis using Analytics.
Use the Titanium.Analytics.featureEvent method to generate custom events that you can view through the Analytics product. You can specify a name for the feature event which is visible through Analytics.
NOTE The Analytics module lets you transmit some data that is stored, but not made accessible through the Analytics UI. To access this data, you must sign up for the optional raw data export service.
The following types of data are stored but not made available through the Analytics UI:
Navigation events.
Extra data added to feature events (the
data
parameter).
Viewing navigation events in the Analytics UI will be supported in a future version of the Analytics product. There is no plan to support the other event types, and they should not be used.
GDPR Compliance
The Ti.Analytics namespace in Titanium is GDPR compliant since SDK 7.2.0. End users should be able to opt out of Analytics using the Titanium.Analytics.optedOut property. If a user opted out from Analytics and you still call Analytics events, they will be ignored.
Note: This does not affect your app until you make use of the optedOut
property. Once
enabled for your users (e.g. by having a Titanium.UI.Switch in your settings), you
should handle it within your app logic.
# Examples
# Custom Feature Event
This example shows how to send a feature event during an application session to indicate some feature that you would like to track was used.
Ti.Analytics.featureEvent('app.feature');
In this case, the Analytics product would show statistics about how many times the 'app.feature' event was generated.
# Properties
# lastEvent READONLY
JSON representation of the last Analytics event generated.
LastEvent is the JSON version of the last event prepared to be sent to Appcelerator during the application's session. This value may be null or undefined if no such event was queued.
# optedOut
Allows the user to opt out from Analytics during runtime to comply to GPDR.
Once opted out, no Analytics events will be sent anymore. If implemented to the end user, ensure to check if the user is opted out before trying to send an Analytics event. In case you do not guard the Analytics call, it will be ignored silently.
Here is an example of a guarded Analytics call:
if (!Ti.Analytics.optedOut) {
Ti.Analytics.featureEvent('gdpr_rocks');
}
Read more about GDPR on the official website.
# Methods
# featureEvent
Sends a feature event for this application session.
From version "6.0.0", the JSON that is being sent will be validated. The JSON can have a maximum of 5 nested levels, 1000 serialised byte length, 25 keys per level and key length of up to 50 characters.
If this is successful, you will get a return number of 0. -1 is returned if it is a JSON Validation error. -2 is returned if Analytics is disabled.
Parameters
Name | Type | Description |
---|---|---|
name | String | Event name, displayed in Analytics UI. |
data | Object | Extra data related to the event. Must be serializable as JSON. |
Returns
It returns 0 if it is successful. Otherwise, it is an error.
- Type
- Number
# filterEvents
Sets a list of events that will not be sent to the Analytics server.
Parameters
Name | Type | Description |
---|---|---|
events | Array<String> | List of events to be filtered. |
Returns
- Type
- void
# navEvent DEPRECATED
DEPRECATED SINCE 8.3.0
Sends a navigation event for this application session. Not displayed in Analytics UI.
Parameters
Name | Type | Description |
---|---|---|
from | String | String describing the location the user navigated from. |
to | String | String describing the location the user navigated to. |
name | String | Event name. |
data | Object | Extra data related to the event. The object must be serializable as JSON. |
Returns
- Type
- void