Your users and their sites
Each of your users becomes a client and each website they add becomes a site, by your own ids. Calling again updates; it never makes a second one.
On sign-up and when a website is added
// When someone signs up (or changes their company name)
await stats.clients.upsert(user.id, { name: user.company });
// Optional: which list it shows in, in wp-admin › Clients ('client', 'subscriber' or 'api', the default)
await stats.clients.upsert(user.id, { name: user.company, kind: 'subscriber' });
// When they add a website, or change its domains
const { site } = await stats.sites.upsert(website.id, {
name: website.name,
domains: [website.domain, 'tenant-42.example.app'], // every hostname it answers on
client: user.id, // the client's ref; null for none
timezone: 'Europe/London', // optional
currency: 'GBP', // optional: revenue totals
goals: [{ kind: 'event', match: 'Purchase' }, { kind: 'page', match: '/thanks' }], // added when missing
}); - Ids may use letters, digits and
_ . : -, up to 128 characters. Two calls with the same id at the same moment are safe: the second updates what the first made. goalsadds the ones a site doesn’t have and never removes any, so send your standard set every time. Shops on WooCommerce, SureCart, FluentCart and Easy Digital Downloads get their shop goals by themselves.- To give a site made earlier in wp-admin your id, pass
adopt: '<its id>'once.
What each site needs#
sites.upsert returns what each kind of site needs to start tracking:
| The site is… | Use |
|---|---|
| Served by your Next.js app | site.site_key with the proxy: see Websites your Next.js app serves |
| Hosted elsewhere | site.snippet: a <script> tag for its <head> |
| On WordPress | site.connection: the code for the connector plugin |
| An app | site.site_key and site.install.receive_url: see Mobile and desktop apps |
Is it tracking?#
Your setup screen
const { receiving, visitors_24h } = await stats.sites.status(website.id);
// receiving: a visit arrived; also pageviews_24h and live Removing#
When they delete them
await stats.sites.remove(website.id);
await stats.clients.remove(user.id); // also removes the client's sites and portal logins Was this helpful?
Thanks for your feedback!
✓ Feedback received. Thank you!



