Analytics query via the API
You can query your analytics by calling onto the Analytics Engine Read API and the Media Manager Query.
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
So we can perform query for video as follows.
WHERE
You can also add a WHERE
condition to your query.
Each separate WHERE
condition must be placed within {}
brackets.
For example
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
AND
CONDITION OPERATORS
Condition have their own operators and can have different formats depending on which operator you are using.
HAS
So say we wanted all analytics that has the meta data uid attached to it. This would be done as follows.
IS
This is like saying field = value
. So for example.
This would then return all analytics for videos that is a play action.
IS NOT
This is like saying field != value
. For example.
This would then return all analytics for videos that is not a play action.
GREATER THAN
This is like saying field > value
. For example.
This would return all analytics for videos that seq
field is greater than 1.
GREATER EQUAL THAN
This is like saying field >= value
. For example.
This would return all analytics for videos that seq
field is greater or equal than 1.
LESS THAN
This is like saying field < value
. For example.
This would return all analytics for videos that seq
field is less than 100.
LESS EQUAL THAN
This is like saying field <= value
. For example.
This would return all analytics for videos that seq
field is less or equal than 100.
IS LIKE
This is like saying field LIKE '%{VALUE}%'
. For example.
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.
or
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
.
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.
So for example:
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.
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).
Note
Either DESC
or ASC
has to be set.
Example. We want to get the top 10 most watched videos.