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

Capture usage metrics in PostHog #650

Open
5 of 8 tasks
PabloCastellano opened this issue Nov 25, 2024 · 0 comments
Open
5 of 8 tasks

Capture usage metrics in PostHog #650

PabloCastellano opened this issue Nov 25, 2024 · 0 comments
Assignees

Comments

@PabloCastellano
Copy link
Member

PabloCastellano commented Nov 25, 2024

Host

TRPC requests can originate from the API or Web

The host is set always as if the request came from the API after the change introduced in commit 79f9151. Instead, we should try to set the host when the trpc context is created

Distinct ID for API requests

We don't require any API key so the only way so far is generating an UUID directly from the IP. We can use something like:

import { v5 as uuidv5 } from 'uuid';
import crypto from 'crypto';

const NAMESPACE = '6ba7b810-9dad-11d1-80b4-00c04fd430c8'; // UUID namespace

function generateUUIDFromIP(ip: string): string {
    const hash = crypto.createHash('sha256').update(ip).digest('hex');
    const uuid = uuidv5(hash, NAMESPACE);
    return uuid;
}

// Example usage
const ip = '192.168.1.1';
const uniqueUUID = generateUUIDFromIP(ip);
console.log(uniqueUUID);
@PabloCastellano PabloCastellano changed the title Capture usage metrics Capture usage metrics in PostHog Nov 27, 2024
@luis-herasme luis-herasme self-assigned this Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants