@formo/analytics 1.36.0 → 1.38.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.
Files changed (44) hide show
  1. package/dist/cjs/src/FormoAnalytics.d.ts +64 -0
  2. package/dist/cjs/src/FormoAnalytics.js +155 -5
  3. package/dist/cjs/src/FormoAnalyticsProvider.js +1 -0
  4. package/dist/cjs/src/evm/EvmEventTracker.d.ts +38 -10
  5. package/dist/cjs/src/evm/EvmEventTracker.js +182 -0
  6. package/dist/cjs/src/evm/EvmProviderRegistry.js +26 -4
  7. package/dist/cjs/src/evm/EvmRequestTracker.d.ts +36 -40
  8. package/dist/cjs/src/evm/EvmRequestTracker.js +216 -115
  9. package/dist/cjs/src/evm/batch.d.ts +94 -0
  10. package/dist/cjs/src/evm/batch.js +130 -0
  11. package/dist/cjs/src/provider/detection.d.ts +30 -0
  12. package/dist/cjs/src/provider/detection.js +62 -0
  13. package/dist/cjs/src/provider/index.d.ts +1 -1
  14. package/dist/cjs/src/provider/index.js +3 -1
  15. package/dist/cjs/src/types/base.d.ts +23 -0
  16. package/dist/cjs/src/types/provider.d.ts +16 -0
  17. package/dist/cjs/src/types/provider.js +17 -1
  18. package/dist/cjs/src/version.d.ts +1 -1
  19. package/dist/cjs/src/version.js +1 -1
  20. package/dist/cjs/src/wagmi/WagmiEventHandler.d.ts +87 -0
  21. package/dist/cjs/src/wagmi/WagmiEventHandler.js +536 -13
  22. package/dist/esm/src/FormoAnalytics.d.ts +64 -0
  23. package/dist/esm/src/FormoAnalytics.js +155 -5
  24. package/dist/esm/src/FormoAnalyticsProvider.js +1 -0
  25. package/dist/esm/src/evm/EvmEventTracker.d.ts +38 -10
  26. package/dist/esm/src/evm/EvmEventTracker.js +183 -1
  27. package/dist/esm/src/evm/EvmProviderRegistry.js +27 -5
  28. package/dist/esm/src/evm/EvmRequestTracker.d.ts +36 -40
  29. package/dist/esm/src/evm/EvmRequestTracker.js +215 -114
  30. package/dist/esm/src/evm/batch.d.ts +94 -0
  31. package/dist/esm/src/evm/batch.js +123 -0
  32. package/dist/esm/src/provider/detection.d.ts +30 -0
  33. package/dist/esm/src/provider/detection.js +60 -0
  34. package/dist/esm/src/provider/index.d.ts +1 -1
  35. package/dist/esm/src/provider/index.js +1 -1
  36. package/dist/esm/src/types/base.d.ts +23 -0
  37. package/dist/esm/src/types/provider.d.ts +16 -0
  38. package/dist/esm/src/types/provider.js +16 -0
  39. package/dist/esm/src/version.d.ts +1 -1
  40. package/dist/esm/src/version.js +1 -1
  41. package/dist/esm/src/wagmi/WagmiEventHandler.d.ts +87 -0
  42. package/dist/esm/src/wagmi/WagmiEventHandler.js +536 -13
  43. package/dist/index.umd.min.js +1 -1
  44. package/package.json +4 -3
@@ -5,6 +5,13 @@ import { AutocaptureEventType } from "../tracking/TrackingPolicy";
5
5
  /** What the request tracker needs from the SDK that owns it. */
