Installing the Universal Tracker SDK using NuGet and MS Visual Studio

Version: 10.4

To install the Universal Tracker SDK using NuGet and Microsoft Visual Studio:

  1. Create a project in Visual Studio. You can create a desktop application, mobile application, Silverlight application, and others. This example describes how to create a console application.

    visual studio new project dialog
  2. In the Solution Explorer window, right-click the project node.

  3. In the context menu, click Manage NuGet Packages.

    visual studio mobilsdkdemo program
  4. In the Manage NuGet Packages dialog box, enter the Sitecore.UniversalTracker.MobileSDK ID in the search field. The ID is case insensitive.

  5. Select the Sitecore Mobile SDK for Universal Tracker search result and click Install.

    nuget package manager
  6. Read and accept the license agreements for the UT SDK.

    Once the NuGet package has been installed, you can see the updated project references.

    solution explorer
  7. In the Visual Studio Code Editor, add the following code to the Main() function of your application:

    RequestResponse
    private static void Main(string[] args)
    {
    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 (var session = SitecoreUTSessionBuilder.SessionWithHost(instanceUrl)
                                                        .DefaultInteraction(defaultInteraction)
                                                        .BuildSession()
    					)
                {
                    var eventRequest = UTRequestBuilder.EventWithDefenitionId(definitionId)
                                                       .Timestamp(DateTime.Now).Build();
                    var eventResponse = session.TrackEventAsync(eventRequest).Result;
                    Console.WriteLine("Track EVENT RESULT: " + eventResponse.StatusCode);
    			}
    }
  8. Add the following namespaces to your project to make the code compile properly:

    RequestResponse
    using System;
    using System.IO;
    using System.Threading.Tasks;
    using Sitecore.UniversalTrackerClient.Entities;
    using Sitecore.UniversalTrackerClient.Request.RequestBuilder;
    using Sitecore.UniversalTrackerClient.Session.SessionBuilder;

Sample output of the application:

application output universaltrackerdemo

Do you have some feedback for us?

If you have suggestions for improving this article,