Skip to content

Commit

Permalink
chore: add metrics with posthog
Browse files Browse the repository at this point in the history
  • Loading branch information
justusmattern27 committed Mar 28, 2024
1 parent 48cb3de commit 37adb6b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ export default makeScene2D(function* (view) {

https://github.com/havenhq/revideo/assets/122226645/4d4e56ba-5143-4e4b-9acf-d8a04330d162

## Telemetry

To understand how people use Revideo, we **anonymously** track how many videos
are rendered using the open-source tool
[Posthog](https://github.com/PostHog/posthog). You can find our code
implementing Posthog
[here](https://github.com/redotvideo/revideo/tree/main/packages/ffmpeg/server/telemetry).

If you want to disable telemetry, just set the following environent variable:

```bash
DISABLE_TELEMETRY=true
```

## Learn More

To learn more about Revideo, feel free to check out our
Expand Down
25 changes: 19 additions & 6 deletions package-lock.json

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

1 change: 1 addition & 0 deletions packages/ffmpeg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@revideo/core": "^0.2.0",
"@revideo/vite-plugin": "^0.2.0",
"fluent-ffmpeg": "^2.1.2",
"posthog-node": "^4.0.0",
"uuid": "^9.0.1",
"vite": "^4.5"
}
Expand Down
2 changes: 2 additions & 0 deletions packages/ffmpeg/server/FFmpegExporterServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as os from 'os';
import * as path from 'path';
import {v4 as uuidv4} from 'uuid';
import {ImageStream} from './ImageStream';
import {EventName, sendEvent} from './telemetry/posthog';

const SAMPLE_RATE = 48000;

Expand Down Expand Up @@ -91,6 +92,7 @@ export class FFmpegExporterServer {
}

public async start() {
sendEvent(EventName.RenderStarted, {});
if (!fs.existsSync(this.config.output)) {
await fs.promises.mkdir(this.config.output, {recursive: true});
}
Expand Down
25 changes: 25 additions & 0 deletions packages/ffmpeg/server/telemetry/posthog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {PostHog} from 'posthog-node';

const Client = new PostHog('phc_YpKoFD7smPe4SXRtVyMW766uP9AjUwnuRJ8hh2EJcVv', {
host: 'https://eu.posthog.com',
});

export enum EventName {
RenderStarted = 'render-started',
}

export function sendEvent(eventName: EventName, eventProperties: object = {}) {
if (process.env.DISABLE_TELEMETRY === 'true') {
return;
}

try {
Client.capture({
distinctId: 'anonymous-user',
event: eventName,
properties: eventProperties,
});
} catch (e) {
console.error(e);
}
}

0 comments on commit 37adb6b

Please sign in to comment.