Skip to content

Commit

Permalink
feat: consent mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
SachaMorard committed Dec 31, 2024
1 parent c3a1189 commit 4817112
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "piano-analytics-component"
version = "0.1.6"
version = "0.2.0"
edition = "2021"

[lib]
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
114 changes: 78 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,112 @@
<div align="center">

<p align="center">
<a href="https://www.edgee.cloud">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://cdn.edgee.cloud/img/favicon-dark.svg">
<img src="https://cdn.edgee.cloud/img/favicon.svg" height="100" alt="Edgee">
<source media="(prefers-color-scheme: dark)" srcset="https://cdn.edgee.cloud/img/component-dark.svg">
<img src="https://cdn.edgee.cloud/img/component.svg" height="100" alt="Edgee">
</picture>
<h1 align="center">Edgee</h1>
</a>
</p>
</div>

<h1 align="center">Piano Analytics Component for Edgee</h1>

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

</div>
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
<script id="__EDGEE_DATA_LAYER__" type="application/json">
{
"data_collection": {
"consent": "granted"
}
}
</script>
```

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)
13 changes: 8 additions & 5 deletions src/piano_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use serde::Serialize;
use std::collections::HashMap;

Check warning on line 4 in src/piano_payload.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/piano-analytics-component/piano-analytics-component/src/piano_payload.rs
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)]
Expand Down Expand Up @@ -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
//
Expand Down
6 changes: 3 additions & 3 deletions wit/deps.lock
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion wit/deps.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
protocols="https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.2.3.tar.gz"
protocols="https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.2.4.tar.gz"
2 changes: 1 addition & 1 deletion wit/deps/protocols/protocols.wit
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type dict = list<tuple<string,string>>;
event-type: event-type,
data: data,
context: context,
consent: consent,
consent: option<consent>,
}

variant data {
Expand Down

0 comments on commit 4817112

Please sign in to comment.