Analytics is a Beagle feature that tags certain events such as clicking in a component or loading a screen.
In its first version, you would have to implement a ClickEvent
or a ScreenEvent
in the Backend, as shown in the example below:
ClickEvent(
category = "category-button",
label = "label-button",
value = "value-button"
)
ScreenEvent(
screenName = "FALLBACK"
)
Each event had to be declared in its own component defined on the backend, for example:
button
component had a property called ClickAnalyticEvent
that would receive a ClickEvent
.Screen
had a property called ScreenAnalyticEvent
that would receive an ScreenEvent
.We have listed an example bellow for a Button
component declared at the backend and configured with an analytic event:
Button(
text = "Analytics 1",
onPress = listOf(
Alert("Analytics 1", "Trying again!")
),
clickAnalyticsEvent = ClickEvent(
category = "category-button",
label = "Label-button",
value = "value-button"
)
)
Once declared in the Backend, the events (with the information listed in them) could be retrieved from the frontend using a custom class to handle them.
Analytics
. This class gathers event information into an object called event
. You can check the Android signature for reference below:@BeagleComponent
class SampleAnalytics: Analytics {
override fun trackEventOnClick(event: ClickEvent) {
//This code block will run when a ClickEvent is received
Log.i("analytics1", "$event")
}
override fun trackEventOnScreenAppeared(event: ScreenEvent) {
//This code block will run when a Screen is rendered
Log.i("analytics1", "screenUp -> "+ event.screenName)
}
override fun trackEventOnScreenDisappeared(event: ScreenEvent) {
//This code block will run when a Screen disappears
}
}
click
, or the appearance or disappearance of a screen
) the functions above are triggered)Analytics 2.0 has highly improved the control over the tracking of Beagle Events. These can still be mapped in the backend and retrieved from frontend but now it also possible to enable tracking
for actions and its properties directly from your app without even having to map them in the backend.
AnalycticsProvider
. When creating it, you must implement some functions that will receive the events mapping them. Information about thes events are added in a record
object that can be sent to your analytics service, such as the Google Analytics Service, for example.An example on how this class will look like on the Android has been set up below:
@BeagleComponent
class SampleAnalytics2:AnalyticsProvider {
override fun getConfig(): AnalyticsConfig = object: AnalyticsConfig{
override var actions: Map<String, List<String>>? = hashMapOf(
"beagle:alert" to listOf("message")
)
override var enableScreenAnalytics: Boolean? = true
}
override fun createRecord(record: AnalyticsRecord) {
Log.i("analytics2", record.toString())
}
}
getConfig
and createRecord
. The first one is where we define which actions and properties of each action will be observed. Whenever the action occurs, the second function, createRecord
, will be triggered and you can access the created record for this event on its scope.The general configuration of what should and should not generate analytics
events is in the frontend, but it is still possible to control the events from the backend.
Now, the property that holds analytics events is part of the action
, an not the button
or screen
anymore, as in Analytics 1. This property is called analytics
analytics
property can hold an element called ActionAnalyticsConfig
. This element will define if the action will trigger events for the AnalyticsProvider
in the frontend.Here follows an action sample that was declared with analytics settings in the backend
Alert(
title = "Analytics 2",
message = "Trying again!",
analytics = ActionAnalyticsConfig.Enabled(
ActionAnalyticsProperties(
attributes = listOf("message", "title")
)
)
)
Note that ActionAnalyticsConfig
is set to .Enabled
, that is what makes the frontend capture the event that triggers the record function and demonstrate it
ActionAnalyticsConfig
had a few properties, and here we only list the attributes
for the action we want information about, but there is another property called AdditionalEntries
that could send extra information with in this event.
Screen
: Events for Screen
are fired automatically when the screen appears or disappears, and can be accessed from the record
objectLet’s start with the backend. While it is no longer necessary to create events in the backend, this functionality is available for Analytics 2 and event tracking can be performed from the backend as well.
All information, previously implemented in specific attributes in the clickEvent
class, are now automatically sent to the frontend.
ClickEvent
or ScreenEvent
implementation on your components (Screen, button, touchable, or any other clickable custom component that is declared with this settings)ActionAnalyticsConfig.Enabled
code to the analytics
property for any action you want to get analytics for.button
with analytics 1 and 2 functionalities in the backend. We have also listed the information that will be retrieved in the frontend (We listed the information on each object
as a string):Button(
text = "Analytics 1",
onPress = listOf(
Alert("Analytics 1", "Trying again!")
),
clickAnalyticsEvent = ClickEvent(
category = "category-button",
label = "Label-button",
value = "value-button"
)
)
Data on the event
object:
ClickEvent(category=category-button,
label=Label-button,
value=value-button)
Button(
text = "Analytics 2",
onPress = listOf(
Alert(
title = "Analytics 2",
message = "Trying again!",
analytics = ActionAnalyticsConfig.Enabled(
ActionAnalyticsProperties(
attributes = listOf("message", "title")
)
...
)
Data on the record
object:
AnalyticsRecord(
type=action,
platform=android,
attributes={message=Trying again!, title=Analytics 2},
component={
id=6,
position={x=384.0, y=1329.0},
type=beagle:button},
beagleAction=beagle:alert,
event=onPress,
additionalEntries=null,
timestamp=1641235066016,
screen=/fallback-screen)
NOTE: The component id
(button
) was automatically defined by the system, but we can set it with the setId
function in the backend. Check the setId info on our documentation.
Alert
action.AnalysticsConfig
.AnalyticsProvider
getConfig()
functionAnalyticsProvider
has been implemented, just run your application and the events will be received in the frontend.Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.