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
<PackageReference Include="Plugin.Maui.FacebookAppEvents" Version="1.1.4" />
<PackageVersion Include="Plugin.Maui.FacebookAppEvents" Version="1.1.4" />
<PackageReference Include="Plugin.Maui.FacebookAppEvents" />
paket add Plugin.Maui.FacebookAppEvents --version 1.1.4
#r "nuget: Plugin.Maui.FacebookAppEvents, 1.1.4"
#:package Plugin.Maui.FacebookAppEvents@1.1.4
#addin nuget:?package=Plugin.Maui.FacebookAppEvents&version=1.1.4
#tool nuget:?package=Plugin.Maui.FacebookAppEvents&version=1.1.4
Plugin.Maui.FacebookAppEvents
Because implementing Facebook App Events shouldn't be this hard
Get Started • Examples • Troubleshooting
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>
Quick Setup (Recommended)
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.plistand AndroidAndroidManifest.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.
- Fork it
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License
MIT License. Use it however you want.
Support
- Bug Reports: Create an issue
- Feature Requests: Start a discussion
- Documentation: Check the XML docs in your IDE
Made with coffee and mild annoyance at Facebook's unnecessarily complex SDKs.
| Product | Versions 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. |
-
net8.0-android34.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.8)
- Microsoft.Maui.Controls (>= 8.0.100)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.100)
- Xamarin.GooglePlayServices.Ads.Identifier (>= 118.2.0.2)
-
net8.0-ios18.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.8)
- Microsoft.Maui.Controls (>= 8.0.100)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.100)
-
net9.0-android35.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.8)
- Microsoft.Maui.Controls (>= 9.0.100)
- Microsoft.Maui.Controls.Compatibility (>= 9.0.100)
- Xamarin.GooglePlayServices.Ads.Identifier (>= 118.2.0.3)
-
net9.0-ios18.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.8)
- Microsoft.Maui.Controls (>= 9.0.100)
- Microsoft.Maui.Controls.Compatibility (>= 9.0.100)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Fix on FacebookAppEventSender