Skip to content

a-track-io/rust-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

A-Track Rust SDK

Analytics SDK for Rust services and backend applications.

Features

  • initialization with a public_key
  • automatic uuid generation when one is not provided
  • support for your own uuid during initialization
  • user attribute create/update flow
  • user event delivery
  • in-memory storage by default, with pluggable storage support
  • Rust-friendly request context helpers

Geo-based API routing

The SDK sends requests to:

  • https://api.a-track.io by default
  • https://<geo>.api.a-track.io when geo is provided

Authentication/project routing header:

  • x-a-track-key: <public_key>

Default endpoints:

  • /init
  • /attributes
  • /event

Basic usage

use a_track_sdk::{ATrackSdk, EventPayload, Options, UserContext, InitPayload};

fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut options = Options::new("pub_xxxxx");
    options.geo = Some("fra".to_string());

    let mut sdk = ATrackSdk::new(options);

    sdk.init(Some(InitPayload {
        user: Some(UserContext {
            uuid: Some("server-user-42".to_string()),
            attributes: None,
        }),
        ..Default::default()
    }))?;

    sdk.track(EventPayload {
        event: "order_created".to_string(),
        ..Default::default()
    })?;

    Ok(())
}

Generated uuid and later tracking

You can initialize without passing a user uuid, let the SDK generate one, and then read it back:

let result = sdk.init(None)?;
let uuid_from_init = result.uuid.clone();
let current_user = sdk.get_user();
let same_uuid = current_user.map(|user| user.uuid);

Later, anywhere else in your code, you can track an event with that explicit uuid:

sdk.track(EventPayload {
    event: "job_processed".to_string(),
    uuid: Some(uuid_from_init),
    ..Default::default()
})?;

Building init payload from request data

use a_track_sdk::{build_rust_init_payload, Attributes, Options, RequestContextInput, ATrackSdk};
use serde_json::json;

fn example() -> Result<(), Box<dyn std::error::Error>> {
    let mut attrs = Attributes::new();
    attrs.insert("plan".to_string(), json!("pro"));

    let payload = build_rust_init_payload(RequestContextInput {
        url: Some("/pricing?source=google".to_string()),
        referer: Some("https://google.com".to_string()),
        ip_address: Some("134.122.17.144".to_string()),
        user_agent: Some("rust-service/1.0".to_string()),
        locale: Some("en-US".to_string()),
        timezone: Some("America/New_York".to_string()),
        uuid: Some("crm-user-42".to_string()),
        user_attributes: Some(attrs),
        ..Default::default()
    });

    let mut sdk = ATrackSdk::new(Options::new("pub_xxxxx"));
    sdk.init(Some(payload))?;
    Ok(())
}

Updating user attributes

use serde_json::json;
use a_track_sdk::Attributes;

let mut attrs = Attributes::new();
attrs.insert("plan".to_string(), json!("business"));
attrs.insert("seats".to_string(), json!(12));
sdk.set_attributes(attrs, false)?;

set_attributes() sends data to /attributes.

You can also read the current initialized user at any time:

let current_user = sdk.get_user();

Suggested backend contract

POST /init

{
  "sdkVersion": "0.1.0",
  "uuid": "0d54...",
  "isNewUser": true,
  "mode": "merge",
  "context": {},
  "attributes": {},
  "profile": {}
}

POST /attributes

{
  "sdkVersion": "0.1.0",
  "uuid": "0d54...",
  "mode": "merge",
  "attributes": {
    "plan": "business"
  },
  "profile": {}
}

POST /event

{
  "sdkVersion": "0.1.0",
  "uuid": "0d54...",
  "event": "invoice_paid",
  "attributes": {},
  "timestamp": "2026-04-08T12:00:00.000Z",
  "context": {}
}

About

Official Rust SDK for A-Track.io — a lightweight client library for integrating attribution, session, and event tracking into .NET applications. Capture UTM tags, traffic source, device and geo context, create sessions, and send user events to A-Track with a simple developer-friendly API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages