Plugin.Maui.FacebookAppEvents 1.1.4

dotnet add package Plugin.Maui.FacebookAppEvents --version 1.1.4
                    
NuGet\Install-Package Plugin.Maui.FacebookAppEvents -Version 1.1.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Plugin.Maui.FacebookAppEvents" Version="1.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Plugin.Maui.FacebookAppEvents" Version="1.1.4" />
                    
Directory.Packages.props
<PackageReference Include="Plugin.Maui.FacebookAppEvents" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Plugin.Maui.FacebookAppEvents --version 1.1.4
                    
#r "nuget: Plugin.Maui.FacebookAppEvents, 1.1.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Plugin.Maui.FacebookAppEvents@1.1.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Plugin.Maui.FacebookAppEvents&version=1.1.4
                    
Install as a Cake Addin
#tool nuget:?package=Plugin.Maui.FacebookAppEvents&version=1.1.4
                    
Install as a Cake Tool

Plugin.Maui.FacebookAppEvents

NuGet Downloads License: MIT .NET

Because implementing Facebook App Events shouldn't be this hard

Get StartedExamplesTroubleshooting


The Problem

You want to track app events in Facebook. You install their SDK. It's 50MB, breaks your build, and requires 30 lines of setup code just to track a simple purchase. There's got to be a better way.

The Solution

This library does exactly one thing: sends Facebook App Events from your .NET MAUI app. No bloat, no complexity, no headaches. It handles the annoying parts (getting IDFA/GAID, privacy permissions) so you can focus on what matters.

What You Get

  • Works with iOS and Android MAUI apps
  • Handles advertising IDs automatically (IDFA on iOS, GAID on Android)
  • Respects user privacy (ATT on iOS 14+, LAT on Android)
  • Simple methods for common events (purchase, add to cart, login, etc.)
  • Fully customizable when you need it
  • Actually documented

Installation

dotnet add package Plugin.Maui.FacebookAppEvents

Setup

First, get your Facebook App ID and Client Token from developers.facebook.com.

Android

Add this to AndroidManifest.xml:

<uses-permission android:name="com.google.android.gms.permission.AD_ID" />

iOS

Add this to Info.plist:

<key>NSUserTrackingUsageDescription</key>
<string>This helps us show you relevant ads and improve the app.</string>

The easiest way to get started - just one line in your MauiProgram.cs:

public static MauiApp CreateMauiApp()
{
    var builder = MauiApp.CreateBuilder();
    builder
        .UseMauiApp<App>()
        .ConfigureFonts(fonts =>
        {
            fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
        })
        .UseFacebookEvents("YOUR_APP_ID", "YOUR_CLIENT_TOKEN");

    //version 1.1.4 +
    var app = builder.Build();

    var facebookSender = app.Services.GetRequiredService<FacebookAppEventSender>();
    FacebookAppEventSender.InitializeInstance(facebookSender);

    return app;
}

Advanced Setup Options

Need more control? Here are additional setup options:

// With HttpClient configuration
builder.UseFacebookEvents("YOUR_APP_ID", "YOUR_CLIENT_TOKEN", httpClient =>
{
    httpClient.Timeout = TimeSpan.FromSeconds(30);
    httpClient.DefaultRequestHeaders.Add("User-Agent", "MyApp/1.0");
});

// With configuration options
builder.UseFacebookEvents(options =>
{
    options.AppId = "YOUR_APP_ID";
    options.ClientToken = "YOUR_CLIENT_TOKEN";
    options.ConfigureHttpClient = httpClient =>
    {
        httpClient.Timeout = TimeSpan.FromSeconds(15);
    };
});

<details> <summary><strong>Manual Setup (if you prefer DIY)</strong></summary>

public static MauiApp CreateMauiApp()
{
    var builder = MauiApp.CreateBuilder();
    
#if ANDROID
    builder.Services.AddSingleton<IAdvertiserIdService, 
        Plugin.Maui.FacebookAppEvents.Platforms.Android.AdvertiserIdService>();
#elif IOS
    builder.Services.AddSingleton<IAdvertiserIdService, 
        Plugin.Maui.FacebookAppEvents.Platforms.iOS.AdvertiserIdService>();
#endif

    builder.Services.AddSingleton<FacebookAppEventSender>(provider =>
    {
        var httpClient = new HttpClient();
        var advertiserIdService = provider.GetRequiredService<IAdvertiserIdService>();
        return new FacebookAppEventSender(httpClient, "YOUR_APP_ID", "YOUR_CLIENT_TOKEN", advertiserIdService);
    });

    //version 1.1.4 +
    var app = builder.Build();

    var facebookSender = app.Services.GetRequiredService<FacebookAppEventSender>();
    FacebookAppEventSender.InitializeInstance(facebookSender);

    return app;
}

</details>

Examples

Track a Purchase

