sitepong 0.2.1 → 0.2.2

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.mjs CHANGED
@@ -1,5 +1,3 @@
1
- import 'web-vitals';
2
-
3
1
  // src/flags/anonymous-id.ts
4
2
  var STORAGE_KEY = "sitepong_anonymous_id";
5
3
  function generateUUID() {
@@ -580,6 +578,7 @@ var DEFAULT_BLOCK_SELECTORS = [
580
578
  var MAX_TEXT_LENGTH = 255;
581
579
  var AutocaptureModule = class {
582
580
  constructor(config, callback) {
581
+ this.listeners = [];
583
582
  this.clickHandler = null;
584
583
  this.submitHandler = null;
585
584
  this.active = false;
@@ -594,6 +593,27 @@ var AutocaptureModule = class {
594
593
  };
595
594
  this.callback = callback;
596
595
  }
596
+ /**
597
+ * Register a secondary listener that receives the same events as the
598
+ * primary callback (e.g. Watchtower tap capture reusing the single click
599
+ * listener + selector resolution). Returns an unsubscribe function.
600
+ */
601
+ addListener(cb) {
602
+ this.listeners.push(cb);
603
+ return () => {
604
+ const idx = this.listeners.indexOf(cb);
605
+ if (idx >= 0) this.listeners.splice(idx, 1);
606
+ };
607
+ }
608
+ emit(event) {
609
+ this.callback(event);
610
+ for (const listener of this.listeners) {
611
+ try {
612
+ listener(event);
613
+ } catch {
614
+ }
615
+ }
616
+ }
597
617
  start() {
598
618
  if (this.active || typeof document === "undefined" || typeof document.addEventListener !== "function") return;
599
619
  this.active = true;
@@ -626,7 +646,7 @@ var AutocaptureModule = class {
626
646
  properties.$event_type = "click";
627
647
  properties.$x = e.clientX;
628
648
  properties.$y = e.clientY;
629
- this.callback({
649
+ this.emit({
630
650
  type: "click",
631
651
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
632
652
  properties
@@ -648,7 +668,7 @@ var AutocaptureModule = class {
648
668
  };
649
669
  const elemProps = this.getElementProperties(form);
650
670
  Object.assign(properties, elemProps);
651
- this.callback({
671
+ this.emit({
652
672
  type: "form_submit",
653
673
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
654
674
  properties
@@ -865,6 +885,14 @@ var AnalyticsManager = class {
865
885
  );
866
886
  this.autocaptureModule.start();
867
887
  }
888
+ /**
889
+ * The live AutocaptureModule (if click/form autocapture is enabled) —
890
+ * Watchtower tap capture attaches to it so there is only ONE document-level
891
+ * click listener and one selector/element resolution path.
892
+ */
893
+ getAutocaptureModule() {
894
+ return this.autocaptureModule;
895
+ }
868
896
  track(eventName, properties) {
869
897
  if (!this.config.enabled) return;
870
898
  const event = this.createEvent("track", { name: eventName, properties });
@@ -2376,6 +2404,8 @@ var SitePongClient = class {
2376
2404
  this.databaseTracker = null;
2377
2405
  this.profiler = null;
2378
2406
  this.remoteConfigManager = null;
2407
+ this.watchtowerCapture = null;
2408
+ this.watchtowerOptions = void 0;
2379
2409
  this.envUnsubs = [];
2380
2410
  this.identifyHooks = [];
2381
2411
  this.config = {
@@ -2495,6 +2525,12 @@ var SitePongClient = class {
2495
2525
  } else if (config.replay?.enabled) {
2496
2526
  this.log("Replay requested but not available on this platform (web only).");
2497
2527
  }
2528
+ this.watchtowerOptions = config.watchtower;
2529
+ if (config.watchtower?.enabled && webManagerFactories.createWatchtowerCapture) {
2530
+ this.startWatchtowerCapture();
2531
+ } else if (config.watchtower?.enabled) {
2532
+ this.log("Watchtower capture requested but not available on this platform (web only).");
2533
+ }
2498
2534
  if (config.crons?.enabled) {
2499
2535
  this.cronManager = new CronMonitorManager({
2500
2536
  apiKey: config.apiKey,
@@ -2734,6 +2770,7 @@ var SitePongClient = class {
2734
2770
  this.log("identify hook failed:", err);
2735
2771
  }
2736
2772
  }
2773
+ this.watchtowerCapture?.setDistinctId(userId);
2737
2774
  if (!this.analyticsManager) {
2738
2775
  this.log("Analytics not enabled. Set analytics.enabled: true in init()");
2739
2776
  return;
@@ -2801,6 +2838,49 @@ var SitePongClient = class {
2801
2838
  getReplaySessionId() {
2802
2839
  return this.replayManager?.getSessionId() ?? null;
2803
2840
  }
2841
+ // --- Watchtower tap capture (web) ---
2842
+ /**
2843
+ * Start Watchtower web tap capture. Options merge over `watchtower` from
2844
+ * init(); `projectId` is required (either here or in init config). Reuses
2845
+ * the analytics AutocaptureModule's click listener when autocapture is on.
2846
+ */
2847
+ startWatchtowerCapture(options) {
2848
+ if (!webManagerFactories.createWatchtowerCapture) {
2849
+ this.log("Watchtower capture not available on this platform (web only).");
2850
+ return false;
2851
+ }
2852
+ if (!this.initialized || !this.config.apiKey) {
2853
+ this.log("Watchtower capture requires init() to be called first.");
2854
+ return false;
2855
+ }
2856
+ const opts = { ...this.watchtowerOptions, ...options };
2857
+ if (!opts.projectId) {
2858
+ this.log("Watchtower capture requires watchtower.projectId.");
2859
+ return false;
2860
+ }
2861
+ if (this.watchtowerCapture) {
2862
+ this.watchtowerCapture.stop();
2863
+ this.watchtowerCapture = null;
2864
+ }
2865
+ this.watchtowerCapture = webManagerFactories.createWatchtowerCapture({
2866
+ apiKey: this.config.apiKey,
2867
+ projectId: opts.projectId,
2868
+ endpoint: opts.endpoint || this.config.endpoint || DEFAULT_ENDPOINT3,
2869
+ appVersion: this.config.release || void 0,
2870
+ maxBatchSize: opts.maxBatchSize,
2871
+ flushInterval: opts.flushInterval,
2872
+ blockSelector: opts.blockSelector,
2873
+ maskSelector: opts.maskSelector,
2874
+ debug: this.config.debug
2875
+ });
2876
+ this.watchtowerCapture.start(this.analyticsManager?.getAutocaptureModule() ?? null);
2877
+ return true;
2878
+ }
2879
+ stopWatchtowerCapture() {
2880
+ if (!this.watchtowerCapture) return;
2881
+ this.watchtowerCapture.stop();
2882
+ this.watchtowerCapture = null;
2883
+ }
2804
2884
  // --- Performance (Tier 7) ---
2805
2885
  startTransaction(name, data) {
2806
2886
  if (!this.performanceManager) {
@@ -2952,6 +3032,7 @@ var SitePongClient = class {
2952
3032
  if (this.replayManager) {
2953
3033
  this.replayManager.setUser(null);
2954
3034
  }
3035
+ this.watchtowerCapture?.setDistinctId(null);
2955
3036
  }
2956
3037
  addBreadcrumb(breadcrumb) {
2957
3038
  this.log("Breadcrumb added:", breadcrumb);
@@ -3176,6 +3257,8 @@ var getDeviceSignals = sitepong.getDeviceSignals.bind(sitepong);
3176
3257
  var getFraudCheck = sitepong.getFraudCheck.bind(sitepong);
3177
3258
  var startReplay = sitepong.startReplay.bind(sitepong);
3178
3259
  var stopReplay = sitepong.stopReplay.bind(sitepong);
3260
+ var startWatchtowerCapture = sitepong.startWatchtowerCapture.bind(sitepong);
3261
+ var stopWatchtowerCapture = sitepong.stopWatchtowerCapture.bind(sitepong);
3179
3262
  var isReplayRecording = sitepong.isReplayRecording.bind(sitepong);
3180
3263
  var getReplaySessionId = sitepong.getReplaySessionId.bind(sitepong);
3181
3264
  var startTransaction = sitepong.startTransaction.bind(sitepong);
@@ -3209,6 +3292,6 @@ var onRemoteConfigChange = sitepong.onRemoteConfigChange.bind(sitepong);
3209
3292
  var registerIdentifyHook = sitepong.registerIdentifyHook.bind(sitepong);
3210
3293
  var src_default = sitepong;
3211
3294
 
3212
- export { DEFAULT_SUPERLINK_ENDPOINT, SuperLinkClient, TracePropagator, addBreadcrumb, areFlagsReady, captureError, captureMessage, captureWebDeepLink, clearAnonymousId, clearUser, sitepong as client, completeFromScan, createTraceContext, cronCheckin, cronStart, cronWrap, dbTrack, dbTrackSync, src_default as default, endSpan, endTransaction, extractIdentityMetadata, extractTrace, flush, flushMetrics, flushProfiles, generateSpanId, generateTraceId, getAllFlags, getAnonymousId, getDbNPlusOnePatterns, getDbQueryCount, getDeepLink, getDeviceSignals, getFlag, getFraudCheck, getLatestProfile, getMatchedDeepLink, getProfiles, getRemoteConfig, getReplaySessionId, getVariant, getVariantPayload2 as getVariantPayload, getVisitorId, getWebVitals, group, identify2 as identify, init, initRN, initSuperLink, isInitialized, isRemoteConfigFeatureEnabled, isReplayRecording, metricDistribution, metricGauge, metricHistogram, metricIncrement, metricStartTimer, metricTime, onDeferredDeepLink, onRemoteConfigChange, parseUniversalLink, profile, propagateTrace, refreshFlags, registerIdentifyHook, registerWebManagerFactories, resetAnalytics, resetDbQueryCount, setAnonymousId, setContext, setCurrentScreen, setEnvironment, setRNGetCurrentScreen, setTags, setUser, startProfileSpan, startReplay, startSpan, startTransaction, stopReplay, superlinkClient, identify as superlinkIdentify, track, trackPageView, waitForFlags, writeClipboardToken };
3295
+ export { DEFAULT_SUPERLINK_ENDPOINT, SuperLinkClient, TracePropagator, addBreadcrumb, areFlagsReady, captureError, captureMessage, captureWebDeepLink, clearAnonymousId, clearUser, sitepong as client, completeFromScan, createTraceContext, cronCheckin, cronStart, cronWrap, dbTrack, dbTrackSync, src_default as default, endSpan, endTransaction, extractIdentityMetadata, extractTrace, flush, flushMetrics, flushProfiles, generateSpanId, generateTraceId, getAllFlags, getAnonymousId, getDbNPlusOnePatterns, getDbQueryCount, getDeepLink, getDeviceSignals, getFlag, getFraudCheck, getLatestProfile, getMatchedDeepLink, getProfiles, getRemoteConfig, getReplaySessionId, getVariant, getVariantPayload2 as getVariantPayload, getVisitorId, getWebVitals, group, identify2 as identify, init, initRN, initSuperLink, isInitialized, isRemoteConfigFeatureEnabled, isReplayRecording, metricDistribution, metricGauge, metricHistogram, metricIncrement, metricStartTimer, metricTime, onDeferredDeepLink, onRemoteConfigChange, parseUniversalLink, profile, propagateTrace, refreshFlags, registerIdentifyHook, registerWebManagerFactories, resetAnalytics, resetDbQueryCount, setAnonymousId, setContext, setCurrentScreen, setEnvironment, setRNGetCurrentScreen, setTags, setUser, startProfileSpan, startReplay, startSpan, startTransaction, startWatchtowerCapture, stopReplay, stopWatchtowerCapture, superlinkClient, identify as superlinkIdentify, track, trackPageView, waitForFlags, writeClipboardToken };
3213
3296
  //# sourceMappingURL=index.mjs.map
3214
3297
  //# sourceMappingURL=index.mjs.map