Skip to content

Client analytics ​

Verstka sends authored widget, group, and article scroll events only through GA4 and Yandex Metrica APIs already installed on the page. The viewer does not load or initialize either provider.

ts
interface AnalyticsOptions {
  googleMeasurementId?: string
  yandexCounterId?: number
}

interface InitOptions {
  dev?: boolean
  debug?: boolean
  viewerUrl?: string
  analytics?: false | AnalyticsOptions
}

await initArticle(articleRoot, {
  analytics: {
    googleMeasurementId: 'G-XXXXXXXXXX',
    yandexCounterId: 12345678
  }
})

await initArticles(document, {
  analytics: {
    googleMeasurementId: 'G-XXXXXXXXXX',
    yandexCounterId: 12345678
  }
})

await initArticles(document, { analytics: false })

Article views ​

The viewer also attempts an article-view pixel when an article initializes. The backend supplies meta.fingerprint in article JSON. The viewer can also read the data-vms-hash attribute on the article or its nearest wrapper. Without a fingerprint, rendering continues and no pixel is sent.

The image request sends only the fingerprint and hosting page URL, excluding query parameters and fragments. Allow https://gif.r2.verstka.io in CSP img-src. The viewer attempts collection once per fingerprint and page URL in each document, including pages containing multiple copies of an article. Browser caching remains enabled, so received hits are not an exact count of visits or unique readers. Referral sources and UTM parameters are not collected.

Article-view collection is mandatory and has no SDK opt-out. analytics: false controls authored GA4 and Yandex events only; it does not suppress the pixel. Local mock builds send the same pixel to a local receiver. For SPA navigation, initialize the article after updating the page URL; an active article retains its interactions and attempts collection for the new URL.

Resolution and kill switch ​

For each provider independently, a valid article ID wins; otherwise a valid ID from InitOptions.analytics is used. Article Google plus SDK Yandex therefore attempts both providers. A blank or invalid article value does not block a valid SDK fallback.

analytics: false disables authored provider events, including persisted article destinations and SDK fallback. Article-view collection remains active. It does not disable Enhanced Measurement, click maps, automatic goals, or other observation owned by the site's provider tag.

Repeated initialization of an active root keeps the first options. To apply new options, call its destroy function and initialize that same root again.

Host-installed provider APIs ​

For Google, the viewer calls only:

ts
gtag('event', eventName, { send_to: measurementId })

For Yandex, all widget, group, and article scroll events use reachGoal:

ts
ym(counterId, 'reachGoal', eventName)

If the specified counter exposes a callable yaCounter<ID>.reachGoal, the viewer calls yaCounter<ID>.reachGoal(eventName) instead. Each occurrence uses one of these APIs. If the counter method throws, the viewer does not retry through ym.

The viewer does not support Universal Analytics, direct GTM custom-event objects, provider/counter discovery, script loading, config/init, provider page views, author-configured event parameters, callbacks, retries, or delivery acknowledgement. A GTM-only page must intentionally expose a compatible gtag; adding a duplicate Google tag is not the remedy.

The host site owns its CMP, legal basis, consent order, and provider lifecycle. Configure Google consent defaults before viewer initialization because Show and scroll milestones can occur immediately after hydration. Before provider consent, pass analytics: false; after provider consent, destroy and reinitialize. This switch does not affect mandatory article-view collection. Suppressed Once occurrences are not replayed.

Destination IDs are public article JSON. Only trusted publishers may choose them. If article authors must not choose client analytics destinations, the host must pass analytics: false.

Verstka explicitly passes only the event name and destination ID. The site's provider tag can add page URL, referrer, title, device, cookie, consent, identity, and session context. Never include personal data in event names. Keep provider-owned page context current in SPAs. A provider used inside an iframe must exist in that iframe; the viewer never accesses window.parent.

Event and Once behavior ​

Show is the transition from no positive viewport intersection to a positive intersection after hydration. Hover is mouseenter on the widget or group root. Click uses a capture listener on the widget or group root without preventing default behavior or stopping propagation.

Groups use the same Show, Hover, Click, and Once settings as widgets. Settings belong to the selected group and are not copied to its children. Show observes the group's bounding box; Hover fires when entering its root, not on every move between children. Click includes clicks on descendants. If a group, a nested group, and a child each have a Click event, one click on that child attempts all three events. Each container has independent Once state, even when event names match.

Once is page memory keyed by root + container + trigger + event name. Destroying and reinitializing the same root does not reset it; a replacement root or reload does. No browser storage is used. If a provider is absent during a Once occurrence, there is no later replay. A repeating event can use a provider that becomes callable before a later occurrence.

Article scroll events ​

Scroll settings are optional article data, separate from the SDK's destination options:

json
{
  "clientAnalytics": {
    "scroll": {
      "name": "article_read",
      "step": 25
    }
  }
}

An absent or empty name disables tracking. The optional step defaults to 25 and accepts 10, 20, 25, 50, or 100. Names are case-sensitive, use Latin letters, digits, and underscores, and start with a letter; no prefix is required. Widget and group names allow 40 characters, scroll bases 36. Invalid names, GA4-reserved event names or prefixes, and unsupported steps do not produce calls. For scroll bases, validation applies to the generated names. See event naming.

With the example above, the viewer sends article_read_0 at first visibility, followed by article_read_25, _50, _75, and _100 as the visible viewport reaches those fractions of the article. Jumps emit all crossed milestones, including any already visible at initialization. An article that fits in view can reach 100% immediately. Horizontal frames use horizontal extent; scroll-driven presentations use the whole sequence. Click-driven presentations are excluded.

Each milestone is attempted once per article root and event name in the current document. Destroy/reinitialize of that root and responsive frame changes keep the reached milestones; a new root or reload starts again. The same provider resolution, analytics: false, and failure isolation apply as for widget events. There is no replay when a provider appears after a milestone attempt.

Yandex Metrica goals ​

reachGoal does not create a goal. In the selected counter, create a Conversion goal with a matches condition and an identifier equal to the event name. For example, CTA_Click requires the goal identifier CTA_Click.

To report scroll milestones separately, configure a goal for each generated name, such as article_read_0, article_read_25, article_read_50, article_read_75, and article_read_100. Compare converted sessions or users for those goals; goal completions are not unique readers.

Metrica allows up to 200 goals per counter, records the same goal no more than once per second, and registers up to 400 online conversions per session. Repeating Hover events and articles in a feed share that allowance. See goal restrictions.

Failure and troubleshooting ​

A callable global or queued command proves only an attempted call, not provider receipt or registration. Consent, CSP, blockers, or the network can prevent processing. Analytics failure must not break the article.

For GA4, use Tag Assistant and, when you have property access, DebugView. For Yandex Metrica, use ?_ym_debug=2. Confirm processing in the matching property or counter reports.

Mock-client verification ​

The mock host always passes Google G-2RQ4P9EBVF and Yandex 95333140 as SDK fallback. Ordinary/off mode is fully offline. mockAnalytics=record uses preinstalled doubles and no scripts. mockAnalytics=live is allowed only for the committed client-analytics fixture; production viewer code never installs tags.

Exercise /standard/client-analytics, /feed/client-analytics, and /standard/client-analytics/no-js after:

bash
yarn workspace viewer-core build
yarn workspace renderer build:critical-css
yarn workspace mock-clients test:browser

Live mode requires explicit operator opt-in, authorized dedicated non-production destinations, disabled GA Enhanced Measurement, disabled Yandex Automatic goals and unrelated collection, preflighted filters, and no personal data. A console call alone does not prove a registered conversion.