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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Next
2
2
 
3
+ # 3.4.0 - 2025-02-20
4
+
5
+ ## Added
6
+
7
+ 1. Adds the ability to capture user feedback in LLM Observability using the `captureTraceFeedback` and `captureTraceMetric` methods.
8
+
3
9
  # 3.3.0 - 2025-02-06
4
10
 
5
11
  ## Added
package/README.md CHANGED
@@ -71,5 +71,5 @@ posthog.onFeatureFlag('my-feature-flag', (value) => {
71
71
 
72
72
  // Opt users in or out, persisting across sessions (default is they are opted in)
73
73
  posthog.optOut() // Will stop tracking
74
- posthog.optIn() // Will stop tracking
74
+ posthog.optIn() // Will start tracking
75
75
  ```
package/lib/index.cjs.js CHANGED
@@ -1490,6 +1490,7 @@ class PostHogCore extends PostHogCoreStateless {
1490
1490
  this.setPersistedProperty(PostHogPersistedProperty[key], null);
1491
1491
  }
1492
1492
  }
1493
+ this.reloadFeatureFlags();
1493
1494
  });
1494
1495
  }
1495
1496
  getCommonEventProperties() {
@@ -1765,6 +1766,7 @@ class PostHogCore extends PostHogCoreStateless {
1765
1766
  if (res.errorsWhileComputingFlags) {
1766
1767
  // if not all flags were computed, we upsert flags instead of replacing them
1767
1768
  const currentFlags = this.getPersistedProperty(PostHogPersistedProperty.FeatureFlags);
1769
+ this.logMsgIfDebug(() => console.log('PostHog Debug', 'Cached feature flags: ', JSON.stringify(currentFlags)));
1768
1770
  const currentFlagPayloads = this.getPersistedProperty(PostHogPersistedProperty.FeatureFlagPayloads);
1769
1771
  newFeatureFlags = { ...currentFlags, ...res.featureFlags };
1770
1772
  newFeatureFlagPayloads = { ...currentFlagPayloads, ...res.featureFlagPayloads };
@@ -1939,9 +1941,33 @@ class PostHogCore extends PostHogCoreStateless {
1939
1941
  properties.$exception_personURL = new URL(`/project/${this.apiKey}/person/${this.getDistinctId()}`, this.host).toString();
1940
1942
  this.capture('$exception', properties);
1941
1943
  }
1944
+ /**
1945
+ * Capture written user feedback for a LLM trace. Numeric values are converted to strings.
1946
+ * @param traceId The trace ID to capture feedback for.
1947
+ * @param userFeedback The feedback to capture.
1948
+ */
1949
+ captureTraceFeedback(traceId, userFeedback) {
1950
+ this.capture('$ai_feedback', {
1951
+ $ai_feedback_text: userFeedback,
1952
+ $ai_trace_id: String(traceId),
1953
+ });
1954
+ }
1955
+ /**
1956
+ * Capture a metric for a LLM trace. Numeric values are converted to strings.
1957
+ * @param traceId The trace ID to capture the metric for.
1958
+ * @param metricName The name of the metric to capture.
1959
+ * @param metricValue The value of the metric to capture.
1960
+ */
1961
+ captureTraceMetric(traceId, metricName, metricValue) {
1962
+ this.capture('$ai_metric', {
1963
+ $ai_metric_name: metricName,
1964
+ $ai_metric_value: String(metricValue),
1965
+ $ai_trace_id: String(traceId),
1966
+ });
1967
+ }
1942
1968
  }
1943
1969
 
1944
- var version = "3.3.0";
1970
+ var version = "3.4.0";
1945
1971
 
1946
1972
  function getContext(window) {
1947
1973
  let context = {};