m8ty_tracking
What features are really used by the end user? This library should help providing details about the user behaviour within a flutter application
Setup the package
Install package
m8ty_device_info:
git: git@gitlab.m8ty.eu:app-framework/infra/m8ty_tracking.git
Initialize the package
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await M8tyTracking.initialize(
apiKey: "85e2f8cg-88a7-4e77-aede-6b5745749088",
shouldLog: (_) => true,
baseUrl: "https://api-dev.m8ty.eu/api/v1",
);
runApp(const MyApp());
}
Parameter | Description |
|---|
apiKey | Key configured on the server so that you can access the API |
shouldLog | As this is a function you can decide based on the event if the data should be sent to the server |
baseUrl | Url to the server API responsible for tracking |
timerDuration | How often should the tracking logs be sent to the server |
metaData | There are default meta data like appName, version, os etc. being send to the server. Here you can define additional metadata like some details about the user (not confidential) |
Track navigation events
No we need to integrate the tracking library into the application. The simplest part is the navigation by using M8tyTrackingOberserver
MaterialApp(
// ...
navigatorObservers: [
M8tyTrackingObserver(),
],
);
Track other events
To track other events this changes have to be added manually to the code. Here just some examples:
M8tyTracking.instance.logAppOpen();
M8tyTracking.instance.logLogin(loginMethod: "biometrics");
M8tyTracking.instance.logScreenView(screenName: "payments");
M8tyTracking.instance.logSearch(searchTerm: "Shell");
M8tyTracking.instance.logFormSubmission(formId: "domesticPayment");
M8tyTracking.instance.logSelectItem(itemListId: "transactionList", itemListName: "Transaction List");
M8tyTracking.instance.logSelectContent(contentType: "video", itemId: "payments.mp4");
M8tyTracking.instance.logViewItem(currency: "CHF", value: 1000.00);
M8tyTracking.instance.logViewItemList(itemListId: "specialOfferList", itemListName: "Special Offers");
M8tyTracking.instance.logShare(contentType: "accountDetails", itemId: "acc1", method: "app_share");
M8tyTracking.instance.logButtonClick(buttonId: "sendSecureMessage");
M8tyTracking.instance.logSwipe(swipeId: "accountList");
M8tyTracking.instance.logGenerateLead(currency: "CHF", value: 100);
M8tyTracking.instance.logViewPromotion(
creativeName: "greatOffer",
creativeSlot: "slot1",
locationId: "123",
promotionId: "10000",
promotionName: "Gold Card",
items: List.of([M8tyTrackingEventItem(itemId: "1", itemCategory: "cheap1")]),
);
M8tyTracking.instance.logSelectPromotion(
creativeName: "greatOffer",
creativeSlot: "slot1",
locationId: "123",
promotionId: "10000",
promotionName: "Gold Card",
);
M8tyTracking.instance.logTutorialBegin();
M8tyTracking.instance.logTutorialComplete();
How does it work behind the scenes
As this library uses behind the scenes m8ty_clint_tracking the process works as following. Events are
Added to the queue
Persisted to the device
Transferred to the server
Removed from the device storage
Offline support
As shared_preferences are used for the persistence of the tracking events entries data will be written locally as long as the device is offline. As soon as the device is online, the data will be transferred to the server.
Last modified: 07 January 2025