Skip to content

Disclaimer :Appgain Xamarin SDK is End of Life, we are not supporting it any more

Getting Started

Appgain.io Xamarin SDK Setup Guide. Works with iOS, Android

Required For Setup

Generate Credentials

Before setting up Xamarin SDK, you must generate the appropriate credentials for the platform(s) you are releasing on:

Installation

  • Integrate Appgain SDK Project to Your Project


enter image description here


enter image description here

  • After Adding Appgain Sdk to Project it will be like this and Need to Build your project



enter image description here

  • After that Need to Add Reference to Appgain Sdk in your project like this

    enter image description here



enter image description here



enter image description here

Now you Can Use Appgain Sdk Methods

Push Notification setup

  • Open Firebase console, Go to project settings

    firbase project settings

  • Go to Cloud Messaging tab and copy SenderID and Legacy server key

cloud settings

  • Open appgain dashboard
  • Go to APP BACKEND > Settings
  • Navigate to Android push tab
  • enter your SenderID and Server key

Appgain Android Push settings


  • create a New Class that Extends from AppgainPushReceiver class
public class PushReceiver extends AppgainPushReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        super.onReceive(context, intent);
    }

    @Override
    protected void onReceive(Context context, ReceiveStatus receiveStatus, Intent intent) {

    }

    @Override
    protected void onSilentPushReceive(@NonNull String operation) {
        super.onSilentPushReceive(operation);
    }
}
  • open manifest.xml file and add the following lines:
    <receiver
            android:name=".PushReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.DELETE" />
                <action android:name="com.parse.push.intent.OPEN" />
            </intent-filter>
        </receiver>


        <service
            android:name="io.appgain.sdk.controller.AppgainMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>
  • in your android application class, implement LifecycleObserver interface and add the follwing lines
public class MainApplication extends Application implements ReactApplication, LifecycleObserver {
    @Override
    public void onCreate() {
        // onCreate method body
        super.onCreate();
        SoLoader.init(this, false);
        initializeFlipper(this);
        // ...
        // add this line of code    
        ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
    }

    // also add the following two methods
    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    void onAppBackgrounded() {
        //App in background
        Appgain.onAppBackgrounded();
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    void onAppForegrounded() {
        // App in foreground
        Appgain.onAppForegrounded();
    }
}

Initializing

To initialize appgain SDK, call the following method on app start

Appgain.Initialize(this, "Project id", "Api key", true, new AppgainDataCallback());
//add this callback to you file
class AppgainDataCallback : Java.Lang.Object, IO.Appgain.Sdk.Interfaces.IAppgainDataCallback
    {
        public void OnFailure(BaseResponse p0)
        {
            Log.Error("init", p0.ToString());
        }

        public void OnSuccess(Java.Lang.Object p0)
        {
            Log.Error("init", "Success");
        }
    }

Set Custom User Attributes



 IDictionary<string, string> userData = new Dictionary<string, string>();
            userData.Add("keyOne", "valueOne");
            userData.Add("keyTwo", "valueTwo");
            userData.Add("keyThree", "keyThree");
Appgain.UpdateUserData(userData, new AppgainDataCallback());
//add this callback to you file
class AppgainDataCallback : Java.Lang.Object, IO.Appgain.Sdk.Interfaces.IAppgainDataCallback
    {
        public void OnFailure(BaseResponse p0)
        {
            Log.Error("UpdateUserData", p0.ToString());
        }

        public void OnSuccess(Java.Lang.Object p0)
        {
            Log.Error("UpdateUserData", "Success");
        }
    }

Deferred Deep Linking

After a new user has installed your app, our SDK will detect if the app was installed from a smart deep link or not, if it's then our SDK will automatically route their flow to the marketing campaign desired location in the app (not just to the default home screen).

To achieve that, appgain.io SDK must be installed in the app, and the matching process must be initiated

Appgain.MatchLink(new AppgainDataCallback());
//add this callback to you file
class AppgainDataCallback : Java.Lang.Object, IO.Appgain.Sdk.Interfaces.IAppgainDataCallback
    {
        public void OnFailure(BaseResponse p0)
        {
            Log.Error("match link", p0.ToString());
        }

        public void OnSuccess(Java.Lang.Object p0)
        {
            Log.Error("match link", "Success");
        }
    }

Marketing Automation


 IDictionary<string, string> properties = new Dictionary<string, string>();
            properties.Add("keyOne", "valueOne");
            properties.Add("keyTwo", "valueTwo");
            properties.Add("keyThree", "keyThree");
 Appgain.FireAutomator("", properties, new AppgainDataCallback());

//add this callback to you file
class AppgainDataCallback : Java.Lang.Object, IO.Appgain.Sdk.Interfaces.IAppgainDataCallback
    {
        public void OnFailure(BaseResponse p0)
        {
            Log.Error("fire autmator", p0.ToString());
        }

        public void OnSuccess(Java.Lang.Object p0)
        {
            Log.Error("fire autmator", "Success");
        }
    }

Notification Channels

//type : 'email' or 'sms'
//date : user email or phone number
Appgain.CreateNotificationChannel("type", "date", new AppgainDataCallback());

//add this callback to you file
class AppgainDataCallback : Java.Lang.Object, IO.Appgain.Sdk.Interfaces.IAppgainDataCallback
    {
        public void OnFailure(BaseResponse p0)
        {
            Log.Error("CreateNotificationChannel", p0.ToString());
        }

        public void OnSuccess(Java.Lang.Object p0)
        {
            Log.Error("CreateNotificationChannel", "Success");
        }
    }

Revenue Tracking

// amount is number
Appgain.LogPurchase("product name", amount, "currency", new AppgainDataCallback());
//add this callback to you file
class AppgainDataCallback : Java.Lang.Object, IO.Appgain.Sdk.Interfaces.IAppgainDataCallback
    {
        public void OnFailure(BaseResponse p0)
        {
            Log.Error("LogPurchase", p0.ToString());
        }

        public void OnSuccess(Java.Lang.Object p0)
        {
            Log.Error("LogPurchase", "Success");
        }
    }

Custom Events Tracking

whenever you want to log user event, add the below code

 Bundle bundle = new Bundle();
 bundle.PutString("key", "value");
 Appgain.LogEvent("event", "action", bundle, new AppgainDataCallback());
//add this callback to you file
class AppgainDataCallback : Java.Lang.Object, IO.Appgain.Sdk.Interfaces.IAppgainDataCallback
    {
        public void OnFailure(BaseResponse p0)
        {
            Log.Error("LogEvent", p0.ToString());
        }

        public void OnSuccess(Java.Lang.Object p0)
        {
            Log.Error("LogEvent", "Success");
        }
    }