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.
| Header | Required | Value |
|---|---|---|
Content-Type | Yes | application/json |
User-Agent | Yes | App or platform user agent, which many HTTP clients send automatically |
x-hrd-session-id | No | Stable UUID for the current app session |
x-hrd-consent | No | granted 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"
}
}
}"
import Foundation
let url = URL(string: "https://analytics.yourdomain.com/collect")!
// Create once when the app session starts, then reuse it for every event.
let sessionId = UUID()
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("denied", forHTTPHeaderField: "x-hrd-consent")
request.setValue(sessionId.uuidString, forHTTPHeaderField: "x-hrd-session-id")
request.httpBody = """
{
"tenantId": "your-tenant-id",
"type": "event",
"eventName": "app_open",
"payload": {
"sourceId": "your-source-id",
"url": "app://home",
"timestamp": \(Int(Date().timeIntervalSince1970 * 1000)),
"data": {
"screen_name": "Home"
}
}
}
""".data(using: .utf8)
let (bytes, response) = try await URLSession.shared.data(for: request)
let body = try JSONSerialization.jsonObject(with: bytes) as? [String: Any]
let result = body?["data"] as? [String: Any]
if (response as? HTTPURLResponse)?.statusCode == 202, result?["accepted"] as? Int == 1 {
print("Event accepted")
} else {
print("Check the collection response:", String(decoding: bytes, as: UTF8.self))
}
Add OkHttp to your Android app and declare android.permission.INTERNET in its manifest. Call sendAppOpen on a background thread with your shared client and app-session UUID.
import java.util.UUID
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject
fun sendAppOpen(client: OkHttpClient, sessionId: UUID) {
val body = """
{
"tenantId": "your-tenant-id",
"type": "event",
"eventName": "app_open",
"payload": {
"sourceId": "your-source-id",
"url": "app://home",
"timestamp": ${System.currentTimeMillis()},
"data": {
"screen_name": "Home"
}
}
}
""".trimIndent()
val request = Request.Builder()
.url("https://analytics.yourdomain.com/collect")
.header("User-Agent", requireNotNull(System.getProperty("http.agent")))
.addHeader("x-hrd-consent", "denied")
.addHeader("x-hrd-session-id", sessionId.toString())
.post(body.toRequestBody("application/json".toMediaType()))
.build()
client.newCall(request).execute().use { response ->
val text = response.body?.string().orEmpty()
check(response.code == 202 && JSONObject(text).optJSONObject("data")?.optInt("accepted") == 1) {
"Hardal returned ${response.code}: $text"
}
}
}
const response = await fetch("https://analytics.yourdomain.com/collect", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-hrd-consent": "denied"
},
body: JSON.stringify({
tenantId: "your-tenant-id",
type: "event",
eventName: "app_open",
payload: {
sourceId: "your-source-id",
url: "app://home",
timestamp: Date.now(),
data: {
screen_name: "Home"
}
}
})
});
const result = await response.json();
if (response.status !== 202 || result.data?.accepted !== 1) {
throw new Error(result.data?.reason ?? result.error?.message ?? "Event was not accepted");
}
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<void> sendAppOpen() async {
final response = await http.post(
Uri.parse("https://analytics.yourdomain.com/collect"),
headers: {
"Content-Type": "application/json",
"x-hrd-consent": "denied"
},
body: jsonEncode({
"tenantId": "your-tenant-id",
"type": "event",
"eventName": "app_open",
"payload": {
"sourceId": "your-source-id",
"url": "app://home",
"timestamp": DateTime.now().millisecondsSinceEpoch,
"data": {
"screen_name": "Home"
}
}
}),
);
final result = jsonDecode(response.body);
if (response.statusCode != 202 || result['data']?['accepted'] != 1) {
throw StateError('Collection returned ${response.statusCode}: ${response.body}');
}
}
Save this component as HardalAppOpenExample.cs, enter the values for your test source, and attach it to one active object in a test scene. Starting the scene sends one event.
using System;
using System.Collections;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
public class HardalAppOpenExample : MonoBehaviour
{
[Serializable] private class Reply { public Counts data; }
[Serializable] private class Counts { public int accepted; }
private IEnumerator Start()
{
var sessionId = Guid.NewGuid().ToString();
var timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
var payload = $@"{{
""tenantId"": ""your-tenant-id"",
""type"": ""event"",
""eventName"": ""app_open"",
""payload"": {{
""sourceId"": ""your-source-id"",
""url"": ""app://home"",
""timestamp"": {timestamp},
""data"": {{
""screen_name"": ""Home""
}}
}}
}}";
using var request = new UnityWebRequest("https://analytics.yourdomain.com/collect", "POST");
request.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(payload));
request.downloadHandler = new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
request.SetRequestHeader("x-hrd-consent", "denied");
request.SetRequestHeader("x-hrd-session-id", sessionId);
yield return request.SendWebRequest();
var body = request.downloadHandler.text;
if (request.responseCode == 202 && JsonUtility.FromJson<Reply>(body)?.data?.accepted == 1)
Debug.Log("Event accepted");
else
Debug.LogWarning($"Collection returned {request.responseCode}: {body}");
}
}
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.