Crate snowplow_tracker

Crate snowplow_tracker 

Source
Expand description

§Snowplow Tracker

The Snowplow Rust Tracker allows you to track Snowplow events in your Rust applications. For information on how to effectively design tracking using Snowplow, visit our guide on tracking design.

§Example usage

This simple example shows the process of creating a Tracker, and then building and tracking a Self-Describing Event, using the link_click Iglu schema URI, and schema-confirming JSON data.

use snowplow_tracker::{SelfDescribingEvent, Snowplow, Subject};
use serde_json::json;

#[tokio::main]
async fn main() {
    // Build a Subject that will be attached to all events sent by this tracker
    let tracker_subject = match Subject::builder().language("en-gb").build() {
        Ok(subject) => subject,
        Err(e) => panic!("Subject could not be built: {e}"), // your error handling here
    };

    // Create a tracker
    let mut tracker = Snowplow::create_tracker("ns", "app_id", "https://example.com", Some(tracker_subject));

    // Build a Self-Describing Event, with the schema of the event we want to track, along
    // with relevent, schema-conforming, data
    let self_describing_event = match SelfDescribingEvent::builder()
        .schema("iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1")
        .data(json!({"targetUrl": "http://example.com/some-page"}))
        .build()
    {
        Ok(event) => event,
        Err(e) => panic!("SelfDescribingEvent could not be built: {e}"), // your error handling here
    };

    // Track our Self-Describing Event
    let self_desc_event_uuid = match tracker.track(self_describing_event, None) {
        Ok(uuid) => uuid,
        Err(e) => panic!("Failed to emit event: {e}"), // your error handling here
    };

     // Close the tracker emitter thread
     match tracker.close_emitter() {
         Ok(_) => (),
         Err(e) => panic!("Emitter could not be closed: {e}"), // your error handling here
     };
}

Structs§

BatchEmitter
An implementation of the Emitter trait that sends batched events to the Snowplow Collector.
InMemoryEventStore
An implementation of the EventStore trait, that queues events in a Vec
Payload
The final payload that is sent to the collector
PayloadBuilder
Builder for Payload.
ReqwestClient
A HttpClient implementation useing the reqwest crate to send events to the collector.
ScreenViewEvent
Event to track user viewing a screen within the application.
SelfDescribingEvent
Event to track custom information that does not fit into the out-of-the box events.
SelfDescribingJson
Self-describing JSON to be used mainly when creating context entities.
Snowplow
Main interface for the package, used to initialize trackers.
StructuredEvent
Event to capture custom consumer interactions without the need to define a custom schema.
Subject
Subject allows you to attach additional information about your application’s environment.
TimingEvent
Event to track user timing events, such as how long resources take to load.
Tracker
The Snowplow tracker, used to track events

Enums§

Error
The errors that can occur when using the Snowplow Tracker
RetryPolicy
Retry policy for the BatchEmitter.

Traits§

Emitter
An Emitter is responsible for handling events in an EventStore, which are sent to the collector using a HttpClient.
EventStore
An EventStore is responsible for storing events until they are sent to the collector.
HttpClient
A HttpClient is responsible for sending events to the collector.