Xamarin/Maui quick start

šŸ‘

Target Platforms

This quick start guide shows you how to get Heap setup in Maui or Xamarin applications that runs on iOS or Android.

After completing the setup process, you will be able to:

  • Take full advantage of the Heap API to track custom events and manage user identity.
  • Automatically capture changes to the installed app version when recording starts.

For Maui projects

Add the Heap SDK to your application

šŸ“˜

The Heap Maui SDK will compile for all platforms but only track events on iOS and Android devices. No changes are required to disable Heap on those platforms.

  1. In Visual Studio or Visual Studio Code, open the NuGet Package Manager for your project.
  2. Search for "HeapInc.Maui".
  3. Add the package to your project.
  4. Clean your build (e.g., by running dotnet clean) prior to building the app to ensure the frameworks are linked correctly.

Start the Heap SDK

To enable Heap, call StartRecording. This can go anywhere in your app, but we recommend doing this in the OnStart method of your appā€™s App class to make sure tracking starts, no matter how your app is opened.

using HeapInc.Maui;

public partial class App {
  protected override void OnStart() {
    Heap.StartRecording("YOUR_ENVIRONMENT_ID");
  }
}

Once recording has started, youā€™re able to take full advantage of Heapā€™s API to identify users, track custom events, and more. Heap will also automatically start tracking app version changes without any additional code.

For Xamarin projects

Add the Heap SDK to your application

  1. In Visual Studio or Visual Studio Code, open the NuGet Package Manager for your project.

  2. Search for the package for your platform:

    • For an iOS application project, use ā€œHeapInc.Xamarin.iOSā€.
    • For an Android application project, use ā€œHeapInc.Xamarin.Androidā€.
    • For a cross-platform library project used but either an iOS or Android app, use "HeapInc.Xamarin". You will still need to use one of the above packages in your application project.
  3. Add the package to your project.

  4. Clean your build (e.g., by running dotnet clean) prior to building the app.

Start the Heap SDK from an iOS application

To enable Heap, call StartRecording. This can go anywhere in your app, but we recommend doing this in the FinishedLaunching method of your appā€™s IUIApplicationDelegate object to make sure tracking starts, no matter how your app is opened.

[Register ("AppDelegate")]
public class AppDelegate : UIResponder, IUIApplicationDelegate
{
  [Export ("application:didFinishLaunchingWithOptions:")]
  public bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
  {
    HeapInc.Xamarin.iOS.Implementation.StartRecording("YOUR_ENVIRONMENT_ID");
  }
}

Once recording has started, youā€™re able to take full advantage of Heapā€™s API to identify users, track custom events, and more. Heap will also automatically start tracking app version changes without any additional code.

Start the Heap SDK from an Android application

To enable Heap, call StartRecording. This can go anywhere in your app, but we recommend doing this in the OnCreate method of your Application object to make sure tracking starts, no matter how your app is opened. If your app doesn't have an Application, the first activity can also be used.

[Application]
public class MainApplication : Application
{
  public override void OnCreate()
  {
    base.OnCreate();
  
    HeapInc.Xamarin.Android.Implementation.StartRecording(this, "YOUR_ENVIRONMENT_ID");
  }
}

Once recording has started, youā€™re able to take full advantage of Heapā€™s API to identify users, track custom events, and more. Heap will also automatically start tracking app version changes without any additional code.

What next?

To find out how to take full advantage of the Heap API to enhance your data capture, check out our mobile tracking guides here.