LearnMobile Setup

Mobile Setup

Send events from your iOS or Android app to Hardal with an HTTP POST to the /collect endpoint.

How mobile tracking works

Mobile apps send each event to /collect on your first-party URL with an HTTP POST request. You don't need to install an SDK.

Privacy by default

You can send mobile events without attaching a known user identity. After a user grants consent, include only the identifiers allowed by your consent rules.

Consent Signals

When to send consent and what each signal changes.

Mobile collection endpoint

POST https://analytics.yourdomain.com/collect

Use the collection URL generated for the source in Setup. Connect the tracking domain before sending requests.

HeaderRequiredValue
Content-TypeYesapplication/json
User-AgentYesApp or platform user agent, which many HTTP clients send automatically
x-hrd-session-idNoStable UUID for the current app session
x-hrd-consentNogranted or denied

Send tenantId in the top-level JSON body and sourceId in payload. Copy both UUIDs from Setup.

Create one UUID per app session and reuse it in x-hrd-session-id. If you omit it, Hardal creates a session ID for the request. Send x-hrd-consent: granted only when identity processing is allowed. Send denied when consent is declined or unknown.

Mobile event payload

{
  "tenantId": "your-tenant-id",
  "type": "event",
  "eventName": "app_open",
  "payload": {
    "sourceId": "your-source-id",
    "url": "app://home",
    "timestamp": 1750000000000,
    "data": {
      "screen_name": "HomeScreen",
      "app_version": "3.2.1"
    }
  }
}

timestamp is when the event happened, in milliseconds since the Unix epoch — not when the request is sent. Compute it at the moment the event occurs and keep that value: an event sent later, such as a retried or queued one, must still carry the time it originally happened. In practice that is usually the current time (for example Date.now() in JavaScript, System.currentTimeMillis() in Kotlin, or Int(Date().timeIntervalSince1970 * 1000) in Swift). The value in the example is a placeholder for readability.

One event cannot contain both a non-empty items array and a non-empty leads array.

Mobile request examples

Start with app_open in a test source. Replace the collection hostname and both UUIDs with the values from Setup. Choose the language your app uses. For a real purchase, send the order data only after the order is confirmed.

# Create one session ID for this test run. Reuse it for subsequent events in this session.
SESSION_ID=$(uuidgen)
# Event time in milliseconds. Reuse a stored value for a delayed or retried event.
NOW_MS=$(($(date +%s) * 1000))

curl -X POST https://analytics.yourdomain.com/collect \
  -H "Content-Type: application/json" \
  -H "User-Agent: ${USER_AGENT:?Set USER_AGENT to your mobile app User-Agent}" \
  -H "x-hrd-session-id: $SESSION_ID" \
  -H "x-hrd-consent: denied" \
  -d "{
    "tenantId": "your-tenant-id",
    "type": "event",
    "eventName": "app_open",
    "payload": {
      "sourceId": "your-source-id",
      "url": "app://home",
      "timestamp": $NOW_MS,
      "data": {
        "screen_name": "Home"
      }
    }
  }"

In Flutter, add the http package and call sendAppOpen() from your test action. The React Native and Flutter examples send one event without a session header. To group events, supply x-hrd-session-id from your app’s session state.

A successful test returns HTTP 202 with data.accepted: 1. Open Engagement → Events, select the same source and date, and find app_open at the time you sent it. If the response contains data.skipped: true, read its reason before looking in the report. Check the collection response.

Pick your events