Tealium for C#

Tealium for C#

by Monday - edited Friday by Community Manager (359 Views)

This guide shows how to add, configure, and track events for a C# application using the Tealium C# Integration library.

Table of Contents Placeholder

Installation

Requirements

Get the Code

The code for the Tealium C# library is stored in Github. You must retrieve the code to get started.

Code Setup

Import the Tealium folder into your solution.

using TealiumCSharp;

Initialization

Once the Tealium for C# package is installed you are ready to start coding. Use the following code to initialize with the following parameters:

  • account - the name of your account.
  • profile - the name of your profile within your account.
  • environment - "qa" or "prod"
  • visitorID - a 32 character alphanumeric string identifer that should be unique to a user, app instance.
  • modules - (optional) modules to be initialized with library. Default modules if none provided: AppDataModule, CollectModule, LoggerModule.
  • dataSourceKey - (optional) the data source key from UDH.
  • overrideCollectUrl - (optional) custom endpoint for the Tealium Collect service.
  • optionalData - (optional) dictionary for module use. Null acceptable.
// SAMPLE
Config tealConfig = new Config("account", 
                               "profile", 
                               "environment",
                               "visitorID",
                               new string[] { <modules> },
                               "dataSourceKey", 
                               "overrideCollectUrl",
                               new Dictionary<string, object> optionalData);
Tealium tealium = new Tealium(tealConfig);

Tracking

Once the Tealium object has been defined you can begin tracking events with the method Track(), which takes the following parameters::

  • eventName - a name to identify the event
  • customData - (optional) custom data dictionary to send with track call
  • completion - (optional) completion block to trigger after track call
// SAMPLE
// Full argument track call - illustrating call for a UI event with a callback. 
tealium.Track("eventName",
              customData,
              (success, info, error)=>) { 
                  Debug.WriteLine("eventTrackComplete: was successful: " + success); 
              });

Below are two convenience methods for calling Track() without the optional parameters:

// Convenience track call with only a string identifier for an activity type call.
tealium.Track("My Event");

//Convenience track call with event title and optional data dictionary
Dictionary<sting, object> customData = new Dictionary()
{
   {"foo1", new string[]{"a","12"}},
   {"foo2", "bar2"},
   {"foo3", "bar3"}
}; 
tealium.Track("My Event", customData);

Validation

Use Live Events or Trace to validate that Tealium is receiving your tracking calls.

Function Definitions

Config()

public Config (string account,
               string profile,
               string dev,
               string visitorId,
               string[] modules,
               string datasource = null,
               string overrideCollectUrl = null,
               Dictionary<string, object> optionalData = null)
Parameters Description Example Value
account Tealium Account tealium
profile Tealium profile mobile_division
environment Tealium environment. Currently optional prod
visitorID 32-char alphanumeric string identifier that should be unique to a user, app instance, or device 612040730c8c11e6b4cbacbc329f41b7
modules Modules to be initialed with library See Available Modules
dataSourceKey Data Source key from UDH abc123
overrideCollectUrl Custom endpoint for Tealium Collect service -
optionalData Dictionary<string, object> for module use. Null acceptable. Value not typically needed for most setups -
//Sample
Config tealConfig = new Config("account", 
                               "profile", 
                               "environment",
                               "visitorID",
                               new string[] { <modules> },
                               "dataSourceKey", 
                               "overrideCollectUrl",
                               new Dictionary<string, object> optionalData);

The config object has a modules string[] property that must be populated with the string representations of each module desired to use with library. See the Available Modules section

Tealium()

Tealium(Config config) 

Primary object constructor

Parameters Description Example Value
config Required Config instance -
//Sample
Config tealConfig = new Config("account", 
                               "profile", 
                               "environment",
                               "visitorId",
                               new string[] { <ModuleNames> },
                               "datasouceId", 
                               "overrideCollectUrl",
                               new Dictionary<string, object> optionalData);
Tealium tealium = new Tealium(tealConfig);

Enable()

Automatically called with the initial initialization. Re-enable the Tealium instance and any internal modules if the library had been disabled prior.

//Sample
tealium.Enable()

Disable()

Disable library modules from temporarily processing events. May deinit internal class objects.

//Sample
tealium.Disable()

Track()

Track(string eventName, Dictionary<string, object> customData, TrackCompletion completion)
Parameters Description Example Value
eventName Required string identifier for the tracked event "aButtonWasTapped"
customData Optional Dictionary<string, object> of key-value data to include with track call -
completion Optional completion block to be triggered once call has been completed -
//Sample
Dictionary<string, object> data = new Dictionary()
{
    {"foo1", new string[]{"a","12"}},
    {"foo2", "bar2"},
    {"foo3", "bar3"}
};
tealium.Track("My Event",
              customData,
              (success, info, error) =>
              {
                   Debug.WriteLine("Track action completion block triggered.");
                   Debug.WriteLine("Success: " + success + " info: " + info + " error: " + error);
              });

TrackCompletion

The optional callback for track calls will contain the following parameters:

Parameters Description Example Value
successful Bool status if the track call could be delivered true
Dictionary<string, object> info Dictionary<string, object> containing track and response data -
error Optional error from any dispatch services encountering a delivery or response issue -

Available Modules

The following string values can be used to enable modules with the current build.

Module Name Description
AppDataModule Adds automatic data points to calls
CollectModule Delivers processed events to Tealium Collect endpoint
LoggerModule Provides debug output
//Sample
config.Modules = new string[] { AppDataModule.Name,
                                CollectModule.Name,
                                LoggerModule.Name };

Use the .Name constant of each Module class.

Change Log

  • 1.0.0 Initial