feat(frontend): privacy-reviewed source-to-fee product events (Phase 0 S1) #1202
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
code/cl8y-dex-terraclassic#1202
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary and status
Add the Phase 0 S1 first-party client funnel as one bundle: campaign capture, a working product-event opt-out, sanitized event delivery, transaction lifecycle instrumentation, and measured reconciliation coverage. Attribution is descriptive; the indexer remains the fee authority.
Investigated 2026-10-04 against
mainat3f9310652ac83818749f5d32c4e32057b08817bc(also the remote main head). Not implemented; keep this issue open. The body consolidates the engineering report and subsequent decisions in the existing comments. Historical draft comments are background; this body is the implementation contract.Privacy readiness remains on hold. The recorded S1 decision is opt-out required; it is no longer an unanswered decision and needs no replacement decision card. That decision alone does not release the remaining privacy gates. Legal #35 owns the dedicated Notice and footer links. On 2026-10-04,
GET https://terms.cl8y.com/privacyreturned HTTP 200 with titleCL8Y Legal — Terms & Conditions, rather than an identifiable Privacy Notice. A 200, a completed decision card, or T&Cs acceptance is not evidence of the required Notice. Do not mark this issue ready or activate production collection until the gates below are verified.Current codebase
frontend-dappis a React 19/Vite 7 SPA with TanStack Query, Zustand, and cosmes wallets.main.tsx,App.tsx,package.json, andindex.htmlcontain no product-analytics initialization/SDK. There is no campaign/UTM capture,cl8y_intentpersistence, S1 opt-out control, analytics endpoint configuration, or #1202 verifier in the checked-in code.SwapPage.tsxandCreatePairPage.tsxreplace search parameters with canonical swap/pair keys. Incoming UTMs disappear unless captured before route mount/canonicalization./swapis an alias that redirects to/; capture must also precede that redirect.useWallet.tsowns explicit connection, reconnect, simulated connection, and disconnect. Existing wallet session persistence and legal clickwrap are not product-event permission.useTerraBroadcastMutation.tswraps execution throughterraBroadcastScope.ts.terraBroadcast.tsreportssigning,broadcasting,confirming, andrecovering. Split signing and atomic wallet paths differ; abroadcastingcallback can occur before a hash exists. Poll/recovery checks the chain response code before returning a successful hash. Nested allowance/economic broadcasts can occur inside one mutation; generic mutation success is insufficient to classify every underlying action.ShareLinkButton.tsx/sharePageLink.tssupport Web Share, cancellation, clipboard fallback, and copy failure. Canonical shares drop campaigns; share payloads may contain a trader address or exact swap amount, so do not serialize their text/URL into analytics.viteCsp.tsrestrictsconnect-srcto self plus configured chain/indexer, WalletConnect, and Legal origins. No analytics-specific destination exists. Development CSP is broader and cannot prove production privacy behavior.protocol_fee_eventscontains chain-derived fee truth. There are currently sevenFeeSourcevalues:swap_amm,book_take,limit_place,wrap,unwrap,ust1_mint,ust1_redeem. #1269 widened uniqueness to(tx_hash, source, pair_id, ordinal)for pair rows and partial(tx_hash, source, ordinal)for NULL-pair rows. One tx can have multiple legitimate fee rows./api/v1/protocol/feesand/fees/dailyexpose aggregates, not a client attribution or by-tx receipt service.Why this implementation is needed
Current landing links cannot survive canonicalization into a joinable client success receipt. Fee aggregates alone cannot describe the acquisition funnel or campaign coverage, and existing wallet/broadcast state has no S1 event transport. Implementing isolated page beacons without opt-out, capture ordering, and confirmed transaction semantics would produce incomplete or misleading attribution.
The marketing S1 specification and operating-system event contract now exist. The earlier comment saying the instrumentation/exclusions files were missing is stale. They describe the campaign taxonomy and coverage target; they do not prove that client collection or a collector has shipped.
Duplicate/implementation check and bundle boundaries
Searches with
fjincluded open and closed issues/PRs forsource-to-fee,campaign_id, analytics, telemetry, product events, and opt-out. No second issue owning the S1 client bundle or matching implementation PR was found. Source inspection and repository history confirm the client behavior above is absent.https://terms.cl8y.com/privacyand shared footer links. Depend on that work; do not author a second policy here.Keep campaign capture, S1 opt-out, schema/transport, lifecycle hooks, and their tests in this single issue. A marketing warehouse, attribution dashboard, collector deployment, new fee parsers, or wallet-person graph is outside this bundle. A functioning approved first-party receiver is an activation dependency, not a reason to add another service to the DEX indexer.
Constraints and guardrails
*/https:for analytics.FeeSource, fee schema/API, transaction economics, or exact-fee calculations. Reconcile privately/offline to existing chain/indexer records; retain multiple fee rows per transaction without multiplying them by duplicate client receipts/touchpoints. No public campaign→tx→wallet endpoint, causal ROI claim, reward, credit, or transaction authorization from client events.Relevant files
frontend-dapp/src/main.tsx,src/App.tsx,src/components/common/Layout.tsx; S1 settings/control integrated with existing UIfrontend-dapp/src/pages/SwapPage.tsx,src/pages/CreatePairPage.tsx,src/components/common/SwapAliasRedirect.tsx,src/utils/swapQueryParams.tsfrontend-dapp/src/hooks/useWallet.ts,src/components/wallet/WalletModal.tsx,src/services/terraclassic/wallet.tsfrontend-dapp/src/hooks/useTerraBroadcastMutation.ts,src/services/terraclassic/terraBroadcast.ts,terraBroadcastScope.ts,terraTxRecoveryPoll.tsfrontend-dapp/src/pages/{SwapPage,TradePage,LimitOrdersPage,WrapPage,Ust1Page,CreateTokenPage,CreatePairPage}.tsx,src/components/trade/{TradeMarketOrderPanel,TradeOrderTicket}.tsxfrontend-dapp/src/services/indexer/client.ts,src/components/ui/ShareLinkButton.tsx,src/utils/sharePageLink.tsfrontend-dapp/viteCsp.ts,.env.example,src/vite-env.d.ts,index.html,src/components/legal/LegalFooterNotice.tsx(coordinate Notice ownership with Legal #35)indexer/src/indexer/protocol_fees.rs,indexer/src/api/protocol_fees.rs,indexer/src/db/queries/protocol_fees.rs,indexer/migrations/20260916120001_protocol_fee_events_pair_id.sqluseWallet,useTerraBroadcastMutation, broadcast/recovery, query/share,viteCsptests;frontend-dapp/e2e/,playwright.config.ts,Makefile,docs/frontend.md,docs/testing.mdExpected new modules: a small typed S1 capture/schema/permission/transport service with focused unit tests, one opt-out UI, a browser integration spec,
docs/qa/issue-1202/README.md, andmake verify-issue-1202. These paths/target are proposed, not existing implementation.Recommended solution direction
utm_campaignas canonicalcampaign_id; validate the marketing taxonomy/source/medium/intent allowlists, cap all fields, and define handling of duplicate/conflicting parameters. Store only validated first/last touch; do not keep arbitrary query data. Direct navigation must not silently erase a valid prior touch.trackadapter with a dark-by-default enable flag, fixed approved endpoint, bounded delivery, and explicit finite caps documented with tests. Fail closed on invalid configuration. Quote debounce/re-renders, StrictMode, recovery/retries, and repeated callbacks must not generate duplicate logical successes.qualified_page_viewquote_requestedwallet_connect_started/wallet_connect_succeededtx_sign_promptedtx_broadcast/tx_succeededrecoveringalone does not prove success. Success requires confirmed chain code 0.tx_failedshare_started/share_completed$0or fake fee receipts. Collector/warehouse construction remains outside this issue.Acceptance criteria
/,/swap,/createcanonicalization, navigation, permitted reload, connect and transaction completion; expiry is ≤30d. Invalid/absent campaigns have documented behavior.tx_succeeded.txhashmatching the indexer's canonical success and positive-fee row(s), without duplicate USD attribution. Stubbed hashes alone cannot satisfy this criterion; mainnet spending is not required.distinct eligible successful economic trades with a joinable S1 success receipt / independently verified eligible successful economic trades on instrumented surfaces, with numerator, denominator, window, surface/chain, exclusion version, ingest lag, and suppression/missing-receipt counts. Establish the 14-day dual-logging baseline described by the S1 plan after permitted activation. Never derive the denominator solely from received client events, count fee rows as trades, include auxiliary approvals, or silently drop missing events. Explicitly report opted-out traffic as unobserved/excluded; no claim of global retail coverage. Zero denominator is N/A, not 100%; pending baseline/receiver evidence keeps this AC open.Test plan — functional and failure paths
/,/swap,/create, and each other scoped route with valid params; alias/direct/SPA/reload/back navigationTest plan — attack, hack and abuse vectors
$0; only received successes form denominatorVerification criteria
make verify-issue-1202entrypoint with explicit prerequisite failures. No existing verifier currently proves S1. The issue/PR must map each AC to actual evidence, not just source text checks.make lint-frontend,make test-frontend,make build-frontend, and regressionsmake verify-issue-711,make verify-issue-713,make verify-issue-715,make verify-issue-695. Extend existing wallet/broadcast/recovery/share/CSP tests where the hooks change. Use the repo Node 24 wrapper.make has-localterra;make setup-cloud-localterraif absent), start Vite withmake dev, and use the controlled wallet/test receiver. Do not report “no chain in agent VM” without provisioning. Record matching actual confirmed hash/fee-row counts and sanitized receipts privately; do not publish campaign-linked wallet histories in issue evidence.docs/qa/issue-1202/README.md. Verify the diff introduces no fee-source/API/schema changes, no canonical-share regression, and no production analytics activation while gates are unresolved. Close this issue only when all applicable acceptance evidence is complete.Summary
Marketing cannot measure source → fee. The DEX SPA (
frontend-dappon dex.cl8y.com) has no PostHog, gtag, Plausible, or other product-analytics SDK. There is no UTM /campaign_id/cl8y_intentpersistence. Swap and Create Pair replace the query string with a canonical set after land, so inbound campaign params are wiped unless captured first.Add privacy-reviewed first-party product events so a
campaign_idcan survive from landing throughtx_succeeded, joinable to indexer fee rows viatxhash. Attribution is descriptive only — not causal ROI. The indexer remains the sole economic authority for fees. Do not changeFeeSource. Pair-creation fee indexing stays a separate ticket.Related spec lives in
PlasticDigits/cl8y-marketing(strategy/operating-system.mdproduct event contract; Phase 0 item 6 instrategy/90-day-plan.md). There is nostrategy/source-to-fee-instrumentation.mdorwallet-exclusions.mdin-tree yet.Current codebase
Architecture
frontend-dapp— React 19 + Vite 7 + TanStack Query + Zustand + cosmes wallets.indexer— Rust Axum/SQLx; economic authority for fees.index.html.connect-srcis allowlisted (LCD/RPC/indexer/WalletConnect/Legal). Third-party analytics hosts are blocked unless CSP is updated (viteCsp.ts).Surfaces in scope
/(/swapalias)SwapPage.tsx/trade,/trade/:pairAddr,/limitsTradePage.tsx,LimitOrdersPage.tsx/wrapWrapPage.tsx/ust1Ust1Page.tsx/token/createCreateTokenPage.tsx/createCreatePairPage.tsxWrap / UST1 / create-token nav items appear when the corresponding env addresses are set.
UTM / campaign
Grep finds no
utm_,campaign_id, orcl8y_intent.SwapPageandCreatePairPagecallsetSearchParams(..., { replace: true })with canonical keys only (from/to/amount or pair tokens). Inbound UTMs are stripped after first sync unless captured on land first.Wallet, quotes, txs, share
WalletModal→useWalletStore.connect→connectTerraWallet. Persistence keyscl8y_wallet_connection,cl8y_dev_sim.route/solveon Swap — naturalquote_requestedhook.terraBroadcast.tsphasessigning→broadcasting→confirming(+recovering).useTerraBroadcastMutationexposesphase+pendingTxHash; success data is typically the tx hash string. Maps totx_sign_prompted/tx_broadcast/tx_succeeded/tx_failed.ShareLinkButton+shareOrCopyPageLink(Web Share → clipboard) on Swap, Trader, Portfolio. Shared URLs are canonical and campaign-free today.Indexer join key (do not change FeeSource)
protocol_fee_events.tx_hashwithUNIQUE (tx_hash, source, ordinal). Sources today:swap_amm,book_take,limit_place,wrap,unwrap,ust1_mint,ust1_redeem. Public API is aggregate (GET /api/v1/protocol/fees); there is no by-txhash HTTP API. Reconciliation is offline/SQL or a future marketing-core ingest.Feature flags
No LaunchDarkly/Unleash. Behavior is
VITE_*. There is noVITE_ANALYTICS_ENDPOINTor analytics kill-switch yet. Simulated Wallet exists only inVITE_DEV_MODEand must not hit a production sink.Why a new implementation is needed
Phase 0 marketing cannot claim what acquires fee-paying flow. Without client events + durable campaign params, landing traffic cannot be joined to
protocol_fee_eventsontxhash. Indexer aggregates cannot answer “which campaign”. Third-party pixels are the wrong default: production CSP blocks them, and raw wallets must not leave the first party.Capture must run before Swap/Create Pair URL canonicalization, or campaign params are lost on the primary trade landing path.
Constraints and guardrails
FeeSourceor put exact fees in analytics.actor_keywith offline salt.cl8y-marketing-coreor a minimal Coolify collector). A vendor is allowed only if already privacy-reviewed and CSP/script allowlisted. None is in-tree today.FeeSource/ pair_creation (separate ticket), marketing Postgres schema in this repo, incrementality experiments, Telegram/X ↔ wallet joins, paid media pixels.cl8y_intent.wallet-exclusionsapplies on the reporting side, not in the client. Do not invent exclusion lists in the SPA.VITE_DEV_MODEmust not emit to the production sink.Relevant files
frontend-dapp/src/main.tsx,App.tsx,components/common/navItems.tsfrontend-dapp/viteCsp.ts,index.html,.env.example,package.jsonfrontend-dapp/src/pages/SwapPage.tsx,utils/swapQueryParams.ts,pages/CreatePairPage.tsxfrontend-dapp/src/hooks/useWallet.ts,components/wallet/WalletModal.tsxfrontend-dapp/src/hooks/useTerraBroadcastMutation.ts,services/terraclassic/terraBroadcast.tsfrontend-dapp/src/services/indexer/client.ts, Swap quote effectsfrontend-dapp/src/components/ui/ShareLinkButton.tsx,utils/sharePageLink.tspages/TradePage.tsx,WrapPage.tsx,Ust1Page.tsx,CreateTokenPage.tsx,components/trade/TradeMarketOrderPanel.tsx,TradeOrderTicket.tsxindexer/src/indexer/protocol_fees.rs,indexer/migrations/20260821120000_protocol_fees.sql,indexer/src/api/protocol_fees.rscl8y-marketing/strategy/operating-system.md,90-day-plan.md,fee-growth-model.md,technical-architecture.md,founder-decisions.mdRecommended direction
setSearchParams): parseutm_*+cl8y_intent(+ agreed campaign taxonomy keys); persist first-touch and last-touch inlocalStoragewith ≤30d TTL.track(event, props)module, gated by env (VITE_ANALYTICS_ENDPOINTor equivalent kill-switch) so it can ship dark.qualified_page_viewquote_requested(bucketed amounts)wallet_connect_started/wallet_connect_succeededuseTerraBroadcastMutation/ phase callbacks →tx_sign_prompted/tx_broadcast/tx_succeeded/tx_failedwithtxhash, action, pair/route, first+lastcampaign_idShareLinkButton→share_started/share_completed(if share UI exists on that surface; else defer that event only)connect-src. Do not add gtag/PostHog unless separately approved.actor_keyin local storage; never send raw wallet to third parties.protocol_fee_eventsontxhash.source-to-fee-instrumentation.mdin marketing if still missing; do not block the client on that filename.Acceptance criteria
tx_succeeded)./or/create.qualified_page_view,quote_requested,wallet_connect_started/wallet_connect_succeeded,tx_sign_prompted,tx_broadcast/tx_succeeded/tx_failed, and share events where share UI exists.tx_broadcast/tx_succeededincludetxhash, action, pair/route, first+lastcampaign_id.tx_succeeded.txhashmatching an indexerprotocol_fee_events.tx_hash(or equivalent success/fee row).VITE_DEV_MODE/ Simulated Wallet does not hit prod sink.FeeSourceunchanged.Test plan: all paths
cl8y_intenton/: first-touch stored; Swap canonical URL rewrite does not drop stored campaign;qualified_page_viewfires once per qualified land.quote_requestedon swap quote (success, empty route, LCD error) with bucketed amount.txhash.tx_failedwith normalized stage; no fake success.protocol_fee_events.Test plan: attack, hack, and abuse vectors
campaign_id/ UTM (XSS, huge strings, unknown keys)tx_succeededwithout chain confirmterra1/0xaddress appears in analytics payloadVerification criteria
useTerraBroadcastMutationphase mapping.tx_succeededpayload still has first-touch campaign id after URL rewrite.make/ existing frontend verify targets still pass; indexer tests untouched.Intake request — DEX client source-to-fee instrumentation (Phase 0 S1) From: Mato feat(frontend): privacy-reviewed source-to-fee product events (Phase 0 S1)+1; S1 also requires ≥80% coverage of non-excluded successful trades on instrumented surfaces (join tx_succeeded.txhash to indexer fee rows).
Privacy DoR (enqueue / ship hold) — Privacy policy alignment
Not legal advice. Gap IDs: G1 (block), G3 (high). Forwarded via Market sensor to Ops Sensor as enqueue hold.
Must be true before enqueue claims “ready” / before ship:
Nice-to-have (not ship-blockers alone): align with bridge storage-consent schema (cl8y-bridge-monorepo#165) if S1 shares the same consent record; document retention/deletion owner.
Not blocked on PlasticDigits/cl8y-agent-control#65 (that issue is work-queue ranking research, not privacy).
DRAFT — DoR items 2 / 3 / 6 (schema · destinations · redaction)
Status: DRAFT — not ship approval / not legal advice. For founder/counsel + eng review. Full stub kept by Privacy policy alignment; Market sensor may send event-name deltas after field inventory.
2 — Event schema (field classes)
Aligned with
source-to-fee-instrumentation(names provisional until eng finalizes):qualified_page_viewwallet_connect_started/succeededtx_broadcast/tx_succeeded/tx_failedactor_key_pseudo= first-party irreversible / session key — not the on-chain address in cleartext to third parties. Campaign persistence: first-party ≤30d TTL (plan rec); disclose when Privacy Notice (G1) ships.3 — Destinations
Any proposed 3P hop for S1 payloads → stop for founder/counsel + Notice update before enqueue.
6 — Redaction tests (sketches)
actor_key_pseudo≠ raw address.tx_succeededcarries campaign_id + txhash for indexer join without wallet on marketing hop.Still founder-gated: G1 Privacy Notice; DoR 4 opt-out decision.
DRAFT delta — DoR 2 fuller S1 table (Market sensor inventory)
Status: DRAFT — not ship approval / not legal advice. Eng may trim event names. Supersedes the shorter event list in the prior DoR 2/3/6 draft comment for schema rows only; destinations + redaction sketches still apply.
Events (source-to-fee + OS; don’t invent beyond this)
qualified_page_viewquote_requestedwallet_connect_startedwallet_connect_succeededtx_sign_promptedtx_broadcast/tx_succeededtx_failedshare_started/share_completedCross-cut:
utm_*,cl8y_intent,campaign_id≤30d,session_id,actor_key_pseudo. Amounts bucketed. No raw wallets to third parties.Destination preference: first-party
VITE_ANALYTICS_ENDPOINT/ Coolify Postgres; indexer is fee-truth join only.DoR 4 (opt-out): still OPEN — founder skipped opt-out widget; do not assume an answer.
DRAFT delta — fuller S1 event set (Market sensor)
Status: DRAFT — complements comment 44486; not ship approval. Canonical:
PlasticDigits/cl8y-marketing/strategy/source-to-fee-instrumentation.md.Also include (provisional until eng finalizes):
quote_requestedtx_sign_promptedshare_started/share_completedSame rules as 44486: amounts bucketed; no raw wallets to 3P;
actor_key_pseudofirst-party only; 1P sink preferred; indexer = txhash fee-truth join only.Still open: G1 Privacy Notice; DoR 4 opt-out (founder skipped widget — no assumed answer).
HOLD: privacy DoR / legal#35 — Market+ops overnight hold
Overnight privacy/#1202 security note (2026-09-06)
Private dual-pass audit filed under
ops-worker/cl8y-security-audits→2026-09-06/cl8y-dex-terraclassic-privacy-1202/(ops-sensor mirror of kimi-k3-max + grok-4.6-high).HOLD respected — no implement, no
ready. Top process High: do not ship client product events until destinations + redaction DoR signed (campaign_id/txhash linkability, sink allowlist, no secrets in payloads). Formal kimi security pass when HOLD lifts.S1 opt-out operator card on cl8y-pm
/inboxwas failed (“Could not understand the issue”). That was this engineering ticket, not a missing DEX AC.A replacement phone card is queued: pick required (opt-out before product events go live) or not_required (events may go live without an opt-out widget). Completing that card is the unlock; it is not implement work on this issue.
Operator S1 decision on cl8y-pm /inbox: required. Ship an opt-out control before DEX product events go live. This is the unlock, not implement work on this ticket.