AppsFlyer SDK Integration Guide - Windows

Current Version: 2.2.2

AppsFlyer's SDK provides app installation and event tracking functionality.  We have developed an SDK that is highly robust (8+ billion SDK installations to date), secure, lightweight and very simple to embed.

You can track installs, updates and sessions (by following the mandatory steps below), and also track additional in-app events beyond app installs (including in-app purchases, game levels, etc.) to evaluate ROI and user engagement levels.

The AppsFlyer Windows SDK is compatible with Universal Windows Platform.

  Universal Windows Platform SDK Download

  • To download the Universal Windows Platform App SDK click here.

1.  What’s New in This Version?

  • New Event Parameter - CUSTOMER_SEGMENT
  • Support for new Microsoft method to pass referrer
  • Added a new section for C++ / CX Integration
  • Bug fixes and maintenance

2.  Initial Steps

The Windows Universal SDK is installed via the NuGet Package Manager. To install the appsflyer Windows SDK via Nuget:

  1. Right click the project file
  2. Click "Manage NuGet Packages"
  3. Click “Browse” and search for “AppsFlyerLib”
  4. Click the AppsFlyerLib and click Install

If you choose not use to the NuGet package you can embed AppsFlyer’s SDK into your app manually:

  • Copy the AppsFlyerLib.winmd into your project.
  • In Visual Studio, click Add Reference on the Universal Windows Platform project.

  • Locate AppsFlyerLib.winmd and add it.

IMPORTANT:

AppsFlyer uses a Newtonsoft.json package. This is a standard library for parsing Json in Windows. You can add this package using NuGet in Visual Studio. This solves the File Not Found exception in the DLL.

  • In Visual Studio, right-click References and select NuGet Package Newtonsoft.json and add it.
  • Allow Internet access in the app manifest, or use Visual Studio in the Capabilities tab

3.  SDK Initialization & Installation Event (Minimum Requirement for Tracking)

  • Add the following code into your App Launch method.
  • Set your appId & DevKey:
    • Populate tracker.appId and tracker.devKey with your values
    • You can get your AppsFlyer DevKey on our dashboard under SDK Integration
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
this .InitializeComponent();
this .Suspending += this .OnSuspending;
AppsFlyerLib. AppsFlyerTracker tracker =
AppsFlyerLib. AppsFlyerTracker .GetAppsFlyerTracker();
tracker.appId = "YOUR_APP_ID_HERE" ;
tracker.devKey = "YOUR_DEV_KEY_HERE" ;
tracker.trackAppLaunch();
}

4.  In-App Events Tracking API (Optional)

This API enables AppsFlyer to track postinstall events. These events are defined by the advertiser and include an event name in addition to optional event values:
Add the following code to track post install events:

public void TrackEvent(string eventName, IDictionary<string, Object> eventValues)
  • eventName is any string which defines the event name. You can find a list of recommended event names here
  • eventValues is a dictionary of event parameters that comprise an event. You can find a list of recommended parameters here.
  • Counting revenue as part of inapp events: Use InAppEventParameterName.REVENUE (“af_revenue”) constant parameter name to count revenue as part of an inappevent. You can populate it with any numeric value, positive or negative.

Example:

AppsFlyerLib.AppsFlyerTracker tracker = AppsFlyerLib.AppsFlyerTracker.GetAppsFlyerTracker();
           IDictionary<string, object> eventValues = new Dictionary<string, object>();
           eventValues.Add(AppsFlyerLib.AFInAppEventParameterName.CONTENT_ID, "id123");
           eventValues.Add(AppsFlyerLib.AFInAppEventParameterName.REVENUE, "10");
           eventValues.Add(AppsFlyerLib.AFInAppEventParameterName.CURRENCY, "USD");
           tracker.TrackEvent(AppsFlyerLib.AFInAppEventType.ADD_TO_CART, eventValues);

For a complete list of AppsFlyer Rich InApp Events see here

5.  Advanced Integration

The APIs below are optional and are part of the advanced integration with AppsFlyer SDK.  

5.1  Set Currency Code (Optional)

You can set a global currency code using the API below, in addition to specific currency codes that can be used as part of each inapp event sent to AppsFlyer.
USD is the default value. Please find acceptable ISO currency codes here.
Use the following API to set the currency code:

tracker.currencyCode = "GBP";

5.2  GetAppsFlyerUID (Optional)

An AppsFlyer Unique ID is created for every new install of an app.
Use the following API In order to get this ID:

public string getAppsFlyerUID() 

5.3  Customer User ID (Optional)

Setting your own customer ID enables you to cross-reference your own unique ID with AppsFlyer’s user ID and all other device IDs. This ID is available in the AppsFlyer CSV reports along with postbacks APIs for crossreferencing
with your internal IDs.

To set your Customer User ID:

tracker.customerUserId = "YOUR_CUSTOMER_USER_ID";

5.4  GetConversionData (Optional)

You can receive the conversion data for every install through the SDK using this API.  Add the following code to track post install events:

Task.Run(async () =>
{
AppsFlyerLib.AppsFlyerTracker tracker = AppsFlyerLib.AppsFlyerTracker.GetAppsFlyerTracker();
string conversionData = await tracker.GetConversionDataAsync();
});

 

For more information regarding this advanced functionality, read here

5.5  C++ / CX Integration Example

AppsFlyerLib::AppsFlyerTracker^ tracker = AppsFlyerLib::AppsFlyerTracker::GetAppsFlyerTracker();
tracker->appId = ref new Platform::String(L"APP_KEY");
tracker->devKey = ref new Platform::String(L"APPSFLYER_KEY");
tracker->TrackAppLaunch();
create_task(tracker->GetConversionDataAsync()).then([tracker](Platform::String^ conversionData)
{
Windows::Foundation::Collections::IMap<Platform::String^, Platform::Object^>^ eventValues
= ref new Platform::Collections::Map<Platform::String^, Platform::Object^>();

eventValues->Insert(AppsFlyerLib::AFInAppEventParameterName::CONTENT_ID, "134");
eventValues->Insert(AppsFlyerLib::AFInAppEventParameterName::CONTENT_TYPE, "Virtual Goods");
eventValues->Insert(AppsFlyerLib::AFInAppEventParameterName::CURRENCY, "USD");
eventValues->Insert(AppsFlyerLib::AFInAppEventParameterName::REVENUE, "9.99");

tracker->TrackEvent(AppsFlyerLib::AFInAppEventType::PURCHASE, eventValues);
});
Was this article helpful?
0 out of 0 found this helpful