posthog-js-lite 3.3.0 → 3.4.0

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
@@ -323,6 +323,19 @@ declare abstract class PostHogCore extends PostHogCoreStateless {
323
323
  captureException(error: Error, 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
@@ -1486,6 +1486,7 @@ class PostHogCore extends PostHogCoreStateless {
1486
1486
  this.setPersistedProperty(PostHogPersistedProperty[key], null);
1487
1487
  }
1488
1488
  }
1489
+ this.reloadFeatureFlags();
1489
1490
  });
1490
1491
  }
1491
1492
  getCommonEventProperties() {
@@ -1761,6 +1762,7 @@ class PostHogCore extends PostHogCoreStateless {
1761
1762
  if (res.errorsWhileComputingFlags) {
1762
1763
  // if not all flags were computed, we upsert flags instead of replacing them
1763
1764
  const currentFlags = this.getPersistedProperty(PostHogPersistedProperty.FeatureFlags);
1765
+ this.logMsgIfDebug(() => console.log('PostHog Debug', 'Cached feature flags: ', JSON.stringify(currentFlags)));
1764
1766
  const currentFlagPayloads = this.getPersistedProperty(PostHogPersistedProperty.FeatureFlagPayloads);
1765
1767
  newFeatureFlags = { ...currentFlags, ...res.featureFlags };
1766
1768
  newFeatureFlagPayloads = { ...currentFlagPayloads, ...res.featureFlagPayloads };
@@ -1935,9 +1937,33 @@ class PostHogCore extends PostHogCoreStateless {
1935
1937
  properties.$exception_personURL = new URL(`/project/${this.apiKey}/person/${this.getDistinctId()}`, this.host).toString();
1936
1938
  this.capture('$exception', properties);
1937
1939
  }
1940
+ /**
1941
+ * Capture written user feedback for a LLM trace. Numeric values are converted to strings.
1942
+ * @param traceId The trace ID to capture feedback for.
1943
+ * @param userFeedback The feedback to capture.
1944
+ */
1945
+ captureTraceFeedback(traceId, userFeedback) {
1946
+ this.capture('$ai_feedback', {
1947
+ $ai_feedback_text: userFeedback,
1948
+ $ai_trace_id: String(traceId),
1949
+ });
1950
+ }
1951
+ /**
1952
+ * Capture a metric for a LLM trace. Numeric values are converted to strings.
1953
+ * @param traceId The trace ID to capture the metric for.
1954
+ * @param metricName The name of the metric to capture.
1955
+ * @param metricValue The value of the metric to capture.
1956
+ */
1957
+ captureTraceMetric(traceId, metricName, metricValue) {
1958
+ this.capture('$ai_metric', {
1959
+ $ai_metric_name: metricName,
1960
+ $ai_metric_value: String(metricValue),
1961
+ $ai_trace_id: String(traceId),
1962
+ });
1963
+ }
1938
1964
  }
1939
1965
 
1940
- var version = "3.3.0";
1966
+ var version = "3.4.0";
1941
1967
 
1942
1968
  function getContext(window) {
1943
1969
  let context = {};