Group Tracking lets your team see each other’s live location on the map by typing the same Mission Code. It works out of the box with SurvivalArk’s default relay on Cloudflare. If you’d rather keep everything under your own control, you can set up your own copy in about 10 minutes. No coding needed.
The same rules apply whether you use the default relay or your own.
What protects your data
The Mission Code is the only key. Anyone who knows or guesses it can see and add to that mission
Data is sent over HTTPS, but it isn’t otherwise encrypted on the relay
No accounts, phone numbers, or sign-ins: just a random ID made once on each device, and the name each person types in
Each device’s data deletes itself 24 hours after its last update. Tapping End Mission for Everyone deletes the whole mission’s data right away, and the code can be reused for a fresh mission after 10 minutes
Good habits
Use a Mission Code that’s hard to guess, not “1234” or “test”
Treat it like a Wi-Fi password: share it only with people you trust
Use a new code for each mission
Group Tracking is built for quick team coordination, not to hide your location from a determined attacker
Cost
What it costs to run
Cloudflare has a free plan, but its daily limit is small for real searches. Check Cloudflare’s current prices before you start, since they can change.
Cloudflare plan
Included
Roughly enough for
Best for
Free plan
1,000 saves a day
About 5 hours of one phone sharing its location (each phone sends an update about every 20 seconds). A team of 4 uses that up in a little over an hour.
Testing and short practice runs
Workers Paid plan
1 million saves a month
Hundreds of hours of searching each month
Real missions and regular use
When the free limit runs out, location updates stop working until the limit resets at midnight UTC (7 PM Eastern in winter, 8 PM in summer). If your team may rely on this during a real search, use the Workers Paid plan. Check current prices at Workers pricing and KV limits.
Setup
Step by step, no command line needed
Follow these in order. Cloudflare sometimes renames menu items, so if a name doesn’t match exactly, look for the closest one.
In the Cloudflare dashboard sidebar, go to Workers & Pages → Create → Create Worker. Give it a name, for example my-survivalark-relay, and click Deploy. This makes a placeholder “Hello World” Worker. That’s fine; you’ll replace it next.
3
Paste the relay script
Click Edit code. Select all the placeholder code, delete it, and paste in the whole script from the box below (use the Copy script button). Click Deploy (it may say Save and deploy).
4
Create a storage space (KV namespace)
In the sidebar, go to Storage & Databases → KV (on some accounts it’s under Workers & Pages → KV). Click Create, name it something like mission-relay-kv, and create it.
5
Connect the storage to your Worker
Open your Worker → Settings → Bindings (older screens: Variables → KV Namespace Bindings). Click Add binding, choose KV namespace, set the variable name to exactly MISSION_KV, pick the namespace you just made, and deploy again.
6
Copy your Worker’s address
It’s shown at the top of your Worker’s page and looks like https://my-survivalark-relay.YOUR-NAME.workers.dev.
Quick test: add /m/test/d to the end of that address and open it in your browser. If you see {"devices":[]}, your relay is working.
7
Point SurvivalArk to your relay
In SurvivalArk, open the Settings tab → Group Tracking (Optional). Paste your Worker’s address into Relay Server URL, add a device name if you like, and tap Save. Everyone on your team needs to enter the same address.
8
Start a mission
Go to Field Tools → Map → Group Tracking (Optional). Everyone types the same Mission Code and taps Join Mission. Each person’s trail appears on everyone’s map, updating about every 20 seconds.
The script
The relay script (step 3)
Copy everything in this box into the Cloudflare code editor, replacing the placeholder code completely.
worker.js
// SurvivalArk Mission Relay — a minimal location-sharing relay for the app's optional Group
// Tracking feature.
//
// What this does: a small, almost-stateless HTTP relay that lets a group of people see each
// other's live GPS trails on a map without any accounts or sign-in — everyone just types the same
// Mission Code into SurvivalArk. This Worker and its one KV namespace (bound below as MISSION_KV)
// are the entire backend; nothing is stored anywhere else. Each device's uploaded points
// auto-expire 24 hours after its last update (the TTL below), so nothing lingers once everyone
// stops using that code.
//
// PRIVACY NOTE — read this before deploying: a Mission Code is the ONLY thing protecting this
// data. Anyone who knows (or guesses) a code can read and write that mission's location points —
// there's no password, no account, and no encryption beyond plain HTTPS in transit. That's a
// deliberate trade-off for a zero-setup, zero-friction tool a group can start using in seconds;
// it is NOT meant to protect sensitive location data from a determined, targeted attacker. Use a
// code that isn't trivially guessable (not "1234" or "test") and treat it like a shared Wi-Fi
// password: known only to people you trust with this information.
//
// Routes:
// POST /m/{missionCode}/u — upload this device's CURRENT state (replaces, not appends, whatever
// this device last uploaded for this mission).
// Body: {"deviceId":"...", "deviceName":"...", "points":[{"lat":0,"lng":0}, ...],
// "pins":[{"id":"...","label":"...","type":"...","lat":0,"lng":0,"createdAt":0}, ...],
// "checkIn":{"note":"...","at":0} or omitted/null,
// "urgent":true/false, "urgentAt":0, "battery":0-100 or omitted/null}
// pins/checkIn/urgent/battery are all optional.
// Response: {"ok":true} or {"ok":true,"ended":true} — see "ended" note
// below.
// GET /m/{missionCode}/d — download every OTHER device's current state for this mission.
// ?exclude={deviceId} leaves that one id out of the response.
// Response: {"devices":[{"deviceId":"...","deviceName":"...","points":[...],
// "pins":[...],"checkIn":{...} or null,"urgent":false,"urgentAt":0,
// "battery":0-100 or null,"updatedAt":0}, ...]}
// POST /m/{missionCode}/e — end this mission for EVERY device using it. No request body.
// Response: {"ok":true}.
//
// pins/checkIn/urgent/battery all live in the SAME per-device KV record as points/deviceName — no
// new KV keys and no extra reads/writes per poll, which is what keeps this safe against the quota
// issue described below (a client that sends nothing new just keeps re-sending its last known
// state, same as points already do).
//
// "ended" — alongside the "mission captain" End Mission for Everyone action: there's no push
// mechanism here, only polling, so a device only learns a mission ended the next time it happens
// to call /u or /d. Both routes check a short-lived "ended:{missionCode}" flag and report
// {"ended":true} when it's set; the client is responsible for leaving the mission locally the
// moment it sees that, in either an upload or a download response.
//
// Device index instead of KV list(): the download route uses a small "idx:{missionCode}" key (a
// JSON map of deviceId -> last-touched time) that upload maintains and download just reads with a
// plain get(), instead of calling env.MISSION_KV.list({prefix}) on every poll. That matters because
// Cloudflare's free tier limits "list" operations much more tightly (1,000/day account-wide) than
// plain reads (100,000/day), and one idle device polling every 20 seconds would otherwise burn
// through the list quota on its own in a few hours. If you ever have enough simultaneous
// missions/devices to threaten even the read/write ceilings (not just list()), Cloudflare's $5/mo
// Workers Paid plan raises every one of these limits by 100-1000x.
const MAX_POINTS_PER_DEVICE = 300;
const MAX_MISSION_CODE_LENGTH = 40;
const MAX_DEVICE_NAME_LENGTH = 60;
const MAX_PINS_PER_DEVICE = 20;
const MAX_PIN_ID_LENGTH = 64;
const MAX_PIN_LABEL_LENGTH = 80;
const MAX_PIN_TYPE_LENGTH = 20;
const MAX_CHECKIN_NOTE_LENGTH = 200;
const TTL_SECONDS = 24 * 60 * 60; // 24 hours — see file header
const INDEX_REFRESH_MS = 3 * 60 * 1000; // how often one device's entry in the mission index gets rewritten; keeps index writes rare instead of once per 20-second poll
const ENDED_FLAG_TTL_SECONDS = 10 * 60; // how long the "mission ended" flag sticks around — long enough that every device polling at least every few minutes is guaranteed to see it, short enough that the same code can be reused for a brand new mission shortly after
function jsonResponse(body, status = 200) {
return new Response(JSON.stringify(body), {
status,
headers: { "content-type": "application/json" },
});
}
function sanitizeMissionCode(raw) {
if (!raw) {
return null;
}
let decoded;
try {
decoded = decodeURIComponent(raw);
} catch {
return null;
}
const trimmed = decoded.trim();
if (trimmed.length === 0 || trimmed.length > MAX_MISSION_CODE_LENGTH) {
return null;
}
return trimmed;
}
export default {
async fetch(request, env) {
const url = new URL(request.url);
const parts = url.pathname.split("/").filter(Boolean); // ["m", "{code}", "u"|"d"]
if (parts.length !== 3 || parts[0] !== "m") {
return jsonResponse({ error: "not found" }, 404);
}
const missionCode = sanitizeMissionCode(parts[1]);
if (!missionCode) {
return jsonResponse({ error: "invalid mission code" }, 400);
}
const action = parts[2];
if (action === "u" && request.method === "POST") {
return handleUpload(request, env, missionCode);
}
if (action === "d" && request.method === "GET") {
return handleDownload(request, env, missionCode, url);
}
if (action === "e" && request.method === "POST") {
return handleEnd(env, missionCode);
}
return jsonResponse({ error: "not found" }, 404);
},
};
async function handleUpload(request, env, missionCode) {
let body;
try {
body = await request.json();
} catch {
return jsonResponse({ error: "invalid JSON body" }, 400);
}
const deviceId = typeof body.deviceId === "string" ? body.deviceId.trim() : "";
if (!deviceId || deviceId.length > 64) {
return jsonResponse({ error: "missing or invalid deviceId" }, 400);
}
if (await isMissionEnded(env, missionCode)) {
// Don't resurrect the mission's data — just tell this device to leave, same as a download
// response would. See the file header's "ended" note for why both routes need to do this.
return jsonResponse({ ok: true, ended: true });
}
const deviceName = typeof body.deviceName === "string" && body.deviceName.trim().length > 0
? body.deviceName.trim().slice(0, MAX_DEVICE_NAME_LENGTH)
: "Searcher";
const points = Array.isArray(body.points)
? body.points
.filter((p) => p && typeof p.lat === "number" && typeof p.lng === "number"
&& p.lat >= -90 && p.lat <= 90 && p.lng >= -180 && p.lng <= 180)
.slice(-MAX_POINTS_PER_DEVICE)
.map((p) => ({ lat: p.lat, lng: p.lng }))
: [];
const pins = sanitizePins(body.pins);
const checkIn = sanitizeCheckIn(body.checkIn);
const urgent = body.urgent === true;
const urgentAt = urgent
? (typeof body.urgentAt === "number" ? body.urgentAt : Date.now())
: 0;
const battery = sanitizeBattery(body.battery);
const record = { deviceName, points, pins, checkIn, urgent, urgentAt, battery, updatedAt: Date.now() };
const key = `mission:${missionCode}:${deviceId}`;
await env.MISSION_KV.put(key, JSON.stringify(record), { expirationTtl: TTL_SECONDS });
// Race guard: if End Mission for Everyone ran while this upload was in flight (after the check
// above but before the put), the put just re-created a record the end call already deleted.
// Check the flag once more and remove it again, so an ended mission stays empty. Costs one extra
// read per upload; reads are plentiful on every plan (writes are the scarce quota).
if (await isMissionEnded(env, missionCode)) {
await env.MISSION_KV.delete(key);
return jsonResponse({ ok: true, ended: true });
}
await touchDeviceIndex(env, missionCode, deviceId);
return jsonResponse({ ok: true });
}
// Same defensive-filter style as the points array above: silently drop anything malformed rather
// than rejecting the whole upload over one bad pin.
function sanitizePins(raw) {
if (!Array.isArray(raw)) {
return [];
}
return raw
.filter((p) => p && typeof p.id === "string" && p.id.trim().length > 0
&& typeof p.lat === "number" && typeof p.lng === "number"
&& p.lat >= -90 && p.lat <= 90 && p.lng >= -180 && p.lng <= 180)
.slice(-MAX_PINS_PER_DEVICE)
.map((p) => ({
id: p.id.trim().slice(0, MAX_PIN_ID_LENGTH),
label: typeof p.label === "string" ? p.label.trim().slice(0, MAX_PIN_LABEL_LENGTH) : "",
type: typeof p.type === "string" && p.type.trim().length > 0
? p.type.trim().slice(0, MAX_PIN_TYPE_LENGTH)
: "other",
lat: p.lat,
lng: p.lng,
createdAt: typeof p.createdAt === "number" ? p.createdAt : Date.now(),
}));
}
// Returns null for "no check-in posted" (as opposed to a check-in with an empty note, which is
// still a real check-in — someone tapping Check In with nothing typed).
function sanitizeCheckIn(raw) {
if (!raw || typeof raw !== "object") {
return null;
}
return {
note: typeof raw.note === "string" ? raw.note.trim().slice(0, MAX_CHECKIN_NOTE_LENGTH) : "",
at: typeof raw.at === "number" ? raw.at : Date.now(),
};
}
// null means "unknown" (no battery hardware, or an unreadable reading on the device) — distinct
// from 0, which is a real, alarming reading. Rides along passively, same as deviceName; it's never
// a reason by itself to treat an upload as having "nothing to send".
function sanitizeBattery(raw) {
if (typeof raw !== "number" || Number.isNaN(raw)) {
return null;
}
return Math.max(0, Math.min(100, Math.round(raw)));
}
async function isMissionEnded(env, missionCode) {
const flag = await env.MISSION_KV.get(`ended:${missionCode}`);
return !!flag;
}
// "Mission captain" End Mission for Everyone. There's no real authentication behind this —
// anyone who currently has the Mission Code can call it, same trust model as everything else
// here. Deletes every device's data outright (clean slate) and leaves a short-lived "ended" flag
// that handleUpload/handleDownload both check, so devices find out on their next poll regardless
// of which route they happen to call next.
async function handleEnd(env, missionCode) {
const indexKey = `idx:${missionCode}`;
const index = await readIndex(env, indexKey);
const deletions = Object.keys(index).map((deviceId) =>
env.MISSION_KV.delete(`mission:${missionCode}:${deviceId}`)
);
deletions.push(env.MISSION_KV.delete(indexKey));
deletions.push(env.MISSION_KV.put(`ended:${missionCode}`, "1", { expirationTtl: ENDED_FLAG_TTL_SECONDS }));
await Promise.all(deletions);
return jsonResponse({ ok: true });
}
// Keeps "idx:{missionCode}" (a JSON object of deviceId -> last-touched-at-ms) up to date so
// handleDownload can find a mission's devices with a single get() instead of a list(). Only
// actually rewrites the index when this device is missing from it or its entry is older than
// INDEX_REFRESH_MS — most upload polls (every ~20s while a trail is active) skip the write
// entirely, so this adds only a small, occasional amount of write-operation load, not one extra
// write per poll.
async function touchDeviceIndex(env, missionCode, deviceId) {
const indexKey = `idx:${missionCode}`;
const now = Date.now();
let index = await readIndex(env, indexKey);
const lastTouched = index[deviceId];
if (lastTouched && (now - lastTouched) <= INDEX_REFRESH_MS) {
return; // already fresh enough — skip the write
}
index[deviceId] = now;
// Prune entries that have aged out of the mission entirely so this key doesn't grow forever.
for (const id of Object.keys(index)) {
if (now - index[id] > TTL_SECONDS * 1000) {
delete index[id];
}
}
await env.MISSION_KV.put(indexKey, JSON.stringify(index), { expirationTtl: TTL_SECONDS });
}
async function readIndex(env, indexKey) {
try {
const raw = await env.MISSION_KV.get(indexKey);
if (!raw) {
return {};
}
const parsed = JSON.parse(raw);
return parsed && typeof parsed === "object" ? parsed : {};
} catch {
return {};
}
}
async function handleDownload(request, env, missionCode, url) {
if (await isMissionEnded(env, missionCode)) {
return jsonResponse({ devices: [], ended: true });
}
const excludeDeviceId = url.searchParams.get("exclude") || "";
const indexKey = `idx:${missionCode}`;
const index = await readIndex(env, indexKey);
const now = Date.now();
const devices = [];
for (const deviceId of Object.keys(index)) {
if (deviceId === excludeDeviceId) {
continue;
}
if (now - index[deviceId] > TTL_SECONDS * 1000) {
continue; // defensive — the index is pruned on write, but don't trust a stale read either
}
const raw = await env.MISSION_KV.get(`mission:${missionCode}:${deviceId}`);
if (!raw) {
continue; // this device's own record already expired/missing — skip, don't error
}
try {
const record = JSON.parse(raw);
devices.push({
deviceId,
deviceName: record.deviceName || "Searcher",
points: Array.isArray(record.points) ? record.points : [],
pins: Array.isArray(record.pins) ? record.pins : [],
checkIn: record.checkIn && typeof record.checkIn === "object" ? record.checkIn : null,
urgent: !!record.urgent,
urgentAt: record.urgentAt || 0,
battery: typeof record.battery === "number" ? record.battery : null,
updatedAt: record.updatedAt || 0,
});
} catch {
// Skip a corrupted entry rather than failing the whole request for everyone else.
}
}
return jsonResponse({ devices });
}
Optional
Command-line setup (for the technically inclined)
Most people can skip this. It does exactly the same thing as the steps above.
Show the command-line steps
If you’re comfortable with Node.js and Cloudflare’s wrangler tool, run: