Key usage tracking
Keys pile up. A screen is redesigned, a feature is removed, and its texts stay in the project, translated into every language, for years. Deleting them is risky when nobody knows whether some page still shows them.
With usage tracking on, the SDK tells localize.work which keys your app actually looks up while it runs. Each key gets a “last used” time. In the editor and through the API you can then list the keys that no session has used for a while, check them, and delete them.
Turn it on
Section titled “Turn it on”Usage tracking uses the same public key and API address as saveMissing:
await i18next.use(LocalizeBackend).init({// ...backend: { projectSlug: 'your-project', cdnBaseUrl: 'https://cdn.localize.work', apiBaseUrl: 'https://api.localize.work', apiKey: import.meta.env.VITE_LOCALIZE_PUBLIC_KEY, // public key kind // Only in development and staging builds. A browser page reports only // on the listed hostnames, so name your staging host here. trackUsage: (import.meta.env.DEV || import.meta.env.MODE === 'staging') && { allowedHosts: ['localhost', '127.0.0.1', '[::1]', 'staging.example.com'], },},});trackUsage is true, or an object for finer control:
trackUsage: { // Report only on these hostnames (browser only). allowedHosts: ['localhost', '127.0.0.1', '[::1]', 'staging.example.com'], // How often collected names are sent, in milliseconds. flushIntervalMs: 30_000,}| Setting | Default | Meaning |
|---|---|---|
allowedHosts |
['localhost', '127.0.0.1', '[::1]'] |
In a browser, the SDK reports only when window.location.hostname is in this list. Add your staging hostname to report from there. A blob: worker or an about:srcdoc or about:blank frame is checked by the hostname of the page that made it (the frame’s own origin); a sandboxed frame with an opaque origin is checked by its protocol. A page with an opaque origin (file: pages in Electron, data: workers) is checked by its protocol: add 'file:' to report from file: pages. Where there is no web address at all (server rendering, React Native) it reports whenever trackUsage is on, so turn it on only in development and staging builds there. |
flushIntervalMs |
30000 |
Names collected since the last report are sent this often (1 second to 1 hour), and once more when the page is hidden. |
Like saveMissing, it needs both apiBaseUrl and apiKey, and the key must be
the public kind.
What the SDK sends
Section titled “What the SDK sends”- Each key name is reported once per page load, and again when it is still looked up six hours later, so a server or tab that runs for weeks keeps its keys’ last use current. A name whose last report is still waiting to go out (behind rate limits, say) is not queued twice.
- Names are collected and sent in batches, every
flushIntervalMsand when the page is hidden. In a browser, each request is cut to fit the 64 KiB browsers allow forkeepaliverequests on a page, and useskeepalivewhile the page’s budget lasts, so a report in flight survives the tab closing. Outside a browser, queued names are sent before the process exits; when the API rate-limits them, the process waits forRetry-Afterup to twice (at most 65 seconds each) and then drops them with a warning. - A request still unanswered after 30 seconds is abandoned and retried like a network error, so a connection held open cannot stall reporting.
- If the server answers 401 or 403 (a wrong or deleted key), the SDK stops reporting for the rest of that page load.
- Reporting never throws, so it cannot break the app.
- An instance made with
i18next.cloneInstance()shares its parent’s resource store and is reported; one made withcloneInstance({ forkResourceStore: true })gets a new store the backend never sees, so its lookups are not. When the parent callsinit()again with the same tracking settings, its clones stay reported; with other settings (a new key or project) they stop. For server rendering, clone withoutforkResourceStore, or create andinit()an instance per request. Once such an instance is garbage collected, a tracker only it used sends what it queued (waiting out a rate limit at most twice, as at process exit) and is dropped.
What the server records
Section titled “What the server records”Each key has one “last used” time, for the key as a whole, not per language. A report sets it to the time of the report. To keep a busy development session cheap, a key’s time is rewritten at most once every 60 minutes, so “last used” can be up to an hour older than the latest lookup.
Nothing else changes: reporting creates no keys or namespaces, leaves texts and their history alone, and adds nothing to the activity feed. Names that match no key are counted and ignored.
How names map to keys
Section titled “How names map to keys”The SDK reports the names i18next looked up, and the server finds the key for each name in that namespace:
| Looked-up name | Recorded on |
|---|---|
welcome |
the key welcome |
items_one, items_other, items_zero … |
the plural key items |
place_ordinal_two |
the plural key place, and a plural key named place_ordinal if there is one |
friend_male (context) |
the key friend_male — context variants are ordinary keys |
nav, returned as an object (returnObjects: true) |
nav and every text key under it: nav.home, nav.logout … — also with keySeparator: false, where i18next does not look them up itself. At most 10,000 entries and 32 levels of one object are read, with one console warning when it is bigger: look up its parts to record the rest. The object is read again after resources are added to or removed from the store |
group/action, looked up with keySeparator: '/' |
the key group.action — the name is also sent with its separator replaced by ., the way keys are stored, and as the dotted name of the text i18next found, which can keep the separator inside a stored name (group_items_other with keySeparator: '_' → group.items_other, the plural key group.items) |
| a name with no key | nothing; it counts as unknown in the response |
When a project also has a plain key named like the lookup, such as items_one
next to the plural key items, both are recorded: i18next asks for the same
name either way, and a key wrongly marked used is only kept off the unused
list.
Find unused keys
Section titled “Find unused keys”The project’s usage window starts with the first report that matched one of its keys. The editor shows usage from then on:
- the key panel says Last used 3 days ago or No use recorded;
- the Not used in 30 days filter appears once usage has been reported for 30 days (the filter rail says on which date), as long as an app has reported usage in the last 7 days. It lists keys that are older than 30 days and had no reported use in the last 30 days, including keys never reported at all. A key created within the 30 days is never listed.
The filter is refused rather than answered when it would list keys that are in use:
- before the window is as long as the period asked for, every key would look unused;
- when no app has reported usage in the last 7 days, keys used since reports stopped would look unused.
The editor hides the filter and says why; the API returns an error naming the window’s start and the last report. When reports resume after more than 7 days without one, the window starts again from that report, so the filter appears again only 30 days later (N days later, for N days asked through the API): one report after a quiet spell cannot stand for the whole spell. That is also why the shortest period the API accepts is 7 days. Shorter gaps (tracking off for up to 7 days, then on again) cannot be seen, so keys used only during such a gap can still look unused: keep a staging app reporting.
A key’s stamp can trail its last lookup by a few hours (the SDK sends a key again only six hours after its last report, and the server refreshes a stamp at most hourly), so a key counts as unused only when its stamp is older than the period plus eight hours.
Agents and scripts get the same data:
- MCP
search_keysandget_keyreturnlastUsedAt(an ISO time, ornull) on every key, andsearch_keystakesunusedDaysto list keys not used in that many days, with the same rules as the editor filter. When it cannot be answered it fails withinvalid_argument, and its details carryreason(not_started,too_recentorstale),usageTrackedSince(the window’s start, ornull) andusageLastReportedAt(the newest key stamp, ornull). See MCP server. - The REST API takes the same filter, with the same refusal:
GET /v1/keys?unusedDays=30. See REST API.
What “not used” means
Section titled “What “not used” means”“Not used in 30 days” means no session that reported usage looked the key up in that time. It does not prove the key is dead:
- A key shown only on a screen nobody opened with tracking on looks unused. Error messages, rare flows, emails and server-rendered texts are typical.
- A key looked up by a dynamic name, such as
t(`status.${code}`), is recorded when that exact name is looked up, and only then. - Apps that do not run this SDK (a server, a mobile app, another codebase sharing the project) report nothing.
Treat the filter as a list of candidates to check, not a list to delete.
Rate limits
Section titled “Rate limits”Usage reports have their own fixed window, per API key and per IP, so they never use up the saveMissing allowance:
| Limit | Value |
|---|---|
| Window | 60 s (fixed) |
| Requests per API key | 60 / window |
| Requests per IP | 30 / window |
| Names per API key | 2,000 / window |
| Names per IP | 1,000 / window |
The full request and response format is on POST key usage.