Rust Analytics for Snowplow

![early-release] Build Status License

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.

Snowplow Rust Tracker Overview

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.

Quick Start

Installation

Add the snowplow_tracker as a dependency in Cargo.toml inside your Rust application:

yml [dependencies] snowplow_tracker = "0.1"

Use the package APIs in your code:

rust use snowplow_tracker::Snowplow;

Using the Tracker

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

```rust use snowplow_tracker::Subject; let subject = Subject::builder().language("en-gb").build().unwrap();

let tracker = Snowplow::createtracker("ns", "appid", "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.

```rust // Tracking a Screen View event let screenviewevent = match ScreenViewEvent::builder() .id(Uuid::newv4()) .name("a screen view") .previousname("previous name") .build() { Ok(event) => event, Err(e) => panic!("ScreenViewEvent could not be built: {e}"), // your error handling here };

let screenvieweventid = match tracker.track(screenview_event, None).await { Ok(uuid) => uuid, Err(e) => panic!("Failed to emit event: {e}"), // your error handling here };

// Tracking a Self-Describing event with context entity let selfdescribingevent = 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 selfdesceventid = match tracker.track(selfdescribingevent, eventcontext).await { 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 structeventid = match tracker.track(structured_event, None).await { Ok(uuid) => uuid, Err(e) => panic!("Failed to emit event: {e}"), // your error handling here }; ```

Find Out More

| Technical Docs | Setup Guide | | --------------------------------- | --------------------------- | | i1 | i2 | | Technical Docs | Setup Guide |

Maintainers

| Contributing | | -------------------------------------------- | | i4 | | Contributing |

Testing

Copyright and License

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.