Xamarin Mobile Application Implementation Guide¶
Abstract
In this section we will walk through how you can implement and verify WOGAA tracking for your mobile application on iOS and Android.
Warning
Do not reshare this document with anyone unless they need to implement WOGAA tracking on their mobile applications.
Dependencies¶
- Visual Studio
- Xamarin Form
- LiteDB 5.0.11
- Snowplow Tracker 1.1.0
- Snowplow Tracker PlatformExtensions 1.1.0
- Android SDK API 16 and above
- Target Framwork 9.0
Info
Xamarin Tracker uses Snowplow DotNet Trackers.
Step 1. Install dependencies¶
Install Xamarin Form¶
- Open Manage NuGet Packages
- Search for
Xamarin Form
- Select
Xamarin Form
- Click Install Package
- Check for both iOS and Android
Install LiteDB¶
- Open Manage NuGet Packages
- Search for
LiteDB
- Select
LiteDB
with version5.0.11
- Click Install Package
- Check for both iOS and Android
Install Snowplow Tracker¶
- Open Manage NuGet Packages
- Search for
Snowplow Tracker
- Select
Snowplow Tracker
- Click Install Package
- Check for both iOS and Android
Install Snowplow Tracker PlatformExtensions¶
- Open Manage NuGet Packages
- Search for
Snowplow Tracker PlatformExtensions
- Select
Snowplow Tracker
- Click Install Package
- Check for both iOS and Android
Step 2. Configure project setting¶
- Righ click Android project
- Select Options
- Select General
- At Target Framework select Android 9.0(Pie)
- Click Ok
Step 3. Implement codes for Xamarin tracking¶
Wogaa Tracker¶
- Copy WogaaTracker.cs to the main project directory.
- Update the namespace in
WogaaTracker.cs
-MultieplatformApp
to your project namespace. - Add the following code into the
App.cs
protected override void OnStart()
{
if (Tracker.Instance.Started)
{
Tracker.Instance.SetBackground(false);
}
}
protected override void OnSleep()
{
if (Tracker.Instance.Started)
{
Tracker.Instance.SetBackground(true);
}
}
protected override void OnResume()
{
if (Tracker.Instance.Started)
{
Tracker.Instance.SetBackground(false);
}
}
iOS¶
Xamarin Native
Add the following code into AppDelegate.cs FinishedLaunching
function after App.Initialize()
Xamarin Form
Add the following code into AppDelegate.cs FinishedLaunching
function before LoadApplication(new App())
if (!Snowplow.Tracker.Tracker.Instance.Started)
{
WogaaTracker.Init(
url: WogaaTracker.ENVIRONMENT.staging,
appId: "com.xxxx.xxx"
);
}
Add the following code into AppDelegate.cs WillTerminate
function
WogaaTracker.Shutdown();
Add following code to all ViewController
into ViewDidAppear
function, and replace the Screen Name
to your actual screen name.
WogaaTracker.TrackScreenView("Screen Name");
Android¶
Xamarin Native
Add the following code into MainApplication.cs OnCreate
function after App.Initialize()
Xamarin Form
Add the following code into MainApplication.cs OnCreate
function before LoadApplication(new App())
if (!Snowplow.Tracker.Tracker.Instance.Started)
{
WogaaTracker.Init(
url: WogaaTracker.ENVIRONMENT.staging,
appId: "com.xxxx.xxx",
userAgent: Android.Webkit.WebSettings.GetDefaultUserAgent(Application.Context));
}
Xamarin Native
Add the following code into MainApplication.cs OnTerminate
function
Xamarin Form
Add the following code into MainApplication.cs OnDestroy
function
WogaaTracker.Shutdown();
Add following code to all Activity
into OnCreate
function, and replace the <<Screen Name>>
to your actual screen name.
WogaaTracker.TrackScreenView("Screen Name");
Step 4. Check Xamarin implementation¶
Method 1: Manually check the logs¶
Run your application using Xcode or Android Studio and verify the platform logs below
iOS¶
Info: Emitter flushed all (1) events successfully
Note
Info: Emitter flushed all (1) events successfully
shows number of successful event(s) being sent to our backend system
Android¶
Info: Emitter sent and deleted 1 events
Note
Info: Emitter sent and deleted 1 events
shows number of successful event(s) being sent to our backend system
Method 2: Use tool to check if data is being received in your environment(s).¶
Info
- Staging received events will take about 10 seconds to process. (Last 24 hours)
- Production received events will take about 1 day to process.
Step 4. Verification of Xamarin Implementation¶
Move to Production¶
Change the Environment variable from Staging
to Production
.
WogaaTracker.ENVIRONMENT.Production
A verification email will be sent once we have successfully received data from your mobile application in production server.
It may take up to 7 working days for the verification. Please let us know if there is any issues with regards to this via support@wogaa.gov.sg
Reference Implementation¶
https://github.com/wogaa/mobile-tracker-examples/tree/main/xamarin