@outlit/browser 0.0.0-canary-202512180440-754f4ab-20251218044038 → 0.0.0-canary-202601161920-3feb1db-20260116192046

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/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { i as init, t as track, a as identify, g as getInstance, O as Outlit, e as enableTracking, b as isTrackingEnabled } from './tracker-DFcTv3EM.mjs';
2
- export { c as OutlitOptions } from './tracker-DFcTv3EM.mjs';
3
- export { BrowserIdentifyOptions, BrowserTrackOptions, TrackerConfig, UtmParams } from '@outlit/core';
1
+ import { i as init, t as track, a as identify, g as getInstance, O as Outlit, e as enableTracking, b as isTrackingEnabled, s as setUser, c as clearUser, d as activate, f as engaged, p as paid, h as churned } from './tracker-DK-2gYCi.mjs';
2
+ export { j as OutlitOptions, U as UserIdentity } from './tracker-DK-2gYCi.mjs';
3
+ export { BrowserIdentifyOptions, BrowserTrackOptions, ExplicitJourneyStage, TrackerConfig, UtmParams } from '@outlit/core';
4
4
 
5
5
  declare const _default: {
6
6
  init: typeof init;
@@ -10,6 +10,12 @@ declare const _default: {
10
10
  Outlit: typeof Outlit;
11
11
  enableTracking: typeof enableTracking;
12
12
  isTrackingEnabled: typeof isTrackingEnabled;
13
+ setUser: typeof setUser;
14
+ clearUser: typeof clearUser;
15
+ activate: typeof activate;
16
+ engaged: typeof engaged;
17
+ paid: typeof paid;
18
+ churned: typeof churned;
13
19
  };
14
20
 
15
- export { Outlit, _default as default, enableTracking, getInstance, identify, init, isTrackingEnabled, track };
21
+ export { Outlit, activate, churned, clearUser, _default as default, enableTracking, engaged, getInstance, identify, init, isTrackingEnabled, paid, setUser, track };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { i as init, t as track, a as identify, g as getInstance, O as Outlit, e as enableTracking, b as isTrackingEnabled } from './tracker-DFcTv3EM.js';
2
- export { c as OutlitOptions } from './tracker-DFcTv3EM.js';
3
- export { BrowserIdentifyOptions, BrowserTrackOptions, TrackerConfig, UtmParams } from '@outlit/core';
1
+ import { i as init, t as track, a as identify, g as getInstance, O as Outlit, e as enableTracking, b as isTrackingEnabled, s as setUser, c as clearUser, d as activate, f as engaged, p as paid, h as churned } from './tracker-DK-2gYCi.js';
2
+ export { j as OutlitOptions, U as UserIdentity } from './tracker-DK-2gYCi.js';
3
+ export { BrowserIdentifyOptions, BrowserTrackOptions, ExplicitJourneyStage, TrackerConfig, UtmParams } from '@outlit/core';
4
4
 
5
5
  declare const _default: {
6
6
  init: typeof init;
@@ -10,6 +10,12 @@ declare const _default: {
10
10
  Outlit: typeof Outlit;
11
11
  enableTracking: typeof enableTracking;
12
12
  isTrackingEnabled: typeof isTrackingEnabled;
13
+ setUser: typeof setUser;
14
+ clearUser: typeof clearUser;
15
+ activate: typeof activate;
16
+ engaged: typeof engaged;
17
+ paid: typeof paid;
18
+ churned: typeof churned;
13
19
  };
14
20
 
15
- export { Outlit, _default as default, enableTracking, getInstance, identify, init, isTrackingEnabled, track };
21
+ export { Outlit, activate, churned, clearUser, _default as default, enableTracking, engaged, getInstance, identify, init, isTrackingEnabled, paid, setUser, track };
package/dist/index.js CHANGED
@@ -21,12 +21,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
23
  Outlit: () => Outlit,
24
+ activate: () => activate,
25
+ churned: () => churned,
26
+ clearUser: () => clearUser,
24
27
  default: () => src_default,
25
28
  enableTracking: () => enableTracking,
29
+ engaged: () => engaged,
26
30
  getInstance: () => getInstance,
27
31
  identify: () => identify,
28
32
  init: () => init,
29
33
  isTrackingEnabled: () => isTrackingEnabled,
34
+ paid: () => paid,
35
+ setUser: () => setUser,
30
36
  track: () => track
31
37
  });
32
38
  module.exports = __toCommonJS(src_exports);
@@ -251,6 +257,7 @@ var DEFAULT_IDLE_TIMEOUT = 3e4;
251
257
  var SESSION_TIMEOUT = 30 * 60 * 1e3;
252
258
  var TIME_UPDATE_INTERVAL = 1e3;
253
259
  var MIN_SPURIOUS_THRESHOLD = 50;
260
+ var MIN_PAGE_TIME_FOR_ENGAGEMENT = 500;
254
261
  var SESSION_ID_KEY = "outlit_session_id";
