Xamarin quick start

👍

Target Platforms

This quick start guide shows you how to get Heap setup in Xamarin application 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.

Add the Heap SDK to your application

  1. In Visual Studio 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.

Adding Support for .NET MAUI

If your application uses .NET MAUI, the Heap Xamarin Bridge will work for your app as well. To enable building with .NET MAUI, raise your project's target framework to .NET Standard 2.1, clean, and rebuild.

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.

Outside of StartRecording and SetLogLevel, all Heap SDK methods will be referenced using static members of the HeapInc.Xamarin.Heap object.