Auto-commit 2026-05-02 09:37
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Analytics } from '@segment/analytics-node';
|
||||
import { analyticsEnv, EventType, eventPropertiesSchema } from '../config/analytics.config';
|
||||
import { hashPhoneNumber } from '../utils/phone-hash';
|
||||
|
||||
// Mixpanel service
|
||||
export class MixpanelService {
|
||||
@@ -97,7 +98,7 @@ export class MixpanelService {
|
||||
*/
|
||||
async spamBlocked(userId: string, phoneNumber: string, confidence: number, method: string): Promise<void> {
|
||||
await this.track(EventType.SPAM_BLOCKED, userId, {
|
||||
phoneNumber,
|
||||
phoneNumber: hashPhoneNumber(phoneNumber),
|
||||
confidence,
|
||||
method,
|
||||
timestamp: new Date(),
|
||||
|
||||
12
packages/shared-analytics/src/utils/phone-hash.ts
Normal file
12
packages/shared-analytics/src/utils/phone-hash.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Hash a phone number for analytics purposes
|
||||
* Uses a consistent hashing algorithm to create a deterministic hash
|
||||
*/
|
||||
export function hashPhoneNumber(phoneNumber: string): string {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < phoneNumber.length; i++) {
|
||||
hash = ((hash << 5) - hash) + phoneNumber.charCodeAt(i);
|
||||
hash |= 0;
|
||||
}
|
||||
return `hash_${Math.abs(hash)}`;
|
||||
}
|
||||
Reference in New Issue
Block a user