Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve analytics #7091

Closed
FelixMalfait opened this issue Sep 17, 2024 · 0 comments
Closed

Improve analytics #7091

FelixMalfait opened this issue Sep 17, 2024 · 0 comments
Assignees
Labels

Comments

@FelixMalfait
Copy link
Member

FelixMalfait commented Sep 17, 2024

Problems

  • We collect too many data points for self-hosted telemetry which we don't need, this is because self-hosting telemetry is coupled with cloud analytics while they should be two separate concerns
  • That data is pushed to Cloudflare -> Jitsu -> Redshift which is highly inefficient
  • We don't have proper analytics for our cloud version
  • We don't have proper analytics for self-hosting usage
  • We don't give workspace owners any way to track their activity/usage (api calls, etc.)
  • Bonus: be able to run as an "open startup" long-term, sharing our metrics publicly

What

  • Replace the Cloudflare endpoint with a Tinybird endpoint in the Analytics service

    • Introduce a variable IS_ANALYTICS_ENABLED (default to false)
    • Pass that variable to the frontend, only send Track events to the backend if isAnalyticsEnabled
    • On the backend, remove the check on TELEMETRY_ENABLED and rely on IS_ANALYTICS_ENABLED instead
    • Introduce a private env variable TINYBIRD_PRIVATE_TOKEN
    • Replace t.twenty.com/api by api.tinybird.co/v0/events?name=${DATASOURCE}
    • Adapt the frontend Track script, taking inspiration from https://github.com/tinybirdco/web-analytics-starter-kit/blob/main/middleware/src/index.js ; this will change the payload format - we want to stick to TinyBird's format
  • Introduce a new service dedicated to Telemetry

    • Build a simple service that sends a post request to the former Cloudflare url
    • We just want to track new users / workspaces. We'll need to get a sense of usage in the future but maybe we can collect 1/100 events or something like that... TBC
    • Next
      • Track API usage, track function usage...
      • Dashboard for each workspace to view their usage (api calls, function calls, etc.)
      • Use it for throttling / billing
      • Metabase connector?
FelixMalfait added a commit that referenced this issue Sep 26, 2024
#7091 
EventTrackers send information of events to the TinyBird instance:

In order to test:

1. Set ANALYTICS_ENABLED= true and TELEMETRY_ENABLED=true in
evironment-variables.ts
2. Set the TINYBIRD_TOKEN in environment variables (go to TiniyBird
Tokens)
3. Log in to twenty's TinyBird and go to datasources/analytics_events in
twenty_analytics workspace
4. Run twenty and navigate it
5. New events will be logged in the datasources, containing their
timestamp, sessionId and payload.

<img width="1189" alt="Screenshot 2024-09-24 at 17 23 01"
src="https://github.com/user-attachments/assets/85375897-504d-4e75-98e4-98e6a9671f98">
Example of payload when user is not logged in

```
{"hostName":"localhost",
"pathname":"/welcome",
"locale":"en-US",
"userAgent":"Mozilla/5.0",
"href":"http://localhost:3001/welcome",
"referrer":"",
"timeZone":"Europe/Barcelona"}
```
Example of payload when user is logged in
```
{"userId":"2020202",
"workspaceId":"202",
"workspaceDisplayName":"Apple",
"workspaceDomainName":"apple.dev",
"hostName":"localhost",
"pathname":"/objects/companies",
"locale":"en-US",
"userAgent":"Mozilla/5.0Chrome/128.0.0.0Safari/537.36",
"href":"http://localhost:3001/objects/companies",
"referrer":"",
"timeZone":"Europe/Paris"}
```

---------

Co-authored-by: Félix Malfait <[email protected]>
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in Product development ✅ Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

2 participants