@crimson-education/browser-logger 5.0.2 → 5.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -145,10 +145,73 @@ describe('posthogReporter', () => {
145
145
 
146
146
  reporter.recordSession?.();
147
147
  reporter.recordSessionStop?.();
148
- expect(posthogMock.startSessionRecording).toHaveBeenCalledWith(true);
148
+ expect(posthogMock.startSessionRecording).toHaveBeenCalledWith({
149
+ event_trigger: true,
150
+ linked_flag: true,
151
+ sampling: true,
152
+ url_trigger: true,
153
+ });
149
154
  expect(posthogMock.stopSessionRecording).toHaveBeenCalled();
150
155
  });
151
156
 
157
+ it('suppresses configured trackEvent messages from PostHog analytics', () => {
158
+ const reporter = posthogReporter(
159
+ {
160
+ service: 'crimson-app-frontend',
161
+ application: 'crimson-app',
162
+ environment: 'production',
163
+ version: '1.2.3',
164
+ },
165
+ {
166
+ apiKey: 'ph_key',
167
+ apiHost: 'https://eu.i.posthog.com',
168
+ ignoreTrackEventPatterns: ['feedback fetch success'],
169
+ },
170
+ );
171
+
172
+ reporter.trackEvent({
173
+ message: 'feedback fetch success',
174
+ level: LogLevel.Info,
175
+ });
176
+
177
+ expect(posthogMock.capture).not.toHaveBeenCalled();
178
+
179
+ reporter.trackEvent({
180
+ message: 'message-sent',
181
+ level: LogLevel.Info,
182
+ });
183
+
184
+ expect(posthogMock.capture).toHaveBeenCalledWith('message-sent', {
185
+ message: 'message-sent',
186
+ level: LogLevel.Info,
187
+ });
188
+ });
189
+
190
+ it('does not suppress trackEvent messages unless configured', () => {
191
+ const reporter = posthogReporter(
192
+ {
193
+ service: 'crimson-app-frontend',
194
+ application: 'crimson-app',
195
+ environment: 'production',
196
+ version: '1.2.3',
197
+ },
198
+ {
199
+ apiKey: 'ph_key',
200
+ apiHost: 'https://eu.i.posthog.com',
201
+ },
202
+ );
203
+
204
+ reporter.trackEvent({
205
+ message: 'feedback fetch success',
206
+ level: LogLevel.Info,
207
+ });
208
+
209
+ expect(posthogMock.capture).toHaveBeenCalledWith('feedback fetch success', {
210
+ message: 'feedback fetch success',
211
+ level: LogLevel.Info,
212
+ });
213
+ });
214
+
152
215
  it('adds compatibility properties in before_send', () => {
153
216
  const beforeSend = jest.fn((captureResult) => captureResult);
154
217
 
@@ -10,6 +10,7 @@ import {
10
10
  ReportUser,
11
11
  ServiceInfo,
12
12
  } from '../types';
13
+ import { shouldSuppressAnalyticsEvent } from './analyticsNoise';
13
14
 
14
15
  type PostHogValue = Properties[string];
15
16
 
@@ -283,6 +284,9 @@ export function posthogReporter(info: ServiceInfo, config: PostHogReporterConfig
283
284
  const reporter: IReporter = {
284
285
  ...config,
285
286
  trackEvent: function (event: ReporterEvent): void {
287
+ if (shouldSuppressAnalyticsEvent(event.message, config.ignoreTrackEventPatterns)) {
288
+ return;
289
+ }
286
290
  posthog.capture(event.message, {
287
291
  message: event.message,
288
292
  level: event.level,
@@ -363,7 +367,12 @@ export function posthogReporter(info: ServiceInfo, config: PostHogReporterConfig
363
367
  });
364
368
  },
365
369
  recordSession: function (): void {
366
- posthog.startSessionRecording(true);
370
+ posthog.startSessionRecording({
371
+ event_trigger: true,
372
+ linked_flag: true,
373
+ sampling: true,
374
+ url_trigger: true,
375
+ });
367
376
  },
368
377
  recordSessionStop: function (): void {
369
378
  posthog.stopSessionRecording();
@@ -163,6 +163,12 @@ export interface ReporterConfigBase {
163
163
  * This is useful to prevent data of no use for the reporter, or if the data keys are too long.
164
164
  */
165
165
  ignoreMetadataPatterns?: (string | RegExp)[];
166
+
167
+ /**
168
+ * Ignore specific trackEvent messages from analytics-style reporters.
169
+ * This keeps technical log noise out of product analytics/RUM while preserving log reporter output.
170
+ */
171
+ ignoreTrackEventPatterns?: (string | RegExp)[];
166
172
  }
167
173
 
168
174
  /**