The page API
Once loaded, the script exposes window.EodiaAnalytics. Six methods, none of which returns a
value:
EodiaAnalytics.track('newsletter_signup', { placement: 'footer' })EodiaAnalytics.identify(jwt) // or null to forget itEodiaAnalytics.page() // a page view, by handEodiaAnalytics.optOut() // the visitor refuses measurementEodiaAnalytics.optIn() // they withdraw their refusalEodiaAnalytics.consent(true) // "with consent" mode: the consent management platform calls ittrack(name, properties)
Section titled “track(name, properties)”Sends an event, attached to the current page view.
EodiaAnalytics.track('review_posted', { rating: 5, item_id: 'KA2' })| Rule | Limit |
|---|---|
| Name | lowercase letters, digits and _ . : -, 64 characters at most: ^[a-z0-9_.:-]{1,64}$ |
| Properties | 30 at most; keys of 40 characters at most (A-Z a-z 0-9 _ . -) |
| Values | text (500 characters at most), number, boolean or null |
items | reserved for e-commerce events |
An event outside these limits is rejected (“Invalid payload”) and shows up in the
Verification tab. An event received but not declared is kept: it shows up in the
Metadata tab, where one click declares it, with a label, a description and the type of each
property. Once declared, it has its own view, analytics.evt_<name>, with one typed column per
property.
identify(token)
Section titled “identify(token)”Attaches the rest of the visit to a signed-in visitor, through a JWT signed by your server with
the site secret, like data-identity. identify(null) forgets it (on sign-out). See
the signed-in visitor.
page()
Section titled “page()”Counts a page view by hand: with data-auto="false", or when the page changes state without
changing address (a step in a multi-page form, a dialog that acts as a page).
optOut() and optIn()
Section titled “optOut() and optIn()”optOut() records the visitor’s refusal in their browser (localStorage), deletes the
measurement cookie and discards anything waiting to be sent; nothing is sent afterwards, from
that browser, for that site. optIn() lifts the refusal. This is the opt-out link to offer in
the privacy policy:
<a href="#" onclick="EodiaAnalytics.optOut(); this.textContent = 'Audience measurement disabled'; return false"> Stop measuring my visit</a>The browser’s Global Privacy Control signal counts as a refusal in the same way, without a click.
consent(given)
Section titled “consent(given)”For sites in with consent mode: the site’s consent management platform calls
consent(true) when the visitor accepts audience measurement. The script then switches to the
measurement cookie; consent(false) deletes it and returns to the daily hash. In the other
modes, the call has no effect. See tracking modes.
The call queue before loading
Section titled “The call queue before loading”The tag carries defer: the script arrives after the rest of the page. A call made before it
would be lost. Place this bootstrap before the tag: it records the calls in a queue, which
the script replays in order when it arrives.
<script> window.EodiaAnalytics = window.EodiaAnalytics || { q: [] }; ['track', 'identify', 'page', 'optOut', 'optIn', 'consent'].forEach(function (m) { EodiaAnalytics[m] = EodiaAnalytics[m] || function () { EodiaAnalytics.q.push([m, [].slice.call(arguments)]); }; });</script><script defer src="https://stats.example.com/a.js" data-site="s_arvordemo001"></script>When it arrives, the script first replays the identity, the consent and the refusal, then counts
the page view, then replays the events and the manual page views: a track called early is thus
attached to the right page and the right visitor.
With TypeScript
Section titled “With TypeScript”declare global { interface Window { EodiaAnalytics?: { track(name: string, props?: Record<string, string | number | boolean | null | object[]>): void identify(token: string | null): void page(): void optOut(): void optIn(): void consent(given: boolean): void } }}
window.EodiaAnalytics?.track('store_locator', { city: 'Quimper' })The ?. operator keeps the page intact when the script is blocked.
eodia analytics is free software by Eodia.