posthog-js-lite 3.2.1 → 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,17 @@
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
+
9
+ # 3.3.0 - 2025-02-06
10
+
11
+ ## Added
12
+
13
+ 1. Adds `captureException` function to allow manual capture of exceptions
14
+
3
15
  # 3.2.1 - 2025-01-17
4
16
 
5
17
  ## Fixed
@@ -12,13 +24,12 @@
12
24
 
13
25
  1. Add new debugging property `$feature_flag_bootstrapped_response`, `$feature_flag_bootstrapped_payload` and `$used_bootstrap_value` to `$feature_flag_called` event
14
26
 
15
-
16
27
  # 3.1.0 - 2024-11-21
17
28
 
18
29
  ## Changed
19
30
 
20
31
  1. chore: default `captureMode` changed to `json`.
21
- 1. To keep using the `form` mode, just set the `captureMode` option to `form` when initializing the PostHog client.
32
+ 1. To keep using the `form` mode, just set the `captureMode` option to `form` when initializing the PostHog client.
22
33
  2. fix: identify method allows passing a $set_once object
23
34
 
24
35
  # 3.0.2 - 2024-06-15
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > 🚧 This is a reduced feature set package. Currently the only officially supported feature complete way of using PostHog on the web is [posthog-js](https://github.com/PostHog/posthog-js)
4
4
 
5
- This package is currently published to npm as [posthog-js-lite](https://www.npmjs.com/package/posthog-js-lite) and is a simplified version of the recommended and offically supported `posthog-js`.
5
+ This package is currently published to npm as [posthog-js-lite](https://www.npmjs.com/package/posthog-js-lite) and is a simplified version of the recommended and officially supported `posthog-js`.
6
6
 
7
7
  You'd want to use this only if you're very conscious about package sizes, and this reduced feature set (only analytics and feature flags) works for your use case. The most common use case is in chrome extensions.
8
8
 
@@ -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 };
@@ -1918,9 +1920,54 @@ class PostHogCore extends PostHogCoreStateless {
1918
1920
  return this.setPersistedProperty(PostHogPersistedProperty.OverrideFeatureFlags, flags);
1919
1921
  });
1920
1922
  }
1923
+ /***
1924
+ *** ERROR TRACKING
1925
+ ***/
1926
+ captureException(error, additionalProperties) {
1927
+ const properties = {
1928
+ $exception_level: 'error',
1929
+ $exception_list: [
1930
+ {
1931
+ type: error.name,
1932
+ value: error.message,
1933
+ mechanism: {
1934
+ handled: true,
1935
+ synthetic: false,
1936
+ },
1937
+ },
1938
+ ],
1939
+ ...additionalProperties,
1940
+ };
1941
+ properties.$exception_personURL = new URL(`/project/${this.apiKey}/person/${this.getDistinctId()}`, this.host).toString();
1942
+ this.capture('$exception', properties);
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
+ }
1921
1968
  }
1922
1969
 
1923
- var version = "3.2.1";
1970
+ var version = "3.4.0";
1924
1971
 
1925
1972
  function getContext(window) {
1926
1973
  let context = {};