iOS 15+ / macOS 12+, no third-party dependencies. swift test runs on a Mac.
import Lucida
var cfg = LucidaConfig(apiKey: "lc_pk_...", apiHost: URL(string: "https://ingest.example.com")!)
cfg.appVersion = "1.4.0"
let lucida = LucidaClient(config: cfg)
lucida.identify("user-42", set: ["plan": "pro"])
lucida.capture("checkout_started", ["items": 3])
lucida.screen("Settings") // swizzle-free; call from viewDidAppear
if lucida.isFeatureEnabled("new-onboarding") { ... }SwiftUI: .lucidaScreen("Home", client: lucida) records $screen on appear.
- Capture:
POST /v1/batch({api_key, batch, sent_at}), 20 events / 5 s, gzip over 1 KB (Content-Encoding: gzip), retry with jittered exponential backoff (network, 408, 429, 5xx; other 4xx drop the batch). The queue is persisted (one JSON file under Application Support) and is only cleared on gateway acknowledgement, so offline periods and crashes lose nothing. Delivery is at-least-once; eventuuid(UUIDv7) dedupes server-side. - Lifecycle (no swizzling, NotificationCenter):
$app_opened,$app_backgrounded(also flushes),$app_installed,$app_updated(needsappVersion). - Identity:
identify,alias,reset,register/registerOnce/unregister,group, sessions (rotate after 30 min idle or 24 h). - Consent:
consentMode = .optInwrites nothing to storage and sends nothing untiloptIn()/setConsent(...);queueBeforeConsentholds events in memory instead of dropping them. Replay additionally needs thereplaycategory. - Flags:
POST /v1/flagsplus on-device evaluation (localFlags) that passes all oftestdata/flags(swift testloads the files by relative path).$feature_flag_called/$exposurefire on first read. - Wireframe replay (opt in:
cfg.replay.enabled = true): everysnapshotInterval(5 s) the key window's view hierarchy becomes an rrweb Meta + FullSnapshot (positioneddivs) posted to/v1/replayas{api_key, session_id, window_id, seq, events}, plus anavigationcustom event (app://<screen>) on screen change. Unchanged hierarchies are skipped. Privacy: text is masked (*) by default, text/secure inputs never include text,view.lucidaMarkSensitive()drops a view's text even whenmaskText = false.
cfg.beforeSend = [hook, ...]: ordered(WireEvent) throws -> WireEvent?; return a changed event to amend,nilto drop. A hook that throws is logged (whendebug) and skipped: the event continues as it was before that hook.sampleHook(0.1)keeps ~10% and adds$sample_rate.cfg.personProfiles:.always(default),.identifiedOnly(events carry$process_person_profile: falseuntil identify, alias, group or a person-property write; persisted, cleared byreset()),.never(identify/alias/setPersonProperties are no-ops with a debug warning).- Flags:
cfg.bootstrap = Bootstrap(distinctId:, isIdentified:, flags:, payloads:);cfg.flagOptions(sendFeatureFlagEvent,preload,evaluationContexts);onFlags;setPersonPropertiesForFlags(_:reload:),setGroupPropertiesForFlags, reset variants. - Queue/network:
flushAt,flushInterval,maxQueueSize,maxBatchSize,maxRetries,retryBaseDelay,URLSessionTransport(timeout:),dataMode = .wifi(+networkPolicy, default NWPathMonitor),sessionIdleTimeout/sessionMaxAge,disableGeoip,disabled,client.debug(true),queueCipher(aQueueCipherport that encrypts only the persisted queue),appGroupIdentifier(App Group file store so extensions share identity and the queue; set before assigning a customstore). - Person helpers:
setPersonProperties,capture(_:_:set:setOnce:),anonymousId,reuseAnonymousId,anonymousIdProvider,isOptedOut. client.openURL(url, referrer:)records$deep_link_opened(url, query, referrer); call it from your URL-open handlers.- Tracing headers:
cfg.tracingHeaders = ["api.example.com", ".corp.io"], thenclient.tracedRequest(request)addsX-Lucida-Distinct-Id/X-Lucida-Session-Id(never to the Lucida host; analytics consent required). - Autocapture (
cfg.autocapture.enabled = true):$autocapturetaps ($event_typetouch, plus change for switches/segments/steppers) from a non-intrusive tap recognizer on the key window,ignoreLabels,maxElements,propsAllowList,rageTap($rageclick).view.lucidaNoCapture()excludes a view and its subviews. Text-field values are never read. - Replay:
maskAllTextInputs(default on),maskAllImages,maskSandboxedViews(WKWebView, MKMapView: frame only),sampleRate(per session),throttleDelay,view.lucidaUnmask(); secure fields andlucidaMarkSensitive()views are never readable.client.startReplay()/stopReplay()/isReplayActive.
Every remote value below arrives in GET /v1/config and only ever adds masking to what the app configured.
- Masked screens (P-M17):
cfg.replay.maskScreens = ["Checkout", "Pay*"]plus the project'sreplay_mask_screens(case-insensitive,*= any run of characters, whole screen name). On a matching screen every text, input value and image is masked whatevermaskText/maskAllTextInputs/maskAllImagesorlucidaUnmask()say; screenshots paint them all over. - Text patterns (P-M46):
cfg.replay.maskTextPatterns = [#"\d{4,}"#]plusreplay_mask_text_patterns(regular expressions; one that does not compile is ignored). Matches in any text the wireframe would show unmasked become*(whitespace kept); in screenshot mode a view whose text matches is painted over. $dead_swipe(P-M46,cfg.replay.captureDeadSwipes, default on, needscaptureTouches): a pan of 48 pt or more after which the view hierarchy is unchanged ~700 ms later. Properties:$screen_name,$swipe_direction(left|right|up|down),$swipe_distance(pt). Never text or view content; at most one per 2 s.- Controlled exposure (P-L12): when the project sends
replay_exposure_fieldsandreplay_exposure_key, a listed field's value is RSA-OAEP-SHA256 encrypted on device and sent as$sensitive_capture($exposure_field,$exposure_kid,$exposure_ciphertext,$screen_name,$exposure_truncatedwhen cut to 190 bytes). Only an audited reveal on the server can read it. Explicit:client.captureSensitive("card_number", value: v). Automatic: a non-secureUITextField/UITextViewwhoseaccessibilityIdentifieris listed is read during the snapshot walk (it stays masked in the replay). Secure fields are never captured; identical values are sent once per session; nothing is persisted.
SwiftUI in replay: hosting views are walked through their accessibility elements (labels only, never values), so SwiftUI
text appears in wireframes starred like UIKit text; the hosting view itself is a masked placeholder (data-lc-mask) and is
painted over in screenshot mode unless .lucidaUnmask() covers it.
Not built: push registration (needs a scope decision), queue encryption adapter (only the port).
The UIKit adapters type-check for the iOS simulator SDK but are not exercised by swift test.
Kinds modal, banner, announcement, slideout, tour, carousel (Back / Next with a slide pager) and, with an
anchoring presenter, tooltip / hotspot. A step's native_id anchors it to a native view by its accessibilityIdentifier (UIKitGuidePresenter implements AnchoredGuidePresenter): the bubble is drawn next
to the view and follows it on scroll and relayout; a hotspot is a pulsing dot that opens the step. When the view does not
appear within wait_ms (default 3 s, max 15 s) the SDK sends $guide_target_missing {step_id, selector} and shows the step
unanchored; a view gone for 2 s closes the step. The resolved appearance tokens (background, text, accent, radius,
font) apply, with appearance.dark.tokens when theme_mode is dark, or auto and the device is dark.
config.fallbacks = ["new_nav": .bool(false)] serves that value, with reason fallback, when a flag has no value
(missing, failed load, cold start). Fallback reads emit no $feature_flag_called / $exposure.
client.flagDetails("key") returns FlagDetails (value, payload, variant, raw reason, conditionIndex, requestId,
evaluatedLocally), or nil for an unknown key without a fallback. client.onFlagsStatus { .changed/.stale/.error } reports reloads.
Product LucidaOpenFeature (depends on open-feature/swift-sdk 0.3+, Apache-2.0):
let provider = LucidaProvider(client: client)
await OpenFeatureAPI.shared.setProviderAndWait(provider: provider, initialContext: ImmutableContext(targetingKey: "u1"))
let on = OpenFeatureAPI.shared.getClient().getBooleanValue(key: "new_nav", defaultValue: false)Context attrs: groups (type -> key), groupProperties (type -> map), everything else becomes person properties.
Reads carry reason + flagMetadata (lucidaReason, conditionIndex, requestId, evaluatedLocally); track() maps to capture.
On first open $app_installed carries Apple Search Ads attribution from AdServices (iOS 14.3+): the
AAAttribution token is POSTed (text/plain, 10 s timeout, 404 retried up to 3 times) to Apple's attribution API.
Props: $install_store=app_store, $install_adservices_attribution, and when attributed $utm_source=apple_search_ads,
$utm_medium=cpc, $utm_campaign/$utm_term/$utm_content (campaign/keyword/ad group id) and $asa_* ids. If the token
or request fails the event still goes out with $install_store only. Disable with config.installAttribution = false;
swap the source with config.installAttributionSource. Opted-out users send nothing.
HTTPTransport (URLSessionTransport), KeyValueStore (FileKeyValueStore,
MemoryKeyValueStore), LucidaClock, LifecycleSource (NotificationLifecycleSource),
ViewHierarchySource (UIKitViewHierarchy), NetworkPolicy (NWPathNetworkPolicy), QueueCipher (bring your own). Tests use fakes for all of them.
Wireframes are full snapshots, not
incremental mutations; no screenshot mode; the UIKit hierarchy walker type-checks against the iOS SDK
but is not exercised by swift test; no automatic UIKit screen tracking (manual screen() only).
This repository is a read-only mirror of the Lucida monorepo (synced by a script, never edited by hand); releases and provenance attestations are built here by GitHub Actions. Issues are welcome, changes land upstream.