6
6
  export interface EvmRequestTrackerDeps {
7
7
  isAutocaptureEnabled(eventType: AutocaptureEventType): boolean;
8
+ /**
9
+ * Hybrid-capture dedup: true when a PENDING wagmi mutation already covers
10
+ * this request, so the mutation handler owns the capture. TanStack sets a
11
+ * mutation pending BEFORE its mutationFn issues the wallet call, so a
12
+ * hook-driven request always matches; an imperative one never does.
13
+ */
14
+ shouldSkipRequestCapture?(method: string, params: unknown[]): boolean;
8
15
  signature(params: {
9
16
  status: SignatureStatus;
10
17
  chainId?: ChainID;
@@ -23,16 +30,6 @@ export interface EvmRequestTrackerDeps {
23
30
  function_args?: Record<string, unknown>;
24
31
  }, properties?: IFormoEventProperties): Promise<void>;
25
32
  }
26
- /**
27
- * Autocapture for signatures and transactions, by wrapping a provider's
28
- * `request`.
29
- *
30
- * The wrapper is deliberately thin: it observes the call the dapp was already
31
- * making and never issues one of its own. That rule is why the chain a
32
- * request ran on is read from `eth_chainId` calls the app makes, rather than
33
- * probed - an SDK-issued lookup on a serialising transport can wedge the
34
- * user's wallet, which is never an acceptable price for a label.
35
- */
36
33
  export declare class EvmRequestTracker {
37
34
  private readonly wallet;
38
35
  private readonly registry;
@@ -50,6 +47,8 @@ export declare class EvmRequestTracker {
50
47
  constructor(wallet: WalletStateStore, registry: EvmProviderRegistry, deps: EvmRequestTrackerDeps);
51
48
  /** Stop every poll in flight. Terminal, like the event queue's close(). */
52
49
  cleanup(): void;
50
+ /** Providers whose owner list includes this instance; pruned on cleanup. */
51
+ private wrappedProviders;
53
52
  /** Re-arm a poll, unless this tracker has been torn down. */
54
53
  private schedulePoll;
55
54
  /**
@@ -59,6 +58,25 @@ export declare class EvmRequestTracker {
59
58
  * would be missed for the rest of the session.
60
59
  */
61
60
  registerRequestListeners(provider: EIP1193Provider): boolean;
61
+ /** Install the wrapper function onto the provider; separated so the
62
+ * routing shim above stays small. */
63
+ private installWrappedRequest;
64
+ /**
65
+ * The wrapper body proper: everything a request observation does, run
66
+ * against THIS instance's registry, wallet state, and event queue. Kept
67
+ * as a method so a surviving wrapper installed by a previous SDK
68
+ * instance can hand calls to the current one.
69
+ */
70
+ private dispatchWrappedRequest;
71
+ /**
72
+ * Wallet attribution for request-derived events.
73
+ *
74
+ * Live per read through the registry, so a WalletConnect session names
75
+ * its actual signer ("MetaMask Wallet", "Ledger Live") - the live-test
76
+ * rows had provider_name EMPTY on every signature and transaction, which
77
+ * made per-wallet activity unanswerable in the warehouse.
78
+ */
79
+ private attributionFor;
62
80
  private buildSignatureEventPayload;
63
81
  private buildTransactionEventPayload;
64
82
  /**
@@ -68,42 +86,20 @@ export declare class EvmRequestTracker {
68
86
  /**
69
87
  * One `transaction` event per call in an EIP-5792 batch.
70
88
  *
71
- * A batch is not a transaction. It maps to several on-chain transactions,
72
- * so reporting it as one event would understate volume and make revenue and
73
- * per-contract attribution wrong for every app that adopts smart accounts.
74
- * Each call is reported on its own, carrying the batch id so the calls can
75
- * be reassembled downstream.
89
+ * The CALL is the unit of attribution: each has its own target, calldata,
90
+ * and value, and folding a batch into one event would misattribute revenue
91
+ * and per-contract activity for every app that adopts smart accounts. How
92
+ * many on-chain transactions a batch becomes depends on execution - an
93
+ * atomic batch lands as ONE transaction, a non-atomic fallback as several -
94
+ * so on-chain volume is `count(distinct transaction_hash)`, wallet actions
95
+ * `count(distinct batch_id)`, never the event count. Each call is reported
96
+ * on its own, carrying the batch id so the calls reassemble downstream.
76
97
  *
77
98
  * Status is per BATCH, because that is what `wallet_getCallsStatus` reports.
78
99
  * When it resolves, every call in the batch moves together, except where
79
100
  * per-call receipts say otherwise on a non-atomic batch.
80
101
  */
81
102
  private trackBatchedCalls;
82
- /**
83
- * How one call in a settled batch ended.
84
- *
85
- * A per-call receipt is authoritative where it exists: that is what makes a
86
- * partially reverted non-atomic batch report honestly rather than tarring
87
- * every call with the batch's worst outcome. A receipt whose own status is
88
- * unreadable falls back to the batch verdict rather than being assumed good.
89
- *
90
- * The codes are EIP-5792's: 200 confirmed, 400 failed BEFORE landing on
91
- * chain, 500 reverted, 600 partially reverted. 400 is a rejection, not a
92
- * revert - nothing was mined, so calling it reverted would misreport gas
93
- * spent and on-chain activity that never happened.
94
- *
95
- * Returns undefined when the call cannot be decided, which happens on 600
96
- * for a call the wallet gave no receipt for.
97
- */
98
- private batchCallOutcome;
99
- /**
100
- * The batch identifier from a `wallet_sendCalls` result.
101
- *
102
- * EIP-5792 settled on `{ id }`, but wallets shipped against the earlier
103
- * draft return a bare string. Both are accepted so a wallet on either
104
- * version is still grouped.
105
- */
106
- private readBatchId;
107
103
  /**
108
104
  * Resolve a batch through `wallet_getCallsStatus`.
109
105
  *