posthog-js-lite 3.3.0 → 3.4.1

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.
package/lib/index.d.ts CHANGED
@@ -320,9 +320,22 @@ declare abstract class PostHogCore extends PostHogCoreStateless {
320
320
  /***
321
321
  *** ERROR TRACKING
322
322
  ***/
323
- captureException(error: Error, additionalProperties?: {
323
+ captureException(error: unknown, additionalProperties?: {
324
324
  [key: string]: any;
325
325
  }): void;
326
+ /**
327
+ * Capture written user feedback for a LLM trace. Numeric values are converted to strings.
328
+ * @param traceId The trace ID to capture feedback for.
329
+ * @param userFeedback The feedback to capture.
330
+ */
331
+ captureTraceFeedback(traceId: string | number, userFeedback: string): void;
332
+ /**
333
+ * Capture a metric for a LLM trace. Numeric values are converted to strings.
334
+ * @param traceId The trace ID to capture the metric for.
335
+ * @param metricName The name of the metric to capture.
336
+ * @param metricValue The value of the metric to capture.
337
+ */
338
+ captureTraceMetric(traceId: string | number, metricName: string, metricValue: string | number | boolean): void;
326
339
  }
327
340
 
328
341
  type PostHogOptions = {
package/lib/index.esm.js CHANGED
@@ -62,6 +62,9 @@ function safeSetTimeout(fn, timeout) {
62
62
  t?.unref && t?.unref();
63
63
  return t;
64
64
  }
65
+ const isError = (x) => {
66
+ return x instanceof Error;
67
+ };
65
68
  function getFetch() {
66
69
  return typeof fetch !== 'undefined' ? fetch : typeof global.fetch !== 'undefined' ? global.fetch : undefined;
67
70
  }
@@ -1486,6 +1489,7 @@ class PostHogCore extends PostHogCoreStateless {
1486
1489
  this.setPersistedProperty(PostHogPersistedProperty[key], null);
1487
1490
  }
1488
1491
  }
1492
+ this.reloadFeatureFlags();
1489
1493
  });
1490
1494
  }
1491
1495
  getCommonEventProperties() {
@@ -1761,6 +1765,7 @@ class PostHogCore extends PostHogCoreStateless {
1761
1765
  if (res.errorsWhileComputingFlags) {
1762
1766
  // if not all flags were computed, we upsert flags instead of replacing them
1763
1767
  const currentFlags = this.getPersistedProperty(PostHogPersistedProperty.FeatureFlags);
1768
+ this.logMsgIfDebug(() => console.log('PostHog Debug', 'Cached feature flags: ', JSON.stringify(currentFlags)));
1764
1769
  const currentFlagPayloads = this.getPersistedProperty(PostHogPersistedProperty.FeatureFlagPayloads);
1765
1770
  newFeatureFlags = { ...currentFlags, ...res.featureFlags };
1766
1771
  newFeatureFlagPayloads = { ...currentFlagPayloads, ...res.featureFlagPayloads };
@@ -1922,8 +1927,8 @@ class PostHogCore extends PostHogCoreStateless {
1922
1927
  $exception_level: 'error',
1923
1928
  $exception_list: [
1924
1929
  {
1925
- type: error.name,
1926
- value: error.message,
1930
+ type: isError(error) ? error.name : 'Error',
1931
+ value: isError(error) ? error.message : error,
1927
1932
  mechanism: {
1928
1933
  handled: true,
1929
1934
  synthetic: false,
@@ -1935,9 +1940,33 @@ class PostHogCore extends PostHogCoreStateless {
1935
1940
  properties.$exception_personURL = new URL(`/project/${this.apiKey}/person/${this.getDistinctId()}`, this.host).toString();
1936
1941
  this.capture('$exception', properties);
1937
1942
  }
1943
+ /**
1944
+ * Capture written user feedback for a LLM trace. Numeric values are converted to strings.
1945
+ * @param traceId The trace ID to capture feedback for.
1946
+ * @param userFeedback The feedback to capture.
1947
+ */
1948
+ captureTraceFeedback(traceId, userFeedback) {
1949
+ this.capture('$ai_feedback', {
1950
+ $ai_feedback_text: userFeedback,
1951
+ $ai_trace_id: String(traceId),
1952
+ });
1953
+ }
1954
+ /**
1955
+ * Capture a metric for a LLM trace. Numeric values are converted to strings.
1956
+ * @param traceId The trace ID to capture the metric for.
1957
+ * @param metricName The name of the metric to capture.
1958
+ * @param metricValue The value of the metric to capture.
1959
+ */
1960
+ captureTraceMetric(traceId, metricName, metricValue) {
1961
+ this.capture('$ai_metric', {
1962
+ $ai_metric_name: metricName,
1963
+ $ai_metric_value: String(metricValue),
1964
+ $ai_trace_id: String(traceId),
1965
+ });
1966
+ }
1938
1967
  }
1939
1968
 
1940
- var version = "3.3.0";
1969
+ var version = "3.4.1";
1941
1970
 
1942
1971
  function getContext(window) {
1943
1972
  let context = {};