255
262
  var SESSION_LAST_ACTIVITY_KEY = "outlit_session_last_activity";
256
263
  var SessionTracker = class {
@@ -295,7 +302,8 @@ var SessionTracker = class {
295
302
  this.updateActiveTime();
296
303
  const totalTimeMs = Date.now() - this.state.pageEntryTime;
297
304
  const isSpuriousEvent = this.state.activeTimeMs < MIN_SPURIOUS_THRESHOLD && totalTimeMs < MIN_SPURIOUS_THRESHOLD;
298
- if (!isSpuriousEvent) {
305
+ const isTooSoonAfterNavigation = totalTimeMs < MIN_PAGE_TIME_FOR_ENGAGEMENT;
306
+ if (!isSpuriousEvent && !isTooSoonAfterNavigation) {
299
307
  const event = (0, import_core2.buildEngagementEvent)({
300
308
  url: this.state.currentUrl,
301
309
  referrer: document.referrer,
@@ -481,6 +489,7 @@ var SessionTracker = class {
481
489
  this.checkSessionExpiry();
482
490
  this.state.lastActiveTime = Date.now();
483
491
  this.state.hasEmittedEngagement = false;
492
+ this.updateSessionActivity();
484
493
  }
485
494
  }
486
495
  /**
@@ -636,6 +645,9 @@ var Outlit = class {
636
645
  options;
637
646
  hasHandledExit = false;
638
647
  sessionTracker = null;
648
+ // User identity state for stage events
649
+ currentUser = null;
650
+ pendingUser = null;
639
651
  constructor(options) {
640
652
  this.publicKey = options.publicKey;
641
653
  this.apiHost = options.apiHost ?? import_core3.DEFAULT_API_HOST;
@@ -681,9 +693,7 @@ var Outlit = class {
681
693
  }
682
694
  this.visitorId = getOrCreateVisitorId();
683
695
  this.startFlushTimer();
684
- if (this.options.trackEngagement !== false) {
685
- this.initSessionTracking();
686
- }
696
+ this.initSessionTracking();
687
697
  if (this.options.trackPageviews !== false) {
688
698
  this.initPageviewTracking();
689
699
  }
@@ -694,6 +704,10 @@ var Outlit = class {
694
704
  this.initCalendarTracking();
695
705
  }
696
706
  this.isTrackingEnabled = true;
707
+ if (this.pendingUser) {
708
+ this.applyUser(this.pendingUser);
709
+ this.pendingUser = null;
710
+ }
697
711
  }
698
712
  /**
699
713
  * Check if tracking is currently enabled.
@@ -720,12 +734,21 @@ var Outlit = class {
720
734
  /**
721
735
  * Identify the current visitor.
722
736
  * Links the anonymous visitor to a known user.
737
+ *
738
+ * When email or userId is provided, also sets the current user identity
739
+ * for stage events (activate, engaged, paid).
723
740
  */
724
741
  identify(options) {
725
742
  if (!this.isTrackingEnabled) {
726
743
  console.warn("[Outlit] Tracking not enabled. Call enableTracking() first.");
727
744
  return;
728
745
  }
746
+ if (options.email || options.userId) {
747
+ this.currentUser = {
748
+ email: options.email,
749
+ userId: options.userId
750
+ };
751
+ }
729
752
  const event = (0, import_core3.buildIdentifyEvent)({
730
753
  url: window.location.href,
731
754
  referrer: document.referrer,
@@ -735,6 +758,98 @@ var Outlit = class {
735
758
  });
736
759
  this.enqueue(event);
737
760
  }
761
+ /**
762
+ * Set the current user identity.
763
+ * This is useful for SPA applications where you know the user's identity
764
+ * after authentication. Calls identify() under the hood.
765
+ *
766
+ * If called before tracking is enabled, the identity is stored as pending
767
+ * and applied automatically when enableTracking() is called.
768
+ *
769
+ * Note: Both setUser() and identify() enable stage events. The difference is
770
+ * setUser() can be called before tracking is enabled (identity is queued),
771
+ * while identify() requires tracking to be enabled first.
772
+ */
773
+ setUser(identity) {
774
+ if (!identity.email && !identity.userId) {
775
+ console.warn("[Outlit] setUser requires at least email or userId");
776
+ return;
777
+ }
778
+ if (!this.isTrackingEnabled) {
779
+ this.pendingUser = identity;
780
+ return;
781
+ }
782
+ this.applyUser(identity);
783
+ }
784
+ /**
785
+ * Clear the current user identity.
786
+ * Call this when the user logs out.
787
+ */
788
+ clearUser() {
789
+ this.currentUser = null;
790
+ this.pendingUser = null;
791
+ }
792
+ /**
793
+ * Apply user identity and send identify event.
794
+ */
795
+ applyUser(identity) {
796
+ this.currentUser = identity;
797
+ this.identify({ email: identity.email, userId: identity.userId, traits: identity.traits });
798
+ }
799
+ /**
800
+ * Mark the current user as activated.
801
+ * This is typically called after a user completes onboarding or a key activation milestone.
802
+ * Requires the user to be identified (via setUser or identify with userId).
803
+ */
804
+ activate(properties) {
805
+ this.sendStageEvent("activated", properties);
806
+ }
807
+ /**
808
+ * Mark the current user as engaged.
809
+ * This is typically called when a user reaches a usage milestone.
810
+ * Can also be computed automatically by the engagement cron.
811
+ */
812
+ engaged(properties) {
813
+ this.sendStageEvent("engaged", properties);
814
+ }
815
+ /**
816
+ * Mark the current user as paid.
817
+ * This is typically called after a successful payment/subscription.
818
+ * Can also be triggered by Stripe integration.
819
+ */
820
+ paid(properties) {
821
+ this.sendStageEvent("paid", properties);
822
+ }
823
+ /**
824
+ * Mark the current user as churned.
825
+ * This is typically called when a subscription is cancelled.
826
+ * Can also be triggered by Stripe integration.
827
+ */
828
+ churned(properties) {
829
+ this.sendStageEvent("churned", properties);
830
+ }
831
+ /**
832
+ * Internal method to send a stage event.
833
+ */
834
+ sendStageEvent(stage, properties) {
835
+ if (!this.isTrackingEnabled) {
836
+ console.warn("[Outlit] Tracking not enabled. Call enableTracking() first.");
837
+ return;
838
+ }
839
+ if (!this.currentUser) {
840
+ console.warn(
841
+ `[Outlit] Cannot call ${stage}() without setting user identity. Call setUser() or identify() first.`
842
+ );
843
+ return;
844
+ }
845
+ const event = (0, import_core3.buildStageEvent)({
846
+ url: window.location.href,
847
+ referrer: document.referrer,
848
+ stage,
849
+ properties
850
+ });
851
+ this.enqueue(event);
852
+ }
738
853
  /**
739
854
  * Get the current visitor ID.
740
855
  * Returns null if tracking is not enabled.
@@ -770,8 +885,8 @@ var Outlit = class {
770
885
  // ============================================
771
886
  initSessionTracking() {
772
887
  this.sessionTracker = initSessionTracking({
773
- onEngagement: (event) => {
774
- this.enqueue(event);
888
+ // Only emit engagement events when trackEngagement is enabled (default: true)
889
+ onEngagement: this.options.trackEngagement !== false ? (event) => this.enqueue(event) : () => {
775
890
  },
776
891
  idleTimeout: this.options.idleTimeout
777
892
  });
@@ -842,7 +957,9 @@ var Outlit = class {
842
957
  async sendEvents(events) {
843
958
  if (events.length === 0) return;
844
959
  if (!this.visitorId) return;
845
- const payload = (0, import_core3.buildIngestPayload)(this.visitorId, "client", events);
960
+ const userIdentity = this.currentUser ?? void 0;
961
+ const sessionId = this.sessionTracker?.getSessionId();
962
+ const payload = (0, import_core3.buildIngestPayload)(this.visitorId, "client", events, userIdentity, sessionId);
846
963
  const url = `${this.apiHost}/api/i/v1/${this.publicKey}/events`;
847
964
  try {
848
965
  if (typeof navigator !== "undefined" && navigator.sendBeacon) {
@@ -890,6 +1007,24 @@ function enableTracking() {
890
1007
  function isTrackingEnabled() {
891
1008
  return getInstance().isEnabled();
892
1009
  }
1010
+ function setUser(identity) {
1011
+ getInstance().setUser(identity);
1012
+ }
1013
+ function clearUser() {
1014
+ getInstance().clearUser();
1015
+ }
1016
+ function activate(properties) {
1017
+ getInstance().activate(properties);
1018
+ }
1019
+ function engaged(properties) {
1020
+ getInstance().engaged(properties);
1021
+ }
1022
+ function paid(properties) {
1023
+ getInstance().paid(properties);
1024
+ }
1025
+ function churned(properties) {
1026
+ getInstance().churned(properties);
1027
+ }
893
1028
 
894
1029
  // src/index.ts
895
1030
  var src_default = {
@@ -899,16 +1034,28 @@ var src_default = {
899
1034
  getInstance,
900
1035
  Outlit,
901
1036
  enableTracking,
902
- isTrackingEnabled
1037
+ isTrackingEnabled,
1038
+ setUser,
1039
+ clearUser,
1040
+ activate,
1041
+ engaged,
1042
+ paid,
1043
+ churned
903
1044
  };
904
1045
  // Annotate the CommonJS export names for ESM import in node:
905
1046
  0 && (module.exports = {
906
1047
  Outlit,
1048
+ activate,
1049
+ churned,
1050
+ clearUser,
907
1051
  enableTracking,
1052
+ engaged,
908
1053
  getInstance,
909
1054
  identify,
910
1055
  init,
911
1056
  isTrackingEnabled,
1057
+ paid,
1058
+ setUser,
912
1059
  track
913
1060
  });
914
1061
  //# sourceMappingURL=index.js.map