#tracker #analytics #snowplow

bin+lib snowplow_tracker

A package for tracking Snowplow events in Rust apps

2 unstable releases

0.2.0 Dec 19, 2022
0.1.0 Oct 18, 2022

#523 in Database interfaces

Download history 21/week @ 2024-02-04 58/week @ 2024-02-11 86/week @ 2024-02-18 136/week @ 2024-02-25 98/week @ 2024-03-03 52/week @ 2024-03-10 105/week @ 2024-03-17 64/week @ 2024-03-24 80/week @ 2024-03-31 6/week @ 2024-04-07 65/week @ 2024-04-14

218 downloads per month

Apache-2.0

97KB
1.5K SLoC

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:

[dependencies]
snowplow_tracker = "0.2.0"

Use the package APIs in your code:

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

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()

Find Out More

Technical Docs Setup Guide
i1 i2
Technical Docs Setup Guide

Maintainers

Contributing
i4
Contributing

Testing

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.

Dependencies

~7–21MB
~294K SLoC