breat.fr

How to connect your website to your Brivacia installation

The exact snippet for your site is already generated for you: open the integration code modal from the Brivacia menu, pick your site, and copy it from there. This page explains what that snippet does and how to customize it if needed.

There are two tabs in that modal:

The recommended location is just before the closing </body> tag.


HTML tab (default, nothing to configure)

<script>
(new Image()).src =
    'https://INSTALL_URL_BRIVACIA/api/pixel.php?site=SITE_CODE_X' +
    '&page='+encodeURIComponent(location.pathname||'/') +
    '&lang='+encodeURIComponent(document.documentElement.lang||'') +
    '&title='+encodeURIComponent(document.title||'') +
    '&url='+encodeURIComponent(location.pathname||'/') +
    '&ref='+encodeURIComponent(document.referrer||'');
</script>

Everything is captured automatically from the current page, no placeholders to replace:

There is no <noscript> fallback in this tab. If you need one, use the PHP tab below, or write your own <img>-based fallback following the same pattern.


PHP tab (adds a noscript fallback)

The tracking script itself is identical to the HTML tab above — still plain JavaScript reading the current page automatically. The only addition is a <noscript> fallback for visitors without JavaScript, which needs a little PHP since it has no location/document to read from:

<script>
(new Image()).src =
    'https://INSTALL_URL_BRIVACIA/api/pixel.php?site=SITE_CODE_X' +
    '&page='+encodeURIComponent(location.pathname||'/') +
    '&lang='+encodeURIComponent(document.documentElement.lang||'') +
    '&title='+encodeURIComponent(document.title||'') +
    '&url='+encodeURIComponent(location.pathname||'/') +
    '&ref='+encodeURIComponent(document.referrer||'');
</script>

<noscript>
    <img src="https://INSTALL_URL_BRIVACIA/api/pixel.php?site=SITE_CODE_X&amp;page=<?= rawurlencode($pageId ?? (parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/')) ?>&amp;lang=<?= rawurlencode($pageLang ?? $currentLanguage ?? $lang ?? '') ?>&amp;title=<?= rawurlencode($pageTitle ?? $title ?? '') ?>&amp;url=<?= rawurlencode(parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/') ?>" alt="" height="1" width="1" style="opacity:0;pointer-events:none;position:absolute">
</noscript>

The noscript fallback:


Query strings

Brivacia tracks pages without query strings. /about, /about?utm_source=newsletter and /about?lang=en are all recorded as the same page. This is intentional and keeps statistics clean — see legacy statistics for more on why.


Customizing the page identifier

The default snippet uses the current URL path as the page identifier, which works out of the box for most sites. If your CMS or framework has a more stable identifier than the URL (for example, a post ID that survives a URL/slug change), you can override just the page parameter with it instead:

<script>
(new Image()).src =
    'https://INSTALL_URL_BRIVACIA/api/pixel.php?site=SITE_CODE_X' +
    '&page=' + encodeURIComponent('PAGE_IDENTIFIER') +
    '&lang='+encodeURIComponent(document.documentElement.lang||'') +
    '&title='+encodeURIComponent(document.title||'') +
    '&url='+encodeURIComponent(location.pathname||'/') +
    '&ref='+encodeURIComponent(document.referrer||'');
</script>

Replace PAGE_IDENTIFIER with a value from your CMS or framework:

url should still reflect the real current URL path (used for links back to the page from the dashboard) even when page is overridden with a custom identifier.

Once pages are identified by a stable ID, you can shape how they're displayed (a clean title, a friendly URL per language, etc.) with custom site rules — that's a separate, display-only layer on top of whatever page you send here.


Multilingual websites

For multilingual websites, send the current website language using the lang parameter — the default snippet already does this automatically via document.documentElement.lang, so this only matters if you're overriding it manually.

Examples of valid values:

fr
en
es
ko
en-US

Brivacia only keeps the primary language subtag: en-US and en-GB are both stored as en, fr-CA and fr-FR as fr, and so on. This groups pages by language rather than by country or browser variant.

If lang is missing entirely, Brivacia also tries to detect the language from a /xx/ prefix in the page URL or in the referrer before giving up.

If no language can be determined at all, the page is still tracked normally, but its language shows up as unknown (a ? flag) in the dashboard instead of being guessed. Brivacia periodically retries fetching the page in the background to resolve it automatically once a real language becomes available, so this usually corrects itself without any action needed.

Do you find this project useful? You can support its development using the buttons in the page footer.