Stats
Highlight and Share can be used to track stats for the social networks that are interacted with.
Overview
When a user shares content (via a social button or Web Share), the plugin can send a share event to your analytics stack. Stats are on by default; you can turn them off globally or restrict which data is sent for privacy.
Three channels receive the same event (when stats are enabled):
dataLayer
Google Tag Manager (and any GTM-based tags).
gtag
Google Analytics 4 when gtag() is present on the page.
CustomEvent
Custom listeners (e.g. window.addEventListener('has:share', ...)).
If stats are disabled, nothing is pushed to any channel.
Event name
dataLayer / CustomEvent
has:share
GA4 (gtag)
has:share (same; GA4 params are separate).
Data sent (payload)
The event carries a small payload. By default, URL, share text, and title are not sent (they are sent as empty strings). Enable enhanced mode to include them.
dataLayer & CustomEvent (camelCase)
event
Always
Event name, e.g. has:share.
hasShareType
Always
Type of share, e.g. text, image.
hasSocialNetwork
Always
Network or method, e.g. twitter, pinterest, webshare.
hasShareText
Enhanced only
Selected or shared text (privacy-sensitive).
hasSharePostUrl
Enhanced only
URL being shared (privacy-sensitive).
hasSharePostTitle
Enhanced only
Title of the content (privacy-sensitive).
GA4 (gtag) — snake_case parameters
has_share_type
Always
Same as hasShareType.
has_social_network
Always
Same as hasSocialNetwork.
has_share_text
Enhanced only
Same as hasShareText.
has_share_post_url
Enhanced only
Same as hasSharePostUrl.
has_share_post_title
Enhanced only
Same as hasSharePostTitle.
Synthetic events (CustomEvent)
The plugin dispatches a synthetic CustomEvent on window so your own scripts (or GTM custom HTML tags) can react to shares without relying on dataLayer or gtag.
What is sent
The event is dispatched as:
Event type:
has:shareTarget:
windowOptions:
{ bubbles: true, cancelable: false }Payload: The same payload as dataLayer is in
event.detail(camelCase). When enhanced is off,hasShareText,hasSharePostUrl, andhasSharePostTitleare empty strings.
event.detail.event
string
Event name (has:share).
event.detail.hasShareType
string
Share type, e.g. text, image.
event.detail.hasSocialNetwork
string
Network/method, e.g. twitter, webshare.
event.detail.hasShareText
string
Share text (empty unless enhanced).
event.detail.hasSharePostUrl
string
Shared URL (empty unless enhanced).
event.detail.hasSharePostTitle
string
Content title (empty unless enhanced).
How to listen
Attach a listener to window for the event type has:share. Read the payload from event.detail.
The listener runs only when stats are enabled (has_stats_enabled / HAS_STATS_ENABLED). If stats are disabled, no CustomEvent is dispatched.
Constants
Define these in wp-config.php (or before the plugin runs) to set defaults. Filters can still override them.
HAS_STATS_ENABLED
HAS_STATS_ENABLEDDefault: Stats are enabled (no constant = tracking on).
Use: Set to
falseto turn off all stats (dataLayer, gtag, and CustomEvent).
HAS_STATS_ENHANCED
HAS_STATS_ENHANCEDDefault: Enhanced data is off (no constant = URL, text, and title are not sent).
Use: Set to
trueto allow sending URL, share text, and title in the payload.
Filters
Use these in your theme or plugin to override the constants or implement conditional logic.
has_stats_enabled
has_stats_enabledPurpose: Turn stats on or off for the frontend.
Default passed: Value from
HAS_STATS_ENABLEDif defined, otherwisetrue.Return:
trueto enable,falseto disable.
has_stats_enhanced
has_stats_enhancedPurpose: Allow or disallow sending URL, share text, and title (privacy-sensitive fields).
Default passed: Value from
HAS_STATS_ENHANCEDif defined, otherwisefalse.Return:
trueto send enhanced fields,falseto send empty strings for them.
Last updated
Was this helpful?