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/lib/index.d.ts CHANGED
@@ -317,6 +317,25 @@ declare abstract class PostHogCore extends PostHogCoreStateless {
317
317
  onFeatureFlags(cb: (flags: PostHogDecideResponse['featureFlags']) => void): () => void;
318
318
  onFeatureFlag(key: string, cb: (value: string | boolean) => void): () => void;
319
319
  overrideFeatureFlag(flags: PostHogDecideResponse['featureFlags'] | null): Promise<void>;
320
+ /***
321
+ *** ERROR TRACKING
322
+ ***/
323
+ captureException(error: Error, additionalProperties?: {
324
+ [key: string]: any;
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;
320
339
  }
321
340
 
322
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 };
@@ -1914,9 +1916,54 @@ class PostHogCore extends PostHogCoreStateless {
1914
1916
  return this.setPersistedProperty(PostHogPersistedProperty.OverrideFeatureFlags, flags);
1915
1917
  });
1916
1918
  }
1919
+ /***
1920
+ *** ERROR TRACKING
1921
+ ***/
1922
+ captureException(error, additionalProperties) {
1923
+ const properties = {
1924
+ $exception_level: 'error',
1925
+ $exception_list: [
1926
+ {
1927
+ type: error.name,
1928
+ value: error.message,
1929
+ mechanism: {
1930
+ handled: true,
1931
+ synthetic: false,
1932
+ },
1933
+ },
1934
+ ],
1935
+ ...additionalProperties,
1936
+ };
1937
+ properties.$exception_personURL = new URL(`/project/${this.apiKey}/person/${this.getDistinctId()}`, this.host).toString();
1938
+ this.capture('$exception', properties);
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
+ }
1917
1964
  }
1918
1965
 
1919
- var version = "3.2.1";
1966
+ var version = "3.4.0";
1920
1967
 
1921
1968
  function getContext(window) {
1922
1969
  let context = {};