Analytics - API Quickstart
In this tutorial we’ll get you up and running to make your first analytics calls.
Note that you can try analytics calls using the Analytics Console tool before you write any code.
Before you start
Take a look at the Platform Overview guide to understand the key concepts of the Meltwater platform.
To run through this tutorial, you will need:
- Your Meltwater API token
- A Saved Search in your Meltwater App account
Authentication
You need to provide your API token when you call any Meltwater API endpoint.
You provide the API token as a header called apikey
, for example:
For full details take a look at the Authentication page.
Obtaining a Meltwater search
Exports are created with an existing Meltwater search.
In this tutorial we’ll cover using an existing search, but you can create / edit searches using the API. See the Managing Saved Searches guide for more details.
To create an export you need to provide the id
of the required search. You can use the GET /v3/searches
endpoint to list your current searches:
Example response:
Analytics options
The API supports two types of earned analytics features:
- Pre-defined analytics - individual endpoints for common analytics, such as top keywords, sentiment breakdown and number of mentions
- Custom analytics - go beyond pre-defined analytics options by combining measures, dimension and analysis types to meet your needs
Pre-defined analytics
You can use our endpoints for pre-defined analytics to access common analysis needs.
In this guide we’ll call the analytics summary endpoint, but each analytics endpoint is called in a similar way. The full list of analytics endpoints can be found on the analytics options page.
The summary analytics endpoint returns the following analytics for a search:
- Volume - The total number of documents matching our search as well as providing an average for per day and per hour.
- Sentiment - Breakdown of the sentiment i.e. positive or negative for the documents returned by the search.
- Top Countries - Breakdown of countries where the document originated.
- Top Languages - Breakdown of languages for the documents matched.
- Time Series - A detailed breakdown by day, by hour of when the documents were created.
Analytics parameters
When calling an analytics endpoint you need to provide:
start
andend
- the time period you’d like to analyze (ISO8601 timestamps, excluding timezone/offset). Note that the analysis will be inclusive of the start time and exclusive of the end time.tz
- An identifier from the IANA TimeZone Database (tzdb), or a timezone offset, from UTC.
You can also optionally specify a number of additional filters including:
source
- the source(s) you’d like to analyze, for examplenews
orblogs
. If not provided, your request will analyze all sources. You can provide multiple values to analyze across multiple sources.language
- A primary language subtag from the IANA language tag registry, ‘zh-Hant’, ‘zh-Hans’ or ‘zz’.country
- The two-letter ISO 3166-1 Alpha-2 country code, or ‘ZZ’.
Note that the period you can analyze depend on your Meltwater API package. See the Usage Limits page for more details.
Each analytics endpoint has its own list of required fields. For a full list see the endpoints documentation.
Example Request
To fetch the summary analytics you call the GET https://api.meltwater.com/v3/analytics/<search_id>
endpoint.
Example response:
Custom analytics
You can go beyond pre-defined analytics options using the custom analytics feature. This feature allows you to choose an analysis type, and then choose measures and dimensions to meet your need.
For every analysis you will need to specify an analysis type. Depending on the analysis type you choose you may need to specify a dimension and a measure.
Parameters
When calling the custom analytics endpoint you need to provide:
start
andend
- the time period you’d like to analyze (ISO8601 timestamps, excluding timezone/offset). Note that the analysis will be inclusive of the start time and exclusive of the end time.tz
- An identifier from the IANA TimeZone Database (tzdb), or a timezone offset, from UTC.
You can also optionally specify a number of additional filters including:
source
- the source(s) you’d like to analyze, for examplenews
orblogs
. If not provided, your request will analyze all sources. You can provide multiple values to analyze across multiple sources.language
- A primary language subtag from the IANA language tag registry, ‘zh-Hant’, ‘zh-Hans’ or ‘zz’.country
- The two-letter ISO 3166-1 Alpha-2 country code, or ‘ZZ’.
For example to run an analysis from the 1st to the 14th of February 2024, using UTC timezone, and filtered to content in English only:
Note that the period you can analyze depend on your Meltwater API package. See the Usage Limits page for more details.
Analytics types
The API supports the following analysis types:
document_count
- The total number of documents (or mentions)count_unique
- The unique number of items based on a dimension, for example the unique number of countriestop_terms
- Breaks down mentions by a dimension, for example by sentimentdate_histogram
- Breaks down mentions by date, for example by day or monthmeasure_statistic
- Returns the total (sum), average, minimum, maximum for one or more measurements
Note that top_terms and date_histogram support nested top_terms analysis for more advanced breakdowns.
Supported measures and dimensions
See the analytics options page for details of which measures and dimensions are supported.
Document count analysis
Use the document_count
analysis type to get the total number of documents.
For example, this request returns the total number of documents for a two week period:
The response from the API will look as follows:
Here the document_count
field in the response is your analysis result.
Count unique analysis
Use the count_unique
analysis type to get a count of unique values for a dimension.
For example, this request returns the count of unique countries where mentions occur for the search:
The response from the API will look as follows:
Here the analysis
field in the response is your analysis result.
Top terms analysis
Use the top_terms
analysis type to get a breakdown of documents by a dimension.
For example, this request returns the number of documents broken down by the shared_link
dimension, essentially it returns the top links shared within documents that match your search:
Note you can use the limit
parameter to control how many results you want in the breakdown. This parameter defaults to 10, and has a maximum value of 100.
The response from the API will look as follows:
The API returns a breakdown by your chosen dimension returning the top results, each with the number of documents for that value, and what percentage of the documents for your search and time window match that result.
Date histogram analysis
Use the date_histogram
analysis type to get a breakdown of documents over time.
For example, this request returns the number of documents broken down by day:
The granularity
parameter supports the following options:
hour
- supported for time windows of up to 7 daysday
- supported for time windows of up to 30 daysweek
- supported for time windows of up 1 yearmonth
- supported for time windows of up to 1 year
The response from the API will look as follows:
The API returns a breakdown by your chosen time granularity. For each time slice the API tells you the number of documents, and what percentage of the documents for your search and time window are in that period.
Measure statistic analysis
Use the measurement_statistic
analysis type to get the total (sum), average, minimum and maximum value for a measurement.
For example, this request returns statistics for reach:
You can provide up to 3 measures for this analysis.
The response from the API will look as follows:
For each measure requested the API returns the average (mean) value, maximum value, minimum value and total value, for documents that match your requested search and time window.
Date histogram with nested top terms analysis
The date_histogram
analysis type supports top_terms
as a nested analysis option.
For example the following request fetches the top shared links, for each day in a two week period:
The response from the API will look as follows:
The API returns a breakdown by your chosen time granularity. For each time slice the API provides a breakdown of your chosen dimension, providing the number of documents for the dimension value, and what percentage of the documents for your search and time window are in that period and match the dimension value.
Top terms with nested top terms analysis
The top_terms
analysis type supports top_terms
as a nested analysis option so that you can perform a 2-level breakdown.
For example, this request would fetch the top shared links, and the language of the documents they are shared within:
Note you can use the limit
parameter to control how many results you want in the breakdown. This parameter defaults to 10, and has a maximum value of 100.
The response from the API will look as follows:
The API returns a breakdown by your chosen top-level dimension, then further breaks this result down by your second-level dimension. Note that the percentage in the 2nd level of analysis compares the number of matching documents for that key with the number of documents for the parent key.