public async Task OnOrderCompleted(Order order)
{
    var items = order.Items.Select(item => new FacebookContentItem
    {
        Id = item.ProductId,
        Quantity = item.Quantity
    }).ToList();

    var purchaseEvent = FacebookAppEventFactory.CreatePurchaseEvent(
        items, 
        order.Total, 
        "USD"
    );

    FacebookAppEventSender.SendEventsAsync(purchaseEvent);
}

Track Add to Cart

var items = new List<FacebookContentItem>
{
    new() { Id = "product-123", Quantity = 1 }
};

var event = FacebookAppEventFactory.CreateAddToCartEvent(items);
FacebookAppEventSender.SendEvents(event);

Track Screen Views

// In your page's OnAppearing or constructor
var screenEvent = FacebookAppEventFactory.CreateScreenViewEvent("ProductDetails");
FacebookAppEventSender.SendEvents(screenEvent);

Track User Registration

var loginEvent = FacebookAppEventFactory.CreateLoginEvent();
FacebookAppEventSender.SendEvents(loginEvent);

Custom Events

var customEvent = FacebookAppEventFactory.CreateCustomEvent(
    eventName: "video_completed",
    contentType: "media",
    contents: new List<FacebookContentItem>
    {
        new() { Id = "intro_video", Quantity = 1 }
    }
);

FacebookAppEventSender.SendEvents(customEvent);

Send Multiple Events

// More efficient than sending one by one
FacebookAppEventSender.SendEvents(screenEvent, addToCartEvent, purchaseEvent);

Static API Fire-and-Forget

FacebookAppEventSender.SendEvents(FacebookAppEventFactory.CreateScreenViewEvent(nameof(AppSettingsPage)));

Don't Like Dependency Injection?

Fair enough. You can create everything manually:

IAdvertiserIdService advertiserService;
#if ANDROID
advertiserService = new Plugin.Maui.FacebookAppEvents.Platforms.Android.AdvertiserIdService();
#elif IOS
advertiserService = new Plugin.Maui.FacebookAppEvents.Platforms.iOS.AdvertiserIdService();
#endif

var sender = new FacebookAppEventSender(
    new HttpClient(), 
    "YOUR_APP_ID", 
    "YOUR_CLIENT_TOKEN", 
    advertiserService
);

var event = FacebookAppEventFactory.CreatePurchaseEvent(items, 99.99, "USD");
FacebookAppEventSender.SendEvents(event);

Privacy

This library respects user privacy:

  • iOS 14+: Shows the App Tracking Transparency dialog automatically
  • Android: Checks if user has limited ad tracking
  • Both: If users opt out, sends empty advertiser IDs and marks tracking as disabled

No sketchy stuff, no personal data without consent.

Troubleshooting

Events not showing up in Facebook?

  • Check your App ID and Client Token (classic mistake)
  • Events take 15-20 minutes to appear in Facebook's dashboard
  • Test on a real device, not simulator
  • Ensure Privacy permissions in iOS Info.plist and Android AndroidManifest.xml

iOS permission issues?

  • Make sure the ATT description is in Info.plist
  • Permission dialog only shows once per app install
  • Need iOS 14+ for ATT

Android advertising ID not working?

  • Verify AD_ID permission is in AndroidManifest.xml
  • Update Google Play Services on your test device
  • Library handles threading automatically (you're welcome)

API Reference

Method Purpose
SendEvents(params FacebookAppEvent[] events) Static fire-and-forget method

FacebookAppEventFactory Methods

Method Purpose
CreatePurchaseEvent() Track completed purchases
CreateAddToCartEvent() Track items added to cart
CreateRemoveFromCartEvent() Track items removed from cart
CreateScreenViewEvent() Track page/screen views
CreateLoginEvent() Track user registration/login
CreateSearchEvent() Track search queries
CreateCustomEvent() Create any custom event

FacebookAppEvent Properties

Property Type Description
EventName string Facebook event name (required)
EventId string Unique event identifier
FbContent List<FacebookContentItem> Items involved in event
FbContentType string Content type ("product", "screen", etc.)
ValueToSum decimal? Monetary value
FbCurrency string Currency code ("USD", "EUR", etc.)

Contributing

Found a bug? Want to add something? Cool, but let's keep it simple. This library intentionally does one thing well rather than trying to be everything to everyone.

  1. Fork it
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

MIT License. Use it however you want.

Support


Made with coffee and mild annoyance at Facebook's unnecessarily complex SDKs.

Product Compatible and additional computed target framework versions.
.NET net8.0-android34.0 is compatible.  net8.0-ios18.0 is compatible.  net9.0-android was computed.  net9.0-android35.0 is compatible.  net9.0-ios was computed.  net9.0-ios18.0 is compatible.  net10.0-android was computed.  net10.0-ios was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.4 143 9/5/2025
1.1.1 188 9/4/2025
1.1.0 195 9/3/2025
1.0.3 178 9/3/2025
1.0.2 177 9/2/2025
1.0.1 172 9/2/2025
1.0.0 173 9/2/2025

Fix on FacebookAppEventSender