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):

Channel
Purpose

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

Context
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)

Field
When populated
Description

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

Parameter
When populated
Description

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:share

  • Target: window

  • Options: { bubbles: true, cancelable: false }

  • Payload: The same payload as dataLayer is in event.detail (camelCase). When enhanced is off, hasShareText, hasSharePostUrl, and hasSharePostTitle are empty strings.

Property
Type
Description

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

  • Default: Stats are enabled (no constant = tracking on).

  • Use: Set to false to turn off all stats (dataLayer, gtag, and CustomEvent).

HAS_STATS_ENHANCED

  • Default: Enhanced data is off (no constant = URL, text, and title are not sent).

  • Use: Set to true to 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

  • Purpose: Turn stats on or off for the frontend.

  • Default passed: Value from HAS_STATS_ENABLED if defined, otherwise true.

  • Return: true to enable, false to disable.

has_stats_enhanced

  • Purpose: Allow or disallow sending URL, share text, and title (privacy-sensitive fields).

  • Default passed: Value from HAS_STATS_ENHANCED if defined, otherwise false.

  • Return: true to send enhanced fields, false to send empty strings for them.

Last updated

Was this helpful?