Snowplow is a scalable open-source platform for rich, high-quality, low-latency data collection. It is designed to collect high-quality, complete behavioral data for enterprise business.
To find out more, please check out the Snowplow website and our documentation.
The Snowplow Rust Tracker allows you to add analytics to your Rust apps when using a Snowplow pipeline.
With this tracker you can collect granular event-level data as your users interact with your Rust applications.
Technical documentation can be found for each tracker in our Documentation.
Add the snowplow_tracker
as a dependency in Cargo.toml
inside your Rust application:
[dependencies]
snowplow_tracker = "0.2.0"
Use the package APIs in your code:
use snowplow_tracker::Snowplow;
Instantiate a tracker using the Snowplow::create_tracker
function.
The function takes three required arguments: namespace
, app_id
, collector_url
, and one optional argument, subject
.
Tracker namespace
identifies the tracker instance; you may create multiple trackers with different namespaces.
The app_id
identifies your app.
The collector_url
is the URI of the Snowplow collector to send the events to.
subject
allows for an optional Subject to be attached to the tracker, which will be sent with all events
use snowplow_tracker::Subject;
let subject = Subject::builder().language("en-gb").build().unwrap();
let tracker = Snowplow::create_tracker("ns", "app_id", "https://...", Some(subject));
To track events, simply instantiate their respective types and pass them to the tracker.track
method with optional context entities.
Please refer to the documentation for specification of event properties.
// Tracking a Screen View event
let screen_view_event = match ScreenViewEvent::builder()
.id(Uuid::new_v4())
.name("a screen view")
.previous_name("previous name")
.build()
{
Ok(event) => event,
Err(e) => panic!("ScreenViewEvent could not be built: {e}"), // your error handling here
};
let screen_view_event_id = match tracker.track(screen_view_event, None) {
Ok(uuid) => uuid,
Err(e) => panic!("Failed to emit event: {e}"), // your error handling here
};
// Tracking a Self-Describing event with context entity
let self_describing_event = match SelfDescribingEvent::builder()
.schema("iglu:com.snowplowanalytics.snowplow/screen_view/jsonschema/1-0-0")
.data(json!({"name": "test", "id": "something else"}))
.build()
{
Ok(event) => event,
Err(e) => panic!("SelfDescribingEvent could not be built: {e}"), // your error handling here
};
let event_context = Some(vec![SelfDescribingJson::new(
"iglu:org.schema/WebPage/jsonschema/1-0-0",
json!({"keywords": ["tester"]}),
)]);
let self_desc_event_id = match tracker.track(self_describing_event, event_context) {
Ok(uuid) => uuid,
Err(e) => panic!("Failed to emit event: {e}"), // your error handling here
};
// Tracking a Structured event
let structured_event = match StructuredEvent::builder()
.category("shop")
.action("add-to-basket")
.label("Add To Basket")
.property("pcs")
.value(2.0)
.build()
{
Ok(event) => event,
Err(e) => panic!("StructuredEvent could not be built: {e}"), // your error handling here
};
let struct_event_id = match tracker.track(structured_event, None) {
Ok(uuid) => uuid,
Err(e) => panic!("Failed to emit event: {e}"), // your error handling here
};
// Close the emitter when done
tracker.close_emitter()
Technical Docs | Setup Guide |
---|---|
Technical Docs | Setup Guide |
Contributing |
---|
Contributing |
The Snowplow Rust Tracker is copyright 2022 Snowplow Analytics Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.