Skip to content

Analytics query via the API

You can query your analytics by calling onto the Analytics Engine Read API and the Media Manager Query.

GET - /api/v1/analytics/{query}/{from}/{to}

DATE RANGE

You must pass a date range in the form of two dates. A from date and a to date. The format of the date can be in most formats as long as the date is valid. Some example of date formats are as follows.

  • 01 July 2015
  • 2015/01/02
  • 2015-01-02

SHOW

Show is the first part of query

SHOW [type]

So we can perform query for video as follows.

SHOW video

WHERE

You can also add a WHERE condition to your query.

WHERE {CONDITION}

Each separate WHERE condition must be placed within {} brackets.

WHERE {[OPERATOR|FIELD] [OPERATOR|VALUE] [VALUE]}

For example

SHOW video WHERE {action IS play}

CONDITION

A condition is made up of multiple parts (depending on type of condition). Conditions are combined with logical operators like AND, OR.

LOGICAL OPERATORS

There are only two types of logical operators for Media Manager Query.These are used when combining conditions.

Important

The order in which the logical operators appear can greatly affect the results

OR

SHOW {TYPE} WHERE {[FIELD] [OPERATOR] [VALUE]} OR {[FIELD] [OPERATOR] [VALUE]}

AND

SHOW {TYPE} WHERE {[FIELD] [OPERATOR] [VALUE]} AND {[FIELD] [OPERATOR] [VALUE]}

CONDITION OPERATORS

Condition have their own operators and can have different formats depending on which operator you are using.

HAS

{HAS [FIELD]}

So say we wanted all analytics that has the meta data uid attached to it. This would be done as follows.

SHOW video WHERE [HAS events.uid]

IS

{[FIELD] IS [VALUE]}

This is like saying field = value. So for example.

SHOW video WHERE {action IS play}

This would then return all analytics for videos that is a play action.

IS NOT

{[FIELD] IS NOT [VALUE]}

This is like saying field != value. For example.

SHOW video WHERE {action IS NOT play}

This would then return all analytics for videos that is not a play action.

GREATER THAN

{[FIELD] GREATER THAN [VALUE]}

This is like saying field > value. For example.

SHOW video WHERE {seq GREATER THAN 1}

This would return all analytics for videos that seq field is greater than 1.

GREATER EQUAL THAN

{[FIELD] GREATER EQUAL THAN [VALUE]}

This is like saying field >= value. For example.

SHOW video WHERE {seq GREATER EQUAL THAN 1}

This would return all analytics for videos that seq field is greater or equal than 1.

LESS THAN

{[FIELD] LESS THAN [VALUE]}

This is like saying field < value. For example.

SHOW video WHERE [seq LESS THAN 100]

This would return all analytics for videos that seq field is less than 100.

LESS EQUAL THAN

{[FIELD] LESS EQUAL THAN [VALUE]}

This is like saying field <= value. For example.

SHOW video WHERE {seq LESS EQUAL THAN 100}

This would return all analytics for videos that seq field is less or equal than 100.

IS LIKE

{[FIELD] IS LIKE [VALUE]}

This is like saying field LIKE '%{VALUE}%'. For example.

SHOW video WHERE {title IS LIKE bacon}

This would return video analytics that had meta title similar to bacon. (That could mean all kinds of things). Can very much be used like a search.

VALUES

The value within each condition can be pretty much anything you want, this is because you can attach any meta data you want and therefore can query that meta data.

DATES

You can use dates within the Query.

SHOW video WHERE {action is play} AND {created IS 12th Nov 2013}

or

SHOW video WHERE {action is play} AND {created GREATER THAN 12th Nov 2013}

Note

The format of the date can be pretty much any of the possible formats, as long as its a valid date.

If querying updated, created fields. You can pass it in a number of formats, but the most useful is being able to pass a UNIX TIMESTAMP.

{updated GREATER THAN 1391439052}

So we may want to get all logs that have been updates since a given time (02 / 03 / 14 @ 2:50:52pm UTC as above).

COMMA SEPARATED VALUES

Sometimes you may want to check if a field is one of many values. This can be done by using a , to separate them.

{[FIELD] [OPERATOR] ([COMMA SEPARATED VALUES])}

So for example:

SHOW video WHERE {action IS (play,share)}

The comma separated values need to be within () brackets. These are considered "Action Brackets".

LIMIT

You can also LIMIT the results returned by using the LIMIT operator.

SHOW video WHERE {action IS play} AND {created LESS THAN 20 Nov 2013} LIMIT 1

Results above will be limited to 1.

Note

The position of the limit can be anywhere within the where part of the query, but usually placed at the end is good practice.

SORTING

You can sort by any of the fields returned by the API. So depending on your query you can sort pretty much anything. The sort should be placed within the WHERE part of the query (even if you do not have where conditions).

SORT BY [FIELD] [ASC|DESC]
SHOW video WHERE SORTED BY action DESC

Note

Either DESC or ASC has to be set.

Example. We want to get the top 10 most watched videos.

SHOW video WHERE {action IS play} LIMIT 10 SORT BY events.secondsWatched DESC