EarnedStats Docs

Install

Mobile apps

Screens, events and revenue from iOS, Android, React Native, Expo, Flutter, Capacitor and .NET apps.

An app is added like a website, with its app id in place of a domain: the iOS bundle id or the Android package name, for example com.example.app. Choose Mobile app when you add it. Each screen the app shows is counted like a page, and goals, users and revenue work the same way as on a website.

Add it to your app

Each SDK is one file with no other packages to install, except where noted. Download it, add it to your project and start it when the app launches.

Add EarnedStats.swift to your app target (it works on iPhone, iPad, Mac, Apple TV, Apple Watch and Vision Pro). Start it when the app launches, then send screens from your views.

EarnedStats.swift

App.swift
@main
struct MyApp: App {
  init() {
    EarnedStats.configure(siteId: "YOUR_SITE_ID")
  }
  var body: some Scene {
    WindowGroup {
      ContentView()
        .trackScreen("Home")
        .onOpenURL { EarnedStats.open(url: $0) }
    }
  }
}

// Anywhere: a goal
EarnedStats.track("signup", ["plan": "pro"])
Tip

Use an AI coding tool? Open the app's Setup page and choose Let my coding AI do it for a prompt with your real site id and app id.

Screens

Call screen("Home") when a screen appears. The name becomes the page path, so Home shows as /Home and settings/billing as /settings/billing. The SwiftUI modifier .trackScreen, the Flutter EarnedStatsObserver and the React Navigation and Expo Router helpers send them for you.

Goals and users

CallWhat it does
track(name, properties)A goal, with up to 10 properties. It shows on the Goals page next to your website goals.
identify(userId, email, name)Ties this install to your own user, so their visits and payments show on one profile.
open(url)Pass the deep link or universal link that opened the app: its utm_ and ref parameters credit the next screen to that campaign.
visitorIdThis install's visitor id, for crediting purchases (below).
enabledTurn sending off and on, for an analytics opt out inside the app.

Campaigns and installs

Put utm_source, utm_medium and utm_campaign on your deep links and pass the link to open(url). On Android, pass the Play Store install referrer to EarnedStats.installReferrer(referrer) once, to credit installs to the campaign that brought them.

Revenue from in-app purchases

Connect RevenueCat under Settings, Revenue, then give RevenueCat the visitor id once it is known:

Swift
EarnedStats.onVisitorId { id in
  Purchases.shared.attribution.setAttributes(["es_visitor_id": id])
}
Kotlin
EarnedStats.onVisitorId { id ->
  Purchases.sharedInstance.setAttributes(mapOf("es_visitor_id" to id))
}

Each purchase is then credited to the install, its first screen and the campaign that brought it. Payments through Stripe or another web checkout work the same way: send es_visitor_id with the checkout.

One site for the website and the app

To see a website and its app together, add the app id under Settings, General, Additional hostnames of the website's site. When the iOS and Android ids differ, add the second id to the app's site the same way.

How installs are counted

  • The SDK makes one random id the first time the app opens and keeps it inside the app. One install is one visitor for as long as the app is installed.
  • No advertising id, no device identifier and no tracking permission prompt. Nothing is shared with other apps.
  • Visits end after 30 minutes without activity; time in the foreground is counted as visit length.
  • Events made while offline are kept, up to 500, and sent when the phone is back online. Events older than 48 hours are dropped.
  • App versions show in the Browsers list (App 2.4.1), the operating system and phone or tablet in Devices, and the country from the network like on a website.
Note

App Store privacy details: declare Product Interaction and, if you call identify, User ID, as analytics data not used for tracking.