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§
- Batch
Emitter - An implementation of the Emitter trait that sends batched events to the Snowplow Collector.
- InMemory
Event Store - An implementation of the EventStore trait, that queues events in a Vec
- Payload
- The final payload that is sent to the collector
- Payload
Builder - Builder for
Payload
. - Reqwest
Client - A HttpClient implementation useing the reqwest crate to send events to the collector.
- Screen
View Event - Event to track user viewing a screen within the application.
- Self
Describing Event - Event to track custom information that does not fit into the out-of-the box events.
- Self
Describing Json - Self-describing JSON to be used mainly when creating context entities.
- Snowplow
- Main interface for the package, used to initialize trackers.
- Structured
Event - 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.
- Timing
Event - 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
- Retry
Policy - 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.
- Event
Store - An EventStore is responsible for storing events until they are sent to the collector.
- Http
Client - A HttpClient is responsible for sending events to the collector.