Collecting data with Trackers and Webhooks

  1. Home
  2. Docs
  3. Collecting data with Trackers and Webhooks
  4. Trackers – collecting data from your own applications
  5. .NET Tracker
  6. Initialization


Assuming you have completed the .NET Tracker Setup for your project, you are now ready to initialize the .NET Tracker.

Importing the library

Add the following using lines to the top of your .cs scripts to access the Tracker:

using Snowplow.Tracker.Emitters; using Snowplow.Tracker.Endpoints; using Snowplow.Tracker.Logging; using Snowplow.Tracker.Models; using Snowplow.Tracker.Models.Events; using Snowplow.Tracker.Models.Adapters; using Snowplow.Tracker.Queues; using Snowplow.Tracker.Storage;
Code language: CSS (css)

You should now be able to setup the Tracker!

Creating a tracker

Using Snowplow.Tracker (.NET Standard) or Snowplow.Tracker.PlatformExtensions (PCL)

To use the Tracker in your code simply instantiate the Tracker interface with the following:

// Create logger var logger = new ConsoleLogger(); // Controls the sending of events var endpoint = new SnowplowHttpCollectorEndpoint(emitterUri, method: method, port: port, protocol: protocol, l: logger); // Controls the storage of events // NOTE: You must dispose of storage yourself when closing your application! var storage = new LiteDBStorage("events.db"); // Controls queueing events var queue = new PersistentBlockingQueue(storage, new PayloadToJsonString()); // Controls pulling events of the queue and pushing them to the sender var emitter = new AsyncEmitter(endpoint, queue, l: logger); // Contains information about who you are tracking var subject = new Subject().SetPlatform(Platform.Mob).SetLang("EN"); Tracker.Tracker.Instance.Start(emitter: emitter, subject: subject, trackerNamespace: "some namespace", appId: "some appid", l: logger);
Code language: PHP (php)

This starts a global singleton Tracker which can be accessed anywhere via the Tracker.Tracker.Instance.{{ method }} chain.

If you’d like to learn more about Snowplow BDP you can book a demo with our team, or if you’d prefer, you can try Snowplow technology for yourself quickly and easily.