Skip to content

Infinario/xamarin-android-sdk

Repository files navigation

Infinario Xamarin Android SDK

Installation

  1. Download the lastest release of the Xamarin Android SDK
  2. Unzip / untar the downloaded SDK into a preferred directory
  3. In Xamarin, right click on Master Solution -> Add -> Add Existing Project
  4. In the opened dialog window, locate the unzipped Xamarin Android SDK directory and click Finish
  5. In Xamarin, right click on master project References -> Edit References...
  6. In the opened dialog find InfinarioAndroidSDK, check it and then OK
  7. In Manifest.xml add these permissions
    1. <uses-permission android:name="android.permission.INTERNET" />
    2. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    3. <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    4. In Manifest.xml add into application tag these receivers
      
      	    <receiver
                  android:name="com.infinario.android.infinariosdk.AlarmReceiver"
                  android:exported="true" >
              </receiver>
      
          &lt;receiver android:name="com.infinario.android.infinariosdk.BootReceiver" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          
          &lt;receiver
              android:name="com.infinario.android.infinariosdk.ConnectivityReceiver"
              android:enabled="false" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.net.conn.CONNECTIVITY_CHANGE" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          
          &lt;receiver
              android:name="com.infinario.android.infinariosdk.ReferrerReceiver"
              android:exported="true" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.android.vending.INSTALL_REFERRER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;</code></pre></li>
      
    After completing the steps above the Infinario Xamarin Android SDK is now included in your project and ready to be used.
    using Com.Infinario.Android.Infinariosdk; //for IDictionary using System.Collections.Generic;

    Usage

    Basic Interface

    Once the IDE is set up, you may start using the Infinario library in your code. First you need to you need to know the URI of your Infinario API instance, usualy https://api.infinario.com and your companyToken (located at the Company / Overview page in the web application). To interact with the Infinario SDK, you need to obtain an instance of the Infinario class using the application's context and companyToken (the URI parameter is optional):
    // Use public Infinario instance
    Infinario infinario = Infinario.GetInstance(this.ApplicationContext, companyToken);
    

    // Use custom Infinario instance Infinario infinario = Infinario.GetInstance(this.ApplicationContext, companyToken, "http://url.to.your.instance.com");

    To start tracking, you need to identify the customer with their unique customerId. The unique customerId can either be a String, or an Map representing the customerIds as referenced in the API guide. Setting

    String customerId = "123-foo-bar"

    is equivalent to

    IDictionary<string, Java.Lang.Object> customerId = new Dictionary<string,Java.Lang.Object>();
    customerId.Add("registered", "123-foo-bar");

    In order to identify a customer, call the identify() method on the obtained Infinario instance as follows:

    // Identify a customer with their customerId
    infinario.Identify(customerId);

    The identification is performed asynchronously and there is no need to wait for it to finish. All tracked events are stored in the internal SQL database until they are sent to the Infinario API.

    You may track any event by calling the track() method on the Infinario instance. The track() method takes one mandatory and two optional arguments. First argument is String type which categorizes your event. This argument is required. You may choose any string you like.

    Next two arguments are IDictionary<string, Java.Lang.Object> properties and Long timestamp. Properties is a map which uses String keys and the value may be any Object which is serializable by org.json.JSONObject class. Properties can be used to attach any additional data to the event. Timestamp is standard UNIX timestamp in seconds and it can be used to mark the time of the event's occurence. The default timestamp is preset to the time of the tracking of the event.

    IDictionary<string, Java.Lang.Object> properties = new Dictionary<string,Java.Lang.Object>();
    properties.Add("item_id", 45);
    Long timestamp = Java.Lang.JavaSystem.CurrentTimeMillis * 1000L;
    
    // Tracking of buying an item with item's properties at a specific time
    Track("item_bought", properties, timestamp);
    
    // Tracking of buying an item at a specific time
    Track("item_bought", timestamp);
    
    // Tracking of buying an item with item's properties
    Track("item_bought", properties);
    
    // Basic tracking that an item has been bought
    Track("item_bought");
    

    The Infinario Android SDK provides you with means to store arbitrary data that is not event-specific (e.g. customer's age, gender, initial referrer). Such data is tied directly to the customer as their properties. The update() method is used to store such data:

    IDictionary<string, Java.Lang.Object> properties = new Dictionary<string,Java.Lang.Object>();
    properties.Add("age", 34);
    
    // Store customer's age
    infinario.Update(properties);
    

    Automatic events

    INFINARIO Android SDK automatically tracks some events on its own. Automatic events ensure that basic user data gets tracked with as little effort as just including the SDK into your game. Automatic events include sessions, installation, identification and payments tracking.

    Sessions

    Session is a time spent in the game, it starts when the game is launched and ends when the game gets dismissed from recent apps or is freed from memory in another way. Automatic tracking of sessions produces two events, session_start and session_end. Both events contain the timestamp of the occurence together with basic attributes about the device (OS, OS version, SDK, SDK version and device model). Event session_end contains also the duration of the session in seconds. Example of session_end event attributes in JSON format:

    {
      "duration": 125,
      "device_model": "LGE Nexus 5",
      "ip": "10.0.1.58",
      "os_name": "Android",
      "os_version": "5.0.1",
      "sdk": "AndroidSDK",
      "sdk_version": "1.0.4"
    }
    

    Installation

    Installation event is fired only once for the whole lifetime of the game on one device when the game is launched for the first time. Besides the basic information about the device (OS, OS version, SDK, SDK version and device model), it also contains additional attribute called campaign_id which identifies the source of the installation. For more information about this topic, please refer to the aquisition documentation. Please note that com.android.vending.INSTALL_REFERRER intent is used to acquire the source of the installation. Example of installation event:

    {
      "campaign": "Advertisement on my website",
      "campaign_id": "ui9fj4i93jf9083094fj9043",
      "link": "https://play.google.com/store/...",
      "device_model": "LGE Nexus 5",
      "ip": "10.0.1.58",
      "os_name": "Android",
      "os_version": "5.0.1",
      "sdk": "AndroidSDK",
      "sdk_version": "1.0.4"
    }
    

    Identification

    Identification event is tracked each time the identify() method is called. It contains all basic information regarding the device (OS, OS version, SDK, SDK version and device model) as well as registered attribute which identifies the player. Example of an identification event:

    {
      "registered": "[email protected]",
      "device_model": "LGE Nexus 5",
      "ip": "10.0.1.58",
      "os_name": "Android",
      "os_version": "5.0.1",
      "sdk": "AndroidSDK",
      "sdk_version": "1.0.4"
    }
    

    Flushing events

    All tracked events are stored in the internal SQL database in the Android app. By default, Infinario Android SDK automagically takes care of flushing events to the Infinario API. This feature can be turned off with method disableAutomaticFlushing() which takes no arguments. Please be careful with turning automatic flushing off because if you turn it off, you need to manually call Infinario.flush(context); to flush the tracked events manually everytime there is something to flush.