Building an Android application using the SDK in Visual Studio for Mac (Xamarin Studio)

Version: 10.4

This section describes how to install the Universal Tracker SDK and create an Android application in Visual Studio for Mac.

To build an Android application using the Universal Tracker SDK in Visual Studio for Mac:

  1. Create a project in Xamarin Studio. In the project creation wizard, select C# > Android > Android Application.

    android application solution dialog
  2. Select Project from the toolbar, and then click Add Packages.

    project add packages
  3. In the Add Packages dialog box, enter the Sitecore.UniversalTracker.MobileSDK ID in the search field. The ID is case insensitive.

  4. Select the Sitecore.UniversalTracker.MobileSDK in the search result and click Add Package.

    add packages list

    Once the package has been added, you can see it in the Packages folder of the project.

Now you can use the Universal Tracker SDK in your application. For example:

RequestResponse
using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

using Sitecore.UniversalTrackerClient.Entities;
using Sitecore.UniversalTrackerClient.Request.RequestBuilder;
using Sitecore.UniversalTrackerClient.Session.SessionBuilder;

namespace MobileSDKSample
{
  [Activity (Label = "MobileSDKSample", MainLauncher = true, Icon = "@drawable/icon")]
  public class MainActivity : Activity
  {
      protected async override void OnCreate (Bundle bundle)
      {
         base.OnCreate (bundle);

   			string instanceUrl = "http://my.site.com";
  				string channelId = "27b4e611-a73d-4a95-b20a-811d295bdf65";
  				string definitionId = "01f8ffbf-d662-4a87-beee-413307055c48";

         var defaultInteraction = UTEntitiesBuilder.Interaction()
                                   .ChannelId(channelId)
                                   .Initiator(InteractionInitiator.Contact)
                                   .Contact("jsdemo", "demo")
                                   .Build();

    	 using (session = SitecoreUTSessionBuilder.SessionWithHost(instanceUrl)
                                          	    .DefaultInteraction(defaultInteraction)
                                                    .BuildSession())
    	     {

        	var eventRequest = UTRequestBuilder.EventWithDefinitionId(definitionId)
                                           .Build();

                var eventResponse = await session.TrackEventAsync(eventRequest);

                Console.WriteLine("Track EVENT RESULT: " + eventResponse.StatusCode);
	     }
      }
  }
}

On launch, the application should display an alert with the response status code value.

Do you have some feedback for us?

If you have suggestions for improving this article,