| 164 | const posthogKey = config.posthogKey ?? DEFAULT_POSTHOG_KEY; |
| 165 | |
| 166 | const sendBatch = (events: ReadonlyArray<BufferedEvent>) => |
| 167 | HttpClientRequest.post(`${posthogHost}/batch/`).pipe( |
| 168 | HttpClientRequest.bodyJson({ |
| 169 | api_key: posthogKey, |
| 170 | batch: events.map((entry) => ({ |
| 171 | event: entry.event, |
| 172 | distinct_id: distinctId, |
| 173 | timestamp: entry.timestamp, |
| 174 | properties: { |
| 175 | ...entry.properties, |
| 176 | // Anonymous events only: never materialize a person profile. |
| 177 | $process_person_profile: false, |
| 178 | surface: config.surface, |
| 179 | channel: config.channel, |
| 180 | app_version: config.version, |
| 181 | }, |
| 182 | })), |
| 183 | }), |
| 184 | Effect.flatMap(http.execute), |
| 185 | Effect.flatMap(HttpClientResponse.filterStatusOk), |
| 186 | Effect.asVoid, |
| 187 | Effect.timeout(Duration.seconds(10)), |
| 188 | ); |
| 189 | |
| 190 | const flush: Effect.Effect<void> = Effect.gen(function* () { |
| 191 | while (true) { |