This article presents possible use cases and corresponding sample flows that you can support. It provides a useful starting point as you plan your implementation.
A site that tracks site data usage, for example in an admin dashboard or a notification system, should detect when usage is approaching a limit so the Wix user can act before writes start to fail.
To monitor a site's data usage and raise an alert near the quota:
On a periodic schedule, for example, once a day, call Get Site Data Usage.
From the response, compute the percentage used for each resource. Storage is pooled across live and sandbox environments, while item count applies to each environment separately:
storageUsedPct = (totalUsedLive.bytes + totalUsedSandbox.bytes) / storageLimitInBytesliveItemsUsedPct = totalUsedLive.items / itemCountLimitsandboxItemsUsedPct = totalUsedSandbox.items / itemCountLimitcollectionsUsedPct = collectionCount / collectionCountLimitIf any of those percentages exceeds the alerting threshold, for example 80%, raise an alert through the channel that fits the integration. For example, email, dashboard banner, or an event to an external monitoring system.
Note: If a cached value looks unexpected and you want to be sure, call Get Site Data Usage again with consistentRead set to true.
Apps that monetize via plan upgrades can detect when a site is at risk of being blocked from writing new data, and surface an upgrade prompt at the right moment.
To trigger an upgrade prompt based on site data usage:
When loading the part of your app where the prompt would appear, call Get Site Data Usage.
From the response, check whether the site is close to any limit:
(totalUsedLive.bytes + totalUsedSandbox.bytes) / storageLimitInBytes exceeds the threshold.totalUsedLive.items / itemCountLimit exceeds the threshold.totalUsedSandbox.items / itemCountLimit exceeds the threshold.collectionCount / collectionCountLimit exceeds the threshold.If any check passes, render the upgrade prompt in the app UI, with messaging tailored to the resource that's at risk.
Cache the limits returned in step 1, storageLimitInBytes, itemCountLimit, or collectionCountLimit, until the next change plan event, so subsequent calls don't need to refetch them.
3rd-party apps can free up data by deleting old records once a site approaches its storage or item-count limits.
To implement data retention based on used resources:
(totalUsedLive.bytes + totalUsedSandbox.bytes) / storageLimitInBytes) or for item count (totalUsedLive.items / itemCountLimit or totalUsedSandbox.items / itemCountLimit). If usage doesn't exceed either threshold, stop—no action needed.