/** * Guest-side telemetry — runs inside sandboxed product iframes. * * Reads `window.__HOST_TRACE_CONTEXT__` (injected by the host at mount time) * and posts Segment-shaped analytics events + performance timing events back * to the host via postMessage. The host's analytics router then forwards * events to per-product backend adapters. * * When `sampled` is false (or no trace context is present), all calls are * no-ops — zero overhead for unsampled sessions. * * @example * ```ts * import { track, identify, recordSpan } from "@polkadot-apps/product-sdk/guest/telemetry"; * * identify("5F3sa2TJ..."); * track("tx_submitted", { chain: "polkadot", amount: 10 }); * * const start = performance.now(); * await doExpensiveWork(); * recordSpan("expensive_work", start, performance.now() - start); * ``` */ /** Shape of window.__HOST_TRACE_CONTEXT__ injected by the host. */ interface HostTraceContext { readonly traceId: string; readonly parentSpanId: string; readonly sampled: boolean; readonly productId?: string; } declare global { interface Window { __HOST_TRACE_CONTEXT__?: HostTraceContext; } } /** * Record a user action (Segment `track` call). * * No-op when the session is not sampled. * * @param event - Action name (e.g. "wallet_connected", "tx_submitted"). * @param properties - Arbitrary properties describing the action. */ export declare function track(event: string, properties?: Record): void; /** * Associate a user identity (Segment `identify` call). * * Products should only pass the user's public wallet address or an * anonymous ID — never PII like email or real name. * * No-op when the session is not sampled. * * @param userId - User identifier (wallet address or anonymous ID). * @param traits - Traits describing the user. */ export declare function identify(userId: string, traits?: Record): void; /** * Record a page/screen view (Segment `page` call). * * No-op when the session is not sampled. * * @param name - Page or screen name. * @param properties - Additional page properties. */ export declare function page(name: string, properties?: Record): void; /** * Record a performance timing span (bridges to the host's OTel trace tree). * * Use this to wrap expensive operations so they appear in the host's * distributed traces alongside Rust-side spans. * * No-op when the session is not sampled. * * @param name - Span name (e.g. "product.rpc_call", "product.render"). * @param startMs - Start time from `performance.now()`. * @param durationMs - Duration in milliseconds. * @param attributes - Key-value attributes for the span. * * @example * ```ts * const t0 = performance.now(); * const result = await api.query(); * recordSpan("api_query", t0, performance.now() - t0, { endpoint: "/balance" }); * ``` */ export declare function recordSpan(name: string, startMs: number, durationMs: number, attributes?: Record): void; export {}; //# sourceMappingURL=telemetry.d.ts.map