Skip to content

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

  1. Visual Studio
  2. Xamarin Form
  3. LiteDB 5.0.11
  4. Snowplow Tracker 1.1.0
  5. Snowplow Tracker PlatformExtensions 1.1.0
  6. Android SDK API 16 and above
  7. Target Framwork 9.0

Info

Xamarin Tracker uses Snowplow DotNet Trackers.


Step 1. Install dependencies

Install Xamarin Form

  1. Open Manage NuGet Packages
  2. Search for Xamarin Form
  3. Select Xamarin Form
  4. Click Install Package
  5. Check for both iOS and Android

Install LiteDB

  1. Open Manage NuGet Packages
  2. Search for LiteDB
  3. Select LiteDB with version 5.0.11
  4. Click Install Package
  5. Check for both iOS and Android

Install Snowplow Tracker

  1. Open Manage NuGet Packages
  2. Search for Snowplow Tracker
  3. Select Snowplow Tracker
  4. Click Install Package
  5. Check for both iOS and Android

Install Snowplow Tracker PlatformExtensions

  1. Open Manage NuGet Packages
  2. Search for Snowplow Tracker PlatformExtensions
  3. Select Snowplow Tracker
  4. Click Install Package
  5. Check for both iOS and Android

Step 2. Configure project setting

  1. Righ click Android project
  2. Select Options
  3. Select General
  4. At Target Framework select Android 9.0(Pie)
  5. Click Ok

Step 3. Implement codes for Xamarin tracking

Wogaa Tracker

  1. Copy WogaaTracker.cs to the main project directory.
  2. Update the namespace in WogaaTracker.cs - MultieplatformApp to your project namespace.
  3. 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