Skip to content

GET/sites/$site/stats/utm/$utm_param_name/top_posts

Fetch top posts for a given UTM parameter value.

Resource Information

   
Method GET
URL https://public-api.wordpress.com/rest/v1.1/sites/$site/stats/utm/$utm_param_name/top_posts
Requires authentication? No

Method Parameters

Parameter Type Description
$site (int|string) Site ID or domain
$utm_param_name (string)
utm_id:
(default) Stats for utm_id parameter
utm_source:
Stats for utm_source parameter
utm_medium:
Stats for utm_medium parameter
utm_campaign:
Stats for utm_campaign parameter
utm_term:
Stats for utm_term parameter
utm_content:
Stats for utm_content parameter
utm_source_platform:
Stats for utm_source_platform parameter
utm_creative_format:
Stats for utm_creative_format parameter
utm_marketing_tactic:
Stats for utm_marketing_tactic parameter
utm_source,utm_medium:
Stats for combinations of two UTM parameters: utm_source, utm_medium
utm_campaign,utm_source,utm_medium:
Stats for combinations of three UTM parameters: utm_campaign, utm_source, utm_medium

Query Parameters

Parameter Type Description
context (string)
display:
(default) Formats the output as HTML for display. Shortcodes are parsed, paragraph tags are added, etc..
edit:
Formats the output for editing. Shortcodes are left unparsed, significant whitespace is kept, etc..
http_envelope (bool)
false:
(default)
true:
Some environments (like in-browser JavaScript or Flash) block or divert responses with a non-200 HTTP status code. Setting this parameter will force the HTTP status code to always be 200. The JSON response is wrapped in an "envelope" containing the "real" HTTP status code and headers.
pretty (bool)
false:
(default)
true:
Output pretty JSON
meta (string) Optional. Loads data from the endpoints found in the 'meta' part of the response. Comma-separated list. Example: meta=site,likes
fields (string) Optional. Returns specified fields only. Comma-separated list. Example: fields=ID,title
callback (string) An optional JSONP callback function.
utm_param_values (string) Required. UTM parameter values for which to fetch breakdown by posts. When $utm_param_name contains comma this should be the string containing a json-encoded array.
max (int) The maximum number of results to return Default: 10.
date (string) the most recent day to include in results
days (int) number of days to include in the query Default: 1.

Response Parameters

Parameter Type Description
top_posts (array) Array of objects containing `id` (post id), `href` (link to post), `title` and `views` (how many times a post was opened with given UTM values).

Resource Errors

This endpoint does not return any errors.

Example

curl \
 -H 'authorization: Bearer YOUR_API_TOKEN' \
 'https://public-api.wordpress.com/rest/v1/sites/82974409/stats/utm/utm_source/top_posts?utm_param_values=%5B%22wordads%22%2C%22display%22%5D&days=7&date=2023-12-30'
<?php
$options  = array (
  'http' => 
  array (
    'ignore_errors' => true,
    'header' => 
    array (
      0 => 'authorization: Bearer YOUR_API_TOKEN',
    ),
  ),
);

$context  = stream_context_create( $options );
$response = file_get_contents(
	'https://public-api.wordpress.com/rest/v1/sites/82974409/stats/utm/utm_source/top_posts?utm_param_values=%5B%22wordads%22%2C%22display%22%5D&days=7&date=2023-12-30',
	false,
	$context
);
$response = json_decode( $response );
?>