Skip to content

Page views and newsletter for your site ​

Your product's marketing site can count visits and collect newsletter subscribers through TenancyEngine, without a third-party analytics script and without running a mailing list of your own. Both features are off until you turn them on for your application, and both work from any origin you list.

  • Page views are anonymous counters. No cookie, no stored IP address, no stored user agent, no visitor ID that survives the day. They are counted only after the visitor allows analytics in your own consent banner, and never when the browser sends Global Privacy Control or Do Not Track.
  • Newsletter is double opt-in. A visitor types an address and ticks a consent box, receives a confirmation email, and is on the list only after clicking its link. Every later email carries a one-click unsubscribe.

Turn it on ​

  1. Open your application in the console and go to Public site.
  2. Add the browser origins your site is served from, for example https://www.example.com (scheme and host, no path). Only these origins are accepted.
  3. Switch on Page views, Newsletter, or both, and save.
  4. Copy the site key. It starts with tepk_. It only says which site a request is about; the origin list is what authorises a browser, so it is safe in page source.

Add the script ​

html
<script src="https://auth.saasruntime.com/sdk/web-analytics/v1/web-analytics.js"
        data-site-key="tepk_your_key" defer></script>

Use the matching lane for development, such as https://auth.lab.saasruntime.com. The script takes its API origin from where it was loaded, or from data-api.

The script sends nothing until you tell it the visitor allowed analytics. Call it from your consent banner:

js
// visitor accepted analytics
TenancyWebAnalytics.setConsent(true);
// visitor declined, or withdrew consent later
TenancyWebAnalytics.setConsent(false);

If your banner may run before the script has loaded, wait for the tenancy-web-analytics:ready event on document.

As an npm module (single-page apps):

ts
import { init, setConsent, track } from '@tenancyengine/web-analytics';

init({ siteKey: 'tepk_your_key', apiBase: 'https://auth.saasruntime.com' });
setConsent(consentBanner.analyticsAllowed);
track('cta_signup');

Route changes made with the History API are counted automatically; turn that off with spa: false (or data-spa="false").

Count a button or link by adding data-te-event:

html
<a href="/signup" data-te-event="cta_signup">Start free</a>

Event names are lower case, start with a letter, use letters, digits, _ . : -, and are at most 40 characters. pageview is reserved.

Apps built on @platform/form-ui do not need to write their own banner. Create one store per app (its own storage key) and render the shared banner with your own wording:

tsx
import { ConsentBanner, createSiteConsent } from '@platform/form-ui';
import { setConsent } from '@tenancyengine/web-analytics';

export const siteConsent = createSiteConsent({ storageKey: 'acme-site-consent', version: 1 });

<ConsentBanner store={siteConsent} onChange={setConsent}>
  We count which pages are useful. The counts are anonymous. Nothing else is turned on.
</ConsentBanner>

Nothing runs until the visitor presses Allow, both buttons look the same, and a footer "Cookie settings" button calls siteConsent.requestSettings() to reopen it. Call setConsent(siteConsent.hasAnalyticsConsent()) once on load for visitors who chose earlier. Bump version when you add a new kind of non-essential processing so visitors are asked again.

Newsletter form ​

html
<form data-te-newsletter data-consent-version="2026-10">
  <label>Email <input type="email" name="email" required autocomplete="email"></label>
  <label><input type="checkbox" name="consent" required>
    Send me product updates by email. I can unsubscribe at any time.</label>
  <input type="text" name="website" tabindex="-1" autocomplete="off" aria-hidden="true" style="position:absolute;left:-9999px">
  <button type="submit">Subscribe</button>
  <p data-te-newsletter-status role="status"></p>
</form>

With the script loaded the form is enhanced in place. Without JavaScript the same form works as a plain HTML post: set method="post" and action="https://auth.saasruntime.com/api/v1/public/sites/tepk_your_key/newsletter/subscribe", add <input type="hidden" name="returnUrl" value="https://www.example.com/newsletter">, and the browser comes back to that page with ?te_newsletter=pending_confirmation (or invalid_email, consent_required, site_busy). A returnUrl on a different origin than your allowed origins is ignored and the platform shows its own result page.

The text next to the checkbox is yours. Keep a short version label in data-consent-version; it is stored with the subscription as proof of what the visitor agreed to.

HTTP contract ​

All routes are under /api/v1/public/sites/{siteKey} on the platform authority. They are anonymous, rate limited per client IP, and answer CORS for any origin; the origin allowlist is enforced by the handler.

Requests are CORS "simple" requests: send the body as text/plain (or a form) and no custom headers, so the browser makes no preflight request. The server reads the body as JSON whatever the content type.

GET /config ​

json
{ "analytics": true, "newsletter": true, "newsletterListName": "Acme product updates", "originAllowed": true }

POST /collect ​

json
{ "event": "pageview", "path": "/pricing", "referrer": "https://news.example.org/post", "source": "newsletter", "consent": "analytics" }
FieldRules
consentMust be exactly "analytics". Without it nothing is counted.
pathRequired. Query string and fragment are dropped. Segments that look like an email address, UUID, long number or opaque token are replaced by :redacted, :id or :token. At most 300 characters.
eventOptional, defaults to pageview.
referrerOptional. Only the host is kept; your own hosts count as no referrer.
sourceOptional utm_source value, used only when there is no referrer. Stored as utm:<value>.

Answers: 204 when counted or deliberately ignored (Global Privacy Control, Do Not Track, bot-like user agent, missing consent). Ignoring is silent on purpose. Errors: 400 invalid_payload, 403 origin_not_allowed, 403 analytics_disabled, 404 site_not_found, 413 payload_too_large, 429 rate limited.

The device class (desktop, mobile, tablet) is derived from the user agent and the country from the edge, then both the user agent and the IP address are discarded. Unique visitors are estimated from a hash of site, IP address and user agent under a random per-day salt; the hashes and the salt are deleted after two days.

POST /newsletter/subscribe ​

json
{ "email": "[email protected]", "consent": true, "website": "", "locale": "en-CA", "consentTextVersion": "2026-10", "pageUrl": "https://www.example.com/newsletter" }

consent must be true. website is the honeypot and must be empty. The answer is 202 {"status":"pending_confirmation"} whether the address is new, already pending, already subscribed or throttled, so the form cannot be used to find out who is subscribed. Errors: 400 invalid_email, 400 consent_required, 403 origin_not_allowed, 403 newsletter_disabled, 404 site_not_found, 429 site_busy.

Limits that protect third parties: one confirmation email per address every 10 minutes, at most 5 per subscription, at most 3 per address per day across every site, at most 2000 new addresses per site per day. A confirmation link works for 7 days.

LinkBehaviour
GET /api/v1/public/newsletter/confirm?t=…Shows a page with a Confirm button. Opening the link, as a mail scanner does, changes nothing.
POST /api/v1/public/newsletter/confirm (t field)Confirms and sends the welcome email.
GET /api/v1/public/newsletter/unsubscribe?t=…Shows an Unsubscribe button.
POST /api/v1/public/newsletter/unsubscribe?t=…Unsubscribes. With the body List-Unsubscribe=One-Click it answers 200 text/plain with no page (RFC 8058). Unsubscribe links never expire.

Emails to subscribers carry List-Unsubscribe: <…/unsubscribe?t=…> and List-Unsubscribe-Post: List-Unsubscribe=One-Click.

The confirmation and welcome emails are platform email templates (newsletter.confirm, newsletter.welcome) that you can edit like any other, and they use your application's name, logo and support address.

Reading the numbers ​

The Public site page shows page views and visits (daily unique visitors added up; a person who visits on two days counts twice), the trend against the previous period, top pages, referrers, countries, devices and custom events, plus subscriber counts, the confirmation rate and a list you can search, export as CSV, and erase from.

The same data is available over the admin API (bearer token, platform:applications:read for counts, platform:applications:configure for anything that shows addresses):

Route (under /api/v1/admin/applications/{applicationId}/public-site)
GET / , PUT / , POST /rotate-keySettings and key
GET /analytics/summary?days=7|30|90|365Page-view aggregates
GET /newsletter/summary?days=…Subscriber counts and confirmation rate
GET /newsletter/subscribers?status=&search=&page=&pageSize=Subscriber list
GET /newsletter/subscribers/export?includeAll=falseCSV, confirmed subscribers only unless includeAll=true
DELETE /newsletter/subscribers/{id}Erase one subscriber

The platform's own sites use the same routes under /api/v1/admin/platform-sites/{slug}/public-site with the platform:settings:* permissions.

What is stored, and for how long ​

DataContentKept
Daily countersDate, event, path, referrer host, device class, country, count760 days by default (30 to 1095, per site)
Daily totalsDate, page views, visitssame
Visitor hashes and day salt128-bit salted hash, random salt2 days
SubscribersEmail, status, timestamps, locale, form page (no query string), consent wording versionPending rows are deleted after 14 days. Confirmed rows are kept until the person unsubscribes or you erase them. Unsubscribed rows are kept as a suppression record so the address is not re-added silently.

Sites TenancyEngine hosts for you ​

If your marketing pages are served by TenancyEngine (a Marketing custom domain), switching on Page views is all you need. The pages then load the beacon from the platform, show a small consent bar with equal Decline and Allow buttons, and add an Analytics choices link to the footer so a visitor can change their mind. Nothing is counted until the visitor presses Allow. Add the site's own address to the allowed origins first.

Replacing Google Analytics or your own list ​

Remove the gtag.js script, the measurement ID setting and any server-side relay. A site that counts visits through a third-party script, or posts newsletter addresses to its own inbox or list, is outside the platform's rules: authentication, email, analytics and background delivery go through TenancyEngine. Keep your own consent banner; it is what drives setConsent.

Not included yet: sending newsletter issues from the console. Export the confirmed list, or ask for the broadcast feature; every message sent to the list must carry the unsubscribe link and the two RFC 8058 headers.

TenancyEngine platform documentation