The analyticsProvider
must be set whenever you want to add analytics capabilities based on the user interactions with the UI built by Beagle.
There are two types of analytics records generated by Beagle:
These records are generated whenever a page is loaded by Beagle and they contain the following information:
screen
;flutter
in the case of Beagle Flutter;These records are generated whenever a Beagle Action is triggered. Besides all the information already present in the navigation record, it also contains:
action
;Note that when we create an Action record, we expose all attributes of the action. This can be dangerous (sensitive information) or even have low performance. The AnalyticsProvider must provide a configuration that tells which actions must generate records and which attributes should be exposed.
The configuration also tells if we should generate navigation records or not.
The configuration is created when implementing the interface AnalyticsProvider
in the function getConfig
. A configuration is an instance of the class AnalyticsConfig
. To know more about the analytics configuration, please read the article about this feature.
Every time a record is created by Beagle, it calls the method createRecord
of the AnalyticsProvider
. If you want to send this record to a backend, inside this method, you must format it into the format expected by the backend, create the HTTP request and send it.
For more examples, please check the Analytics page.
class LoggerAnalyticsProvider implements AnalyticsProvider {
@override
void createRecord(AnalyticsRecord record) {
debugPrint("Analytics Record emitted");
debugPrint("type: ${record.type}");
debugPrint("platform: ${record.platform}");
debugPrint("beagleAction: ${record.beagleAction}");
debugPrint("event: ${record.event}");
debugPrint("screen: ${record.screen}");
debugPrint("timestamp: ${record.timestamp}");
if (record.component != null) {
debugPrint("component: ${record.component?.values.join(", ")}");
}
if (record.attributes != null) {
debugPrint("attributes: ${record.attributes?.values.join(", ")}");
}
if (record.additionalEntries != null) {
debugPrint(
"additionalEntries: ${record.additionalEntries?.values.join(", ")}");
}
}
@override
AnalyticsConfig getConfig() {
return AnalyticsConfig(enableScreenAnalytics: true, actions: {
"beagle:setContext": ["contextId", "path", "value"]
});
}
}
In the example above, we create an AnalyticsProvider that just logs every record to the console. For actions, it logs only actions of type “beagle:setContext” and it exposes only the attributes “contextId”, “path” and “value” of the action.
To register the analytics provider, you need to pass it to the BeagleService:
final beagleService = BeagleService(
analyticsProvider: LoggerAnalyticsProvider(),
// ...
);
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.