mainwp-google-analytics category. Use them to inspect saved connections and GA4 properties, read aggregate analytics, change mappings and refresh settings, and request background refreshes.
Earlier Google Analytics builds may not register these abilities. Discover the category on your Dashboard before using the examples. A version number alone does not establish that your installed build includes this API.
What You’ll Learn
- Read connections, properties, site mappings, and cached aggregate analytics
- Preview and confirm mapping and refresh-policy changes
- Request a background refresh and check its outcome
- Handle revisions, repeat requests, and uncertain results
Prerequisites
- WordPress 6.9 or later on the MainWP Dashboard site
- MainWP Dashboard with Abilities API support; use version 6.2 or later for the
input_jsonexamples - An active Google Analytics build that registers these abilities
- An authenticated user permitted by the Dashboard Abilities API, with access to the Google Analytics Add-on
- A configured Google connection for property mapping and refreshes
- Working Dashboard scheduled tasks for background refresh jobs
manage_options. Site calls also require the edit_sites Dashboard permission, access to the selected site, and a connected Child site. Team Control restrictions apply. Refresh-status reads require Add-on access and either ownership of the job or manage_options.
Available Abilities
The replacement abilities use DELETE, including for previews, because they are marked destructive and idempotent. They change Dashboard mappings, settings, and cached data; they do not delete Google Analytics properties.
Discover the full input and output schemas for your installed build:
Request Rules
Send read inputs in theinput_json query parameter. For DELETE and POST calls, send a JSON body containing an input object. Unknown fields are rejected. Use JSON booleans for flags.
Site calls use site_id_or_domain, which accepts a MainWP site ID or exact domain. Connection references, property references, and revisions are opaque 64-character hexadecimal strings. Read them from the API; do not substitute Google account IDs or property IDs.
Mapping and policy replacements require the latest resource revision as if_match. Obtain it from the mapping or policy read for that resource.
Every replacement and refresh request also requires these fields:
Review the preview before executing. Keep the same target, desired values, revision, and request UUID. An expired token or changed revision requires a fresh read and preview. Reuse the original UUID and payload when recovering the response to the same execution; use a new UUID for new work. A request-reference conflict is not permission to submit changed work under the old UUID.
The repeated
a and b strings below are fictional references. Replace them with returned values, and generate your own request UUIDs.
List Connections and Properties
List stored connections:
Both lists default to 50 rows and accept a
limit from 1 to 100. Filters and cursors default to null. The connection status filter accepts connected, needs_reauthorization, credential_unavailable, no_properties, or disabled. The property mapped filter accepts true, false, or null.
When truncated is true, pass the returned next cursor into the corresponding after_* field to continue.
Connection entries include connection_ref, label, method (oauth or service_account), status, property_count, mapped_site_count, last_catalog_refresh_at, and revision. Property entries include property_ref, connection_ref, label, account_label, mapped_site_count, and revision.
These reads do not contact Google or return credentials. Use the returned property reference when changing a mapping.
Read and Replace a Site Mapping
Read the mapping:site_id, status (unmapped, mapped, or stale), property_ref, connection_ref, property_label, cache_status, cache_generated_at, and revision. Cache status is none, fresh, stale, or malformed.
Preview a replacement using the current mapping revision and a property reference from the catalog:
property_ref to null to remove the mapping. Every field in this example is required.
The response contains mode (dry_run or applied), site_id, changed, cache_invalidated, mapping, and preview_token. After reviewing the preview, send the same input with the returned token, dry_run: false, and confirm: true. A changed mapping can invalidate that site’s cached analytics. Read its state again before relying on previous figures.
Read Cached Analytics
Callmainwp/get-site-google-analytics-observation-v1 with a required site_id_or_domain and optional include_daily (default false):
site_id, availability, period, generated_at, stale, current, previous, daily, and revision.
availabilityisunmapped,no_cache,available,stale, ormalformed.periodisweek,month, ornullwhen unavailable.- Available period metrics contain
sessions,active_users,new_users,page_views,pages_per_session,bounce_rate(percentage), andaverage_engagement_seconds. Unavailable metric objects can benull. - Daily data contains at most 31 points with UTC calendar dates, active users, new users, page views, and average engagement seconds.
Read and Replace Refresh Policy
mainwp/get-google-analytics-refresh-policy-v1 takes no input. It returns report_period, auto_refresh, refresh_hours, scheduler_mode, schedule_state, refresh timestamps, and revision.
To call mainwp/replace-google-analytics-refresh-policy-v1, use DELETE with the following required input object wrapped in {"input":{...}}:
report_period accepts week or month. refresh_hours accepts 1, 3, 9, 15, 18, or 24. Use the policy read’s revision for if_match, then follow the preview and confirmation rules above.
The response contains mode, changed, schedule_changed, caches_invalidated, policy, and preview_token. Changing policy can invalidate cached observations. The policy reports scheduler_mode as wordpress, external, or disabled, and schedule_state as scheduled, unscheduled, or drifted. Inspect the actual schedule state after changing settings.
Request and Track a Refresh
Callmainwp/request-google-analytics-refresh-v1 with POST. Preview a site-cache refresh using this input:
kind to connection_catalog, supply the returned connection_ref, and omit site_id_or_domain or set it to null. A site-cache refresh requires a mapped site and omits connection_ref or sets it to null. Both require a usable connected Google account.
Review the preview, then confirm using its token and the same target and request UUID. The response contains mode (dry_run or queued), job_id, request_id, kind, target, status (ready or requested), requested_at, and preview_token. Preview responses have no queued job.
A queued response is not completion. Pass its job_id as job_ref to mainwp/get-google-analytics-refresh-status-v1:
job_id, kind, target, status, phase, attempts, result, and request/update/completion timestamps.
The result reports property counts added, updated, and removed, mappings invalidated, whether the cache was updated, a result revision, and a coarse outcome code.
If a response is lost, resend the same logical request with the same
request_ref and payload to recover its existing job receipt. A different target under that UUID returns a conflict. Poll the recovered job rather than creating a duplicate. Completed job history is retained for 30 days; do not treat request references as permanent deduplication keys.
Error Handling
Errors use themainwp_google_analytics_ prefix. WordPress may return authentication, schema, or method errors before the Add-on runs.
For encryption-key recovery, account reconnection, and Dashboard refresh settings, see the Google Analytics guide.
Related Resources
- Abilities API Overview - Authentication, input handling, and discovery
- Google Analytics - Connect accounts and review visitor data
- Google Search Console Abilities - Separate search-performance integration
