From d6625c29d17b8c614b20378c2681b4774d7dd71f Mon Sep 17 00:00:00 2001
From: dan <dan.abramov@gmail.com>
Date: Tue, 21 May 2024 04:28:12 +0100
Subject: [Statsig] Sample router events (#4143)

---
 src/lib/statsig/statsig.tsx | 6 ++++++
 1 file changed, 6 insertions(+)

(limited to 'src/lib/statsig/statsig.tsx')

diff --git a/src/lib/statsig/statsig.tsx b/src/lib/statsig/statsig.tsx
index 005027820..b7299be8c 100644
--- a/src/lib/statsig/statsig.tsx
+++ b/src/lib/statsig/statsig.tsx
@@ -85,11 +85,17 @@ export function toClout(n: number | null | undefined): number | undefined {
   }
 }
 
+const DOWNSAMPLED_EVENTS = new Set(['router:navigate:sampled'])
+const isDownsampledSession = Math.random() < 0.9 // 90% likely
+
 export function logEvent<E extends keyof LogEvents>(
   eventName: E & string,
   rawMetadata: LogEvents[E] & FlatJSONRecord,
 ) {
   try {
+    if (isDownsampledSession && DOWNSAMPLED_EVENTS.has(eventName)) {
+      return
+    }
     const fullMetadata = {
       ...rawMetadata,
     } as Record<string, string> // Statsig typings are unnecessarily strict here.
-- 
cgit 1.4.1

