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
Section titled “Setup the package”Install package
Section titled “Install package” m8ty_tracking: git: git@gitlab.m8ty.eu:app-framework/infra/m8ty_tracking.gitInitialize the package
Section titled “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
Section titled “Track navigation events”Now we need to integrate the tracking library into the application. The simplest part is the navigation by using M8tyTrackingObserver
MaterialApp( // ... navigatorObservers: [ M8tyTrackingObserver(), ], );Track other events
Section titled “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
Section titled “How does it work behind the scenes”As this library uses behind the scenes m8ty_client_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
Section titled “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.
© m8ty GmbH 2023 · m8ty.eu
