DatalyrSDK 2.2.0, which posts events to
https://ingest.datalyr.com/track. For a first install, start with
Install in a mobile app.
Requirements
Install
- Swift Package Manager
- CocoaPods
In Xcode, open File → Add Package Dependencies. Add this URL.Add the
DatalyrSDK product to your app target.Initialize
Callconfigure once, at app launch. Generate a write key under Settings → API.
initialize(config:) throws DatalyrError.invalidConfiguration on an empty key. The SDK buffers
up to 50 events, 50 identity calls, and 50 deep links sent before initialization.
The SDK ignores a second configure() or initialize(config:) call. The first configuration
stays in effect. With debug: true, the SDK logs SDK already initialized (or initializing).
What the SDK tracks without your code
The SDK never prompts for App Tracking Transparency on its own, and it never captures the
launch URL. Call
handleDeepLink(_:) yourself.
Events the SDK sends for you
These names are reserved. Never send one throughtrack().
screen() sends an event named pageview, not screen. Filter on pageview in
Events.[A-Za-z0-9_-.$] up to 100 characters. Whitespace runs collapse to _,
so track("Order Completed") arrives as Order_Completed.
Track an event
Track a screen
- SwiftUI
- UIKit
Identity
Callidentify() once per signed-in person, not on every screen. A call with a different
userId runs reset() first (unless the current ID is provisional, see
Pre-login IDs), which rotates the anonymous ID and erases attribution, the
journey, and the SKAdNetwork high-water value.
$identify event.
Pre-login IDs
Identity on the wire
This SDK sends no
distinct_id and no top-level visitor_id. To pass identity to
RevenueCat or Superwall, use getRevenueCatAttributes() or getSuperwallAttributes().
Both set datalyr_id to the anonymous ID, the same anonymousId value that is on the wire.
reset() rotates the anonymous ID and session, and clears attribution, journey, and
SKAdNetwork state.
Revenue
trackPurchase, trackSubscription, trackAddToCart, trackInitiateCheckout,
trackCompleteRegistration, and trackLead update the SKAdNetwork conversion value.
trackViewContent, trackSearch, and trackAddPaymentInfo do not.
Attribution
Pass every incoming link to the SDK.
Each
utm_* value is mirrored to campaign_source, campaign_medium, campaign_name,
campaign_term, and campaign_content. Since 2.1.9 the whole attribution record rides on
every event. Properties you pass to track() win on a name collision.
Apple Search Ads
The SDK reads AdServices on iOS 14.3 and later, and adds these 12 properties to every event:asa_attribution, asa_org_id, asa_org_name, asa_campaign_id,
asa_campaign_name, asa_adgroup_id, asa_adgroup_name, asa_conversion_type,
asa_click_date, asa_keyword, asa_keyword_id, asa_region.
SKAdNetwork
initialize() registers for attribution. The API depends on the OS version.
Two optional
Info.plist keys control AdAttributionKit postback copies.
Conversion values only ever increase. The SDK stores a high-water fine value and sends an
update only for a strictly higher fine value, or an equal fine value with a higher coarse
value.
Set
skadTemplate at initialization to use conversion values. Without it,
getConversionValue(for:) returns nil, and trackWithSKAdNetwork() logs a warning
once per process and sends no postback update. Pass gaming or subscription for those
templates. Any other string selects the ecommerce template.Journey
App Tracking Transparency
Each call sends
$att_status and refreshes idfa, att_status, and
advertiser_tracking_enabled on later events. The SDK reads advertiser data at
initialization and each time the app becomes active.
The ATT status decides these:
ATT is not an analytics consent system. Your app owns consent and the App Store privacy
disclosure.
Privacy manifest
RevenueCat and Superwall
reset().
From 2.1.19, register once:
See
RevenueCat and Superwall.
Bind a provider identity
Complete method list
Every method below is onDatalyrSDK.shared unless marked static. Each datalyr* free
function mirrors its instance method. The free functions datalyrTrack and
datalyrTrackWithSKAdNetwork name the second parameter properties:, not eventData:.
View.datalyrScreen(_:properties:), View.datalyrTrack(_:properties:), and
UIViewController.datalyrTrackScreenView() wrap the same calls.
Configuration
AutoEventConfig
Note the unit split here:
sessionTimeoutMs is milliseconds, and the other three interval
options are seconds. sessionTimeoutMs sets when session_end fires. Session ID rotation
is fixed at 30 minutes.
trackScreenViews: false stops screen() from sending. No pageview event goes out, and
the internal screen counters do not change.
Options with no effect
Remove these three from your configuration.DatalyrConfig.respectDoNotTrackAutoEventConfig.trackAppUpdates. CalltrackAppUpdate()yourself.AutoEventConfig.trackPerformance
Call these instead
Limits
How failed requests behave
Delegate callbacks
Storage
The SDK keeps its state inUserDefaults under these keys.
The SDK writes nothing to the Keychain.
What changed in 2.1.19
What changed in 2.1.18
What changed in 2.1.16
Verify the install
- Run the app on a clean simulator or a fresh install.
- Open Events in DATALYR.
- Confirm
app_installandsession_startarrive within 30 seconds.
getStatus() and read initialized and queueStats. A queue
that grows without draining means the API key is wrong. See
No events.