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.
@@ -1,5 +1,4 @@
1
1
  import { createContext, useRef, useEffect, Component, useContext, useCallback, useState } from 'react';
2
- import 'web-vitals';
3
2
  import { jsx, jsxs } from 'react/jsx-runtime';
4
3
 
5
4
  // src/react/provider.tsx
@@ -584,6 +583,7 @@ var DEFAULT_BLOCK_SELECTORS = [
584
583
  var MAX_TEXT_LENGTH = 255;
585
584
  var AutocaptureModule = class {
586
585
  constructor(config, callback) {
586
+ this.listeners = [];
587
587
  this.clickHandler = null;
588
588
  this.submitHandler = null;
589
589
  this.active = false;
@@ -598,6 +598,27 @@ var AutocaptureModule = class {
598
598
  };
599
599
  this.callback = callback;
600
600
  }
601
+ /**
602
+ * Register a secondary listener that receives the same events as the
603
+ * primary callback (e.g. Watchtower tap capture reusing the single click
604
+ * listener + selector resolution). Returns an unsubscribe function.
605
+ */
606
+ addListener(cb) {
607
+ this.listeners.push(cb);
608
+ return () => {
609
+ const idx = this.listeners.indexOf(cb);
610
+ if (idx >= 0) this.listeners.splice(idx, 1);
611
+ };
612
+ }
613
+ emit(event) {
614
+ this.callback(event);
615
+ for (const listener of this.listeners) {
616
+ try {
617
+ listener(event);
618
+ } catch {
619
+ }
620
+ }
621
+ }
601
622
  start() {
602
623
  if (this.active || typeof document === "undefined" || typeof document.addEventListener !== "function") return;
603
624
  this.active = true;
@@ -630,7 +651,7 @@ var AutocaptureModule = class {
630
651
  properties.$event_type = "click";
631
652
  properties.$x = e.clientX;
632
653
  properties.$y = e.clientY;
633
- this.callback({
654
+ this.emit({
634
655
  type: "click",
635
656
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
636
657
  properties
@@ -652,7 +673,7 @@ var AutocaptureModule = class {
652
673
  };
653
674
  const elemProps = this.getElementProperties(form);
654
675
  Object.assign(properties, elemProps);
655
- this.callback({
676
+ this.emit({
656
677
  type: "form_submit",
657
678
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
658
679
  properties
@@ -869,6 +890,14 @@ var AnalyticsManager = class {
869
890
  );
870
891
  this.autocaptureModule.start();
871
892
  }
893
+ /**
894
+ * The live AutocaptureModule (if click/form autocapture is enabled) —
895
+ * Watchtower tap capture attaches to it so there is only ONE document-level
896
+ * click listener and one selector/element resolution path.
897
+ */
898
+ getAutocaptureModule() {
899
+ return this.autocaptureModule;
900
+ }
872
901
  track(eventName, properties) {
873
902
  if (!this.config.enabled) return;
874
903
  const event = this.createEvent("track", { name: eventName, properties });
@@ -2380,6 +2409,8 @@ var SitePongClient = class {
2380
2409
  this.databaseTracker = null;
2381
2410
  this.profiler = null;
2382
2411
  this.remoteConfigManager = null;
2412
+ this.watchtowerCapture = null;
2413
+ this.watchtowerOptions = void 0;
2383
2414
  this.envUnsubs = [];
2384
2415
  this.identifyHooks = [];
2385
2416
  this.config = {
@@ -2499,6 +2530,12 @@ var SitePongClient = class {
2499
2530
  } else if (config.replay?.enabled) {
2500
2531
  this.log("Replay requested but not available on this platform (web only).");
2501
2532
  }
2533
+ this.watchtowerOptions = config.watchtower;
2534
+ if (config.watchtower?.enabled && webManagerFactories.createWatchtowerCapture) {
2535
+ this.startWatchtowerCapture();
2536
+ } else if (config.watchtower?.enabled) {
2537
+ this.log("Watchtower capture requested but not available on this platform (web only).");
2538
+ }
2502
2539
  if (config.crons?.enabled) {
2503
2540
  this.cronManager = new CronMonitorManager({
2504
2541
  apiKey: config.apiKey,
@@ -2738,6 +2775,7 @@ var SitePongClient = class {
2738
2775
  this.log("identify hook failed:", err);
2739
2776
  }
2740
2777
  }
2778
+ this.watchtowerCapture?.setDistinctId(userId);
2741
2779
  if (!this.analyticsManager) {
2742
2780
  this.log("Analytics not enabled. Set analytics.enabled: true in init()");
2743
2781
  return;
@@ -2805,6 +2843,49 @@ var SitePongClient = class {
2805
2843
  getReplaySessionId() {
2806
2844
  return this.replayManager?.getSessionId() ?? null;
2807
2845
  }
2846
+ // --- Watchtower tap capture (web) ---
2847
+ /**
2848
+ * Start Watchtower web tap capture. Options merge over `watchtower` from
2849
+ * init(); `projectId` is required (either here or in init config). Reuses
2850
+ * the analytics AutocaptureModule's click listener when autocapture is on.
2851
+ */
2852
+ startWatchtowerCapture(options) {
2853
+ if (!webManagerFactories.createWatchtowerCapture) {
2854
+ this.log("Watchtower capture not available on this platform (web only).");
2855
+ return false;
2856
+ }
2857
+ if (!this.initialized || !this.config.apiKey) {
2858
+ this.log("Watchtower capture requires init() to be called first.");
2859
+ return false;
2860
+ }
2861
+ const opts = { ...this.watchtowerOptions, ...options };
2862
+ if (!opts.projectId) {
2863
+ this.log("Watchtower capture requires watchtower.projectId.");
2864
+ return false;
2865
+ }
2866
+ if (this.watchtowerCapture) {
2867
+ this.watchtowerCapture.stop();
2868
+ this.watchtowerCapture = null;
2869
+ }
2870
+ this.watchtowerCapture = webManagerFactories.createWatchtowerCapture({
2871
+ apiKey: this.config.apiKey,
2872
+ projectId: opts.projectId,
2873
+ endpoint: opts.endpoint || this.config.endpoint || DEFAULT_ENDPOINT3,
2874
+ appVersion: this.config.release || void 0,
2875
+ maxBatchSize: opts.maxBatchSize,
2876
+ flushInterval: opts.flushInterval,
2877
+ blockSelector: opts.blockSelector,
2878
+ maskSelector: opts.maskSelector,
2879
+ debug: this.config.debug
2880
+ });
2881
+ this.watchtowerCapture.start(this.analyticsManager?.getAutocaptureModule() ?? null);
2882
+ return true;
2883
+ }
2884
+ stopWatchtowerCapture() {
2885
+ if (!this.watchtowerCapture) return;
2886
+ this.watchtowerCapture.stop();
2887
+ this.watchtowerCapture = null;
2888
+ }
2808
2889
  // --- Performance (Tier 7) ---
2809
2890
  startTransaction(name, data) {
2810
2891
  if (!this.performanceManager) {
@@ -2956,6 +3037,7 @@ var SitePongClient = class {
2956
3037
  if (this.replayManager) {
2957
3038
  this.replayManager.setUser(null);
2958
3039
  }
3040
+ this.watchtowerCapture?.setDistinctId(null);
2959
3041
  }
2960
3042
  addBreadcrumb(breadcrumb) {
2961
3043
  this.log("Breadcrumb added:", breadcrumb);
@@ -3180,6 +3262,8 @@ var getDeviceSignals = sitepong.getDeviceSignals.bind(sitepong);
3180
3262
  var getFraudCheck = sitepong.getFraudCheck.bind(sitepong);
3181
3263
  var startReplay = sitepong.startReplay.bind(sitepong);
3182
3264
  var stopReplay = sitepong.stopReplay.bind(sitepong);
3265
+ var startWatchtowerCapture = sitepong.startWatchtowerCapture.bind(sitepong);
3266
+ var stopWatchtowerCapture = sitepong.stopWatchtowerCapture.bind(sitepong);
3183
3267
  var isReplayRecording = sitepong.isReplayRecording.bind(sitepong);
3184
3268
  var getReplaySessionId = sitepong.getReplaySessionId.bind(sitepong);
3185
3269
  var startTransaction = sitepong.startTransaction.bind(sitepong);
@@ -3580,6 +3664,6 @@ function useReplay() {
3580
3664
  return { recording, start, stop };
3581
3665
  }
3582
3666
 
3583
- export { DEFAULT_SUPERLINK_ENDPOINT, SitePongContext, SitePongErrorBoundary, SitePongProvider, SuperLinkClient, TracePropagator, addBreadcrumb, areFlagsReady, captureError, captureMessage, captureWebDeepLink, clearAnonymousId, clearUser, sitepong as client, completeFromScan, createTraceContext, cronCheckin, cronStart, cronWrap, dbTrack, dbTrackSync, 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, useAddBreadcrumb, useAllFlags, useCaptureException, useCaptureMessage, useErrorCapture, useExperiment, useFeatureFlag, useFeatureFlagPayload, useFraudCheck, useGroup, useIdentify, usePerformanceTransaction, useReplay, useSetUser, useSitePong, useTrack, useTrackPageView, useVisitorId, useWebVitals, waitForFlags, writeClipboardToken };
3667
+ export { DEFAULT_SUPERLINK_ENDPOINT, SitePongContext, SitePongErrorBoundary, SitePongProvider, SuperLinkClient, TracePropagator, addBreadcrumb, areFlagsReady, captureError, captureMessage, captureWebDeepLink, clearAnonymousId, clearUser, sitepong as client, completeFromScan, createTraceContext, cronCheckin, cronStart, cronWrap, dbTrack, dbTrackSync, 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, useAddBreadcrumb, useAllFlags, useCaptureException, useCaptureMessage, useErrorCapture, useExperiment, useFeatureFlag, useFeatureFlagPayload, useFraudCheck, useGroup, useIdentify, usePerformanceTransaction, useReplay, useSetUser, useSitePong, useTrack, useTrackPageView, useVisitorId, useWebVitals, waitForFlags, writeClipboardToken };
3584
3668
  //# sourceMappingURL=index.mjs.map
3585
3669
  //# sourceMappingURL=index.mjs.map