We have created a example app for the Xamarin SDK integration.
Please check the Example directory for know to how the Trackier SDK
can be integrated.
For integration, you need to add the trackier plugin in your project.
To Embed Tarckier SDK manually to the project
- Copy trackier_xamarin_sdk.dll into your project.
- On Xamarin Studio go to References and click on Edit References.
- Go to .Net Assembly tab and click on Browse… button
- Locate trackier_xamarin_sdk.dll and chose it.
Please check the below screenshot
Screenshot[1]
After the above process, you need to add the below packages
in your project.
- Square.Moshi.Adapters
- Square.Moshi.Kotlin
- Square.Retrofit2.ConverterMoshi
- Xamarin.AndroidX.Work.Work.Runtime.Ktx
- Xamarin.GooglePlayServices.Ads.ldentifier
- Xamarin.Android.Binding.InstallReferrer
For adding the above packages
to your project follow the below steps
- Right click on the
packages
and selectManage NuGet Packages
- Search the above packages on the search option.
- After finding the package, click on the Add Package
Please check the below screenshot
Screenshot[2]
- Login to your Trackier MMP account.
- Select the application from dashboard which you want to get the app token for.
- Go to SDK Integration via the left side navigation menu.
- Copy the SDK Key there to be used as the
"app_token"
.
You should use the following import statement on top of your c#
file:
using Com.Trackier.Sdk;
In your MainApplication.cs
file, add the following code to initialize the Trackier SDK:
using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Com.Trackier.Sdk;
using Android.Util;
namespace SampleApp.Resources
{
[Application]
public partial class MainApplication : Application
{
internal static Context ActivityContext { get; private set; }
public Context Application { get; private set; }
public MainApplication(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer) { }
public override void OnCreate()
{
base.OnCreate();
try
{
/* While Initializing the SDK, You need to pass the three parameter in the TrackierSDKConfig.
* In First argument, you need to pass the Trackier SDK api key
* In third argument, you need to pass the environment which can be either "EnvironmentDevelopment", "EnvironmentProduction". */
TrackierSDKConfig trackierSDK = new TrackierSDKConfig(ApplicationContext, "0455721b-XXXX-XXXX-805e-5XXXXXd910a", "development");
TrackierSDK.Initialize(trackierSDK);
TrackierSDK.TrackAsOrganic(true);
}
catch (NullReferenceException e)
{
String s = e.StackTrace;
Log.Debug("logTrackier", "Debug" + s);
}
}
}
}
Check below the screenshot of above code
Screenshot[1]
Trackier events trackings enable to provides the insights into how to user interacts with your app. Trackier SDK easily get that insights data from the app. Just follow with the simple events integration process
Trackier provides the Built-in events
and Customs events
on the Trackier panel.
Predefined events are the list of constants events which already been created on the dashboard.
You can use directly to track those events. Just need to implements events in the app projects.
Screenshot[2]
using Android.App;
using Android.OS;
using AndroidX.AppCompat.Widget;
using AndroidX.AppCompat.App;
using Com.Trackier.Sdk;
namespace SampleApp
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.activity_main);
eventsTracking();
Toolbar toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
}
public void eventsTracking()
{
//Below are the example of built-in events function calling
//The arguments - "TTrackierEvent.PURCHASE" passed in the Trackier event class is Events id.
TrackierEvent trackierevents = new TrackierEvent(TrackierEvent.Purchase);
trackierevents.Param1 = "XamarinTest1";
trackierevents.Param2 = "XamarinTest2";
TrackierSDK.SetUserEmail("[email protected]");
TrackierSDK.TrackEvent(trackierevents);
}
}
}
Also check the example app screenshot of above example
Screenshot[3]
Customs events are created by user as per their required business logic.
You can create the events in the Trackier dashboard and integrate those events in the app project.
Screenshot[4]
using Android.App;
using Android.OS;
using AndroidX.AppCompat.Widget;
using AndroidX.AppCompat.App;
using Com.Trackier.Sdk;
namespace SampleApp
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.activity_main);
eventsTracking();
Toolbar toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
}
public void eventsTracking()
{
//Below are the example of built-in events function calling
//The arguments - "sEMWSCTXeu" passed in the Trackier event class is Events id for AppOpen
TrackierEvent trackierevents = new TrackierEvent("sEMWSCTXeu");
trackierevents.Param1 = "XamarinTest1";
trackierevents.Param2 = "XamarinTest2";
TrackierSDK.SetUserEmail("[email protected]");
TrackierSDK.TrackEvent(trackierevents);
}
}
}
Check below the example screenshot of customs events:-
Screenshots[5]
Trackier allow user to pass the revenue data which is generated from the app through Revenue events. It is mainly used to keeping record of generating revenue from the app and also you can pass currency as well.
using Android.App;
using Android.OS;
using AndroidX.AppCompat.Widget;
using AndroidX.AppCompat.App;
using Com.Trackier.Sdk;
namespace SampleApp
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.activity_main);
revenueTracking();
Toolbar toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
}
public void revenueTracking()
{
TrackierEvent trackierevents = new TrackierEvent("jYHcuyxWUW");
trackierevents.Param1 = "XamarinTest1";
trackierevents.Param2 = "XamarinTest2";
trackierevents.OrderId = "TestID";
trackierevents.Revenue = (Java.Lang.Double)2.0;
trackierevents.CouponCode = "TestCoupons";
trackierevents.Currency = "INR";
TrackierSDK.SetUserEmail("[email protected]");
TrackierSDK.TrackEvent(trackierevents);
}
}
}
Check below the revenue events calling screenshots.
Screenshot[6]
using Android.App;
using Android.OS;
using AndroidX.AppCompat.Widget;
using AndroidX.AppCompat.App;
using Com.Trackier.Sdk;
using System.Collections.Generic;
namespace SampleApp
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.activity_main);
customsDataPassing();
Toolbar toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
}
public void customsDataPassing()
{
//Below are the example of revenue events function calling
//The arguments - "sEMWSCTXeu" passed in the event class is Events id for AppOpen.
TrackierEvent trackierevents = new TrackierEvent("sEMWSCTXeu");
trackierevents.Param1 = "XamarinTest1";
trackierevents.Param2 = "XamarinTest2";
TrackierSDK.SetUserEmail("[email protected]");
//Passing the custom params in events be like below example
var map = new Dictionary<string, string>();
map.Add("name", "abc");
map.Add("phone", "81xxxxx84");
trackierevents.Ev = map;
TrackierSDK.TrackEvent(trackierevents);
}
}
}
- First create a map.
- Pass its reference to trackierEvent.ev param of event.
- Pass event reference to trackEvent method of TrackierSDK.
Trackier allows to pass additional data like Userid, Email, UserName, and UserPhone to SDK so that same can be correlated to the Trackier Data and logs.
Just need to pass the data of User Id, Email Id , UserName, and UserPhone and other additional data to Trackier SDK function which is mentioned below:-
using Android.App;
using Android.OS;
using AndroidX.AppCompat.Widget;
using AndroidX.AppCompat.App;
using Com.Trackier.Sdk;
using System.Collections.Generic;
namespace SampleApp
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.activity_main);
userData();
Toolbar toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
}
public void userData()
{
//Below are the example of revenue events function calling
//The arguments - "sEMWSCTXeu" passed in the event class is Events id for AppOpen.
TrackierEvent trackierevents = new TrackierEvent(TrackierEvent.Login);
trackierevents.Param1 = "XamarinTest1";
trackierevents.Param2 = "XamarinTest2";
//Passing the userData
TrackierSDK.SetUserEmail("[email protected]");
TrackierSDK.SetUserId("testID");
TrackierSDK.SetUserName("testName");
TrackierSDK.SetUserPhone("8878XX9877");
TrackierSDK.TrackEvent(trackierevents);
}
}
}
Following below are the steps to retrieve the secretId and secretKey :-
- Login your Trackier Panel and select your application.
- In the Dashboard, click on the
SDK Integration
option on the left side of panel. - Under on the SDK Integration, click on the Advanced tab.
- Under the Advanced tab, you will get the secretId and secretKey.
Please check on the below screenshot
Screenshot[11]
Check below the example code for passing the secretId and secretKey to the SDK
using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Com.Trackier.Sdk;
using Android.Util;
namespace SampleApp.Resources
{
[Application]
public partial class MainApplication : Application
{
internal static Context ActivityContext { get; private set; }
public Context Application { get; private set; }
public MainApplication(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer) { }
public override void OnCreate()
{
base.OnCreate();
try
{
/* While Initializing the SDK, You need to pass the three parameter in the TrackierSDKConfig.
* In First argument, you need to pass the Trackier SDK api key
* In third argument, you need to pass the environment which can be either "EnvironmentDevelopment", "EnvironmentProduction". */
TrackierSDKConfig trackierSDK = new TrackierSDKConfig(ApplicationContext, "0455721b-33c5-4c9f-805e-596d818d910a", "development");
trackierSDK.SetAppSecret("xxxx", "xxxxx"); // Pass the secretId and secretKey
TrackierSDK.Initialize(trackierSDK);
}
catch (NullReferenceException e)
{
String s = e.StackTrace;
Log.Debug("logTrackier", "Debug" + s);
}
}
}
}
If your app is using proguard then add these lines to the proguard config file
-keep class com.trackier.sdk.** { *; }
-keep class com.google.android.gms.common.ConnectionResult {
int SUCCESS;
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {
com.google.android.gms.ads.identifier.AdvertisingIdClient$Info getAdvertisingIdInfo(android.content.Context);
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {
java.lang.String getId();
boolean isLimitAdTrackingEnabled();
}
-keep public class com.android.installreferrer.** { *; }