From 481711277ed075dbfc72e53552a281b5c1a82baf Mon Sep 17 00:00:00 2001 From: Sacha Morard <2254275+SachaMorard@users.noreply.github.com> Date: Tue, 31 Dec 2024 16:20:25 +0100 Subject: [PATCH] feat: consent mapping --- Cargo.lock | 2 +- Cargo.toml | 2 +- Makefile | 1 + README.md | 114 +++++++++++++++++++++---------- src/piano_payload.rs | 13 ++-- wit/deps.lock | 6 +- wit/deps.toml | 2 +- wit/deps/protocols/protocols.wit | 2 +- 8 files changed, 94 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1cda215..f188243 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -459,7 +459,7 @@ dependencies = [ [[package]] name = "piano-analytics-component" -version = "0.1.6" +version = "0.2.0" dependencies = [ "anyhow", "chrono", diff --git a/Cargo.toml b/Cargo.toml index ee913ec..74ab9fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "piano-analytics-component" -version = "0.1.6" +version = "0.2.0" edition = "2021" [lib] diff --git a/Makefile b/Makefile index 783ad91..9e68e36 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ help: | awk 'BEGIN { FS = ":.*?## " }; { printf "\033[36m%-30s\033[0m %s\n", $$1, $$2 }' build: ## Build the wasi component + wit-deps cargo build --target wasm32-wasip2 --release cp ./target/wasm32-wasip2/release/piano_analytics_component.wasm piano_analytics.wasm diff --git a/README.md b/README.md index ef68e4f..5851339 100644 --- a/README.md +++ b/README.md @@ -1,70 +1,112 @@
-

- - Edgee + + Edgee -

Edgee

+
+

Piano Analytics Component for Edgee

-**The full-stack edge platform for your edge oriented applications.** - -[![Edgee](https://img.shields.io/badge/edgee-open%20source-blueviolet.svg)](https://www.edgee.cloud) -[![Edgee](https://img.shields.io/badge/slack-edgee-blueviolet.svg?logo=slack)](https://www.edgee.cloud/slack) -[![Docs](https://img.shields.io/badge/docs-published-blue)](https://docs.edgee.cloud) - - +This component implements the data collection protocol between [Edgee](https://www.edgee.cloud) and [Piano Analytics](https://developers.atinternet-solutions.com/piano-analytics/data-collection/how-to-send-events/collection-api). -This component implements the data collection protocol between [Piano Analytics](https://developers.atinternet-solutions.com/piano-analytics/data-collection/how-to-send-events/collection-api) and [Edgee](https://www.edgee.cloud). +## Quick Start +1. Download the latest component version from our [releases page](../../releases) +2. Place the `piano.wasm` file in your server (e.g., `/var/edgee/components`) +3. Add the following configuration to your `edgee.toml`: -### Event mapping: +```toml +[[destinations.data_collection]] +name = "piano" +component = "/var/edgee/components/piano.wasm" +credentials.piano_site_id = "..." +credentials.piano_collection_domain = "..." +``` -Here is the mapping between Edgee events and Piano events: +## Event Handling -| Edgee event | Piano Event | -|-------------|-----------| -| Page | `page.display` | -| Track | Name of the event | -| User | - | +### Event Mapping +The component maps Edgee events to Piano Analytics events as follows: -The User event is not mapped to any Piano event. That means each time you make a `user` call, Edgee won't send any event to Piano Analytics. +| Edgee Event | Piano Analytics Event | Description | +|-------------|----------------------- |-------------| +| Page | `page.display` | Triggered when a user views a page | +| Track | Custom Event | Uses the provided event name directly | +| User | N/A | Used for user identification only | -But when you make a `user` call using Edgee's JS library or Data Layer, the `user_id`, `anonymous_id` and `properties` are stored in the user's device. -This allows the user's data to be added to any subsequent page or follow-up calls for the user, so that you can correctly attribute these actions. +### User Event Handling +While User events don't generate Piano Analytics events directly, they serve an important purpose: +- Stores `user_id`, `anonymous_id`, and `properties` on the user's device +- Enriches subsequent Page and Track events with user data +- Enables proper user attribution across sessions -## Usage +## Configuration Options -- Download the latest version in our [releases page](../../releases). -- Place the wasm file in a known place in your server (e.g. `/var/edgee/components`). -- Update your edgee proxy config: +### Basic Configuration ```toml [[destinations.data_collection]] name = "piano" component = "/var/edgee/components/piano.wasm" credentials.piano_site_id = "..." credentials.piano_collection_domain = "..." + +# Optional configurations +config.anonymization = true # Enable/disable data anonymization in case of pending or denied consent +config.default_consent = "pending" # Set default consent status if not specified by the user ``` -## Contributing -If you're interested in contributing to Edgee, read our [contribution guidelines](./CONTRIBUTING.md) +### Event Controls +Control which events are forwarded to Piano Analytics: +```toml +config.page_event_enabled = true # Enable/disable page event +config.track_event_enabled = true # Enable/disable track event +config.user_event_enabled = true # Enable/disable user event +``` -## Reporting Security Vulnerabilities -If you've found a vulnerability or potential vulnerability in our code, please let us know at -[edgee-security](mailto:security@edgee.cloud). +### Consent Management +Before sending events to Google Analytics, you can set the user consent using the Edgee SDK: +```javascript +edgee.consent("granted"); +``` -## Building from source +Or using the Data Layer: +```html + +``` -To build the wasm file from source, you need to have installed -- [Rust](https://www.rust-lang.org/tools/install) -- `wasm32-wasip2` target: run `rustup target add wasm32-wasip2` +If the consent is not set, the component will use the default consent status. -Then you can run the following commands: +| Consent | Anonymization | Piano Analytics Consent | +|---------|---------------|-------------------------| +| pending | true | Exempt | +| denied | true | Exempt | +| granted | false | Opt-in | +## Development + +### Building from Source +Prerequisites: +- [Rust](https://www.rust-lang.org/tools/install) +- WASM target: `rustup target add wasm32-wasip2` +- wit-deps: `cargo install wit-deps` + +Build command: ```bash make build ``` + +### Contributing +Interested in contributing? Read our [contribution guidelines](./CONTRIBUTING.md) + +### Security +Report security vulnerabilities to [security@edgee.cloud](mailto:security@edgee.cloud) \ No newline at end of file diff --git a/src/piano_payload.rs b/src/piano_payload.rs index 090b724..c0c1edb 100644 --- a/src/piano_payload.rs +++ b/src/piano_payload.rs @@ -4,8 +4,7 @@ use serde::Serialize; use std::collections::HashMap; use std::str::FromStr; -use crate::exports::edgee::protocols::provider::{Dict, Event}; - +use crate::exports::edgee::protocols::provider::{Dict, Event, Consent}; #[derive(Serialize, Debug, Default)] pub(crate) struct PianoPayload { #[serde(skip)] @@ -147,9 +146,13 @@ impl PianoEvent { data.cookie_creation_date = Some(first_seen.to_rfc3339()); } - // we set privacy consent to true and mode to optin because edgee is already handling privacy anonymization - data.visitor_privacy_consent = true; - data.visitor_privacy_mode = "optin".to_string(); + if edgee_event.consent.is_some() && edgee_event.consent.unwrap() == Consent::Granted { + data.visitor_privacy_consent = true; + data.visitor_privacy_mode = "optin".to_string(); + } else { + data.visitor_privacy_consent = false; + data.visitor_privacy_mode = "exempt".to_string(); + } // Campaign // diff --git a/wit/deps.lock b/wit/deps.lock index 553d33e..16908de 100644 --- a/wit/deps.lock +++ b/wit/deps.lock @@ -1,4 +1,4 @@ [protocols] -url = "https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.2.3.tar.gz" -sha256 = "159e4e2f5236e47d5ef0e831cd13fe5da1696a2050accbefe06b496f9bb35314" -sha512 = "c956cc3eeebcb33639260de09a5f24a2d202d5ebc45afd1c25a5c3edd027a8f1699748d6304bd30564bd3bfe39cd9f99d38c563348fef0cf87a0204d95b6ed3a" +url = "https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.2.4.tar.gz" +sha256 = "9085b0ef016f6c1135e7175fe44db4f9694ce94c8cb9dd0e4b45b330610e4abb" +sha512 = "f06230b4471cb4c09b7a31830e0b1f77e58eba56fe7e6d1c764cbba7193cfc1f7396b520afa1d3a8961f86da3643bca37adca6b81fb5cdf92212a41a54fd5275" diff --git a/wit/deps.toml b/wit/deps.toml index 73a6669..3d22e76 100644 --- a/wit/deps.toml +++ b/wit/deps.toml @@ -1 +1 @@ -protocols="https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.2.3.tar.gz" \ No newline at end of file +protocols="https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.2.4.tar.gz" \ No newline at end of file diff --git a/wit/deps/protocols/protocols.wit b/wit/deps/protocols/protocols.wit index 5d44b86..aaac806 100644 --- a/wit/deps/protocols/protocols.wit +++ b/wit/deps/protocols/protocols.wit @@ -13,7 +13,7 @@ type dict = list>; event-type: event-type, data: data, context: context, - consent: consent, + consent: option, } variant data {