The Ooyala Analytics API provides a programmatic interface to retrieve data on various video and channel metrics. Each query requires a mode, date range, result granularity, and an output format. The two modes for the API are per-account level and per-video/channel. The account-level interface provides for queries such as "Top 50 played videos" and "Top 10 videos by time watched" on an account-wide basis. The content-level interface provides information on a specific video or channel and can include a variety of metrics explained in detail later in this document. Result granularity depends on the specific report but includes day, week, month, and total options. Output format options are XML, CSV, and JSON.
A flexible set of options that can be passed to the Analytics API for customized statistics.
Analytics API use cases with sample query strings and their results.
Detailed instructions on signing parameters to create a unique signature that is required for all analytics requests.
A Ruby reference for accessing analytics statistics.
There are four required parameters for a query (format, granularity, date, method) and a number of
optional parameters some of which depend on the query method.
When using a method of account.videoTotals, account.geoTotals, account.domainTotals, or
video.domainTotals, the result can have thousands of entries. To limit the result size we truncate at
500 entries and return a <nextPageID> element with a pointer to the next page of results. A nextPageID
of -1 indicates there are no further results.
When making a request using a video.* method, the video parameter is required. This parameter
accepts a single video embed code or multiple embed codes in a comma-separated list. The video parameter will be ignored
for any non-video.* methods.
today, yesterday, week (current week), month (current month) or all (account
lifetime or 2 years, whichever is less). granularity=day&date=last10), last
6 weeks (granularity=week&date=last6) or a range defined by two dates: YYYY-MM-
DD, YYYY-MM-DD xml, csv, json. day, week, month, total. account.videoTotals – Video summary for an account. Pageable.account.totals – Sum of all video statistics account-wide. account.geoTotals – Country-based statistics on viewership. Pageable. account.domainTotals – Domain-based statistics on viewership. Pageable. domain.totals – Statistics for a specific domain. Can be account-based or video-based. Include an
embed code for a specific video using the video parameter. video.totals – All stats for a given embed code. You can provide a maximum of 100 comma-
separated embed codes in the video parameter to query against. video.domainTotals – All statistics for a given video, grouped by domain. You can provide a
maximum of 100 comma-separated embed Codes in the video parameter. The limit parameter can be used to limit
the number of domains included in the result (500 is the max). The orderBy parameter
will order the list of domains returned. Pageable. video.behavioral – Detailed behavioral statistics, percentWatched and segmentWatched, for a
video. You can provide a maximum of 100 comma-separated embed codes in the video parameter. This method
includes counts for every 2.5% of the video watched, instead of every 25% as in
video.totals. Requires the fields parameter to include only percentWatched, segmentWatched
or a combination of the two separated by a comma. domain.totals method. Use the format domainname.gTLD (generic top-level domain) e.g., "ooyala.com"embedCode – Embed code of the content title – Title of the content displays – A display represents a video or channel being shown to the user, whether it's the
start screen or actual video content. XML field uniqueDisplays (unique per user) will also be returned if available (only for day, week, month) plays – A play represents a single video or channel being watched by the user. XML field uniquePlays (unique per user) will also be returned if available (only for day, week, month) replays – A replay represents a replay of a video after it has finished. XML field uniqueReplays (unique per user) will also be returned if available (only for day, week, month) timeWatched – video delivery time in hours accurate to 2 decimal points percentWatched – Percentage of the video, accurate to 2.5%, that has been watched on a given play of a video or channel. Each bucket holds the count of users who watched N%. Replays and rewatching of the same slice of the video multiple times are ignored. Only applicable to video.behavioral queries
segmentWatched – The count of "segments watched at N%" represents the number of times that the user watched the segment at N%. Every time a particular bucket is re-watched, even on the same play, the bucket will be reported again. Only applicable to video.behavioral queries contentType – Type of content to include in the result. One of video, channel, channelSet.account.videoTotals
queries. The default is 500 value,[asc|desc] e.g., "displays,asc" video, channel, channelSet.
Only applicable to queries using the account.videoTotals method. Query for displays, plays, and timeWatched for a specific video from August 18 to 19, 2008:
http://www.ooyala.com/api/analytics?pcode=<pcode>date=2008-08-18%2C2008-08-19&expires=<expiration>&fields=displays%2Cplays%2CtimeWatched&format=xml&granularity=day&limit=2&method=video.totals&video=<embedCode>&signature=<signature>
Result:
<result>
<video>
<embedCode>A5bjM6ugP5LWOxnmXxgk6fjJ22Kn36dw</embedCode>
<day>
<date>2008-08-18</date>
<displays>143</displays>
<uniqueDisplays>122</uniqueDisplays>
<plays>104</plays>
<uniquePlays>96</uniquePlays>
<timeWatched>16542.00</timeWatched>
</day>
<day>
<date>2008-08-19</date>
<displays>185</displays>
<uniqueDisplays>147</uniqueDisplays>
<plays>123</plays>
<uniquePlays>87</uniquePlays>
<timeWatched>21846.00</timeWatched>
</day>
</video>
</result>
Example:
Query for domain information, from July 1, 2008 to September 1, 2008, limited to the top two embed domains:
http://www.ooyala.com/api/analytics?pcode=<pcode>date=2008-07-01%2C2008-09-01&expires=<expiration>&format=xml&granularity=total&limit=2&method=account.domainTotals&signature=<signature>
Result:
<result>
<account>
<domain>
<name>example.org</name>
<displays>104</displays>
<plays>46</plays>
<replays>23</replays>
<timeWatched>1.86</timeWatched>
</domain>
<domain>
<name>example.net</name>
<displays>2</displays>
<plays>2</plays>
<replays>0</replays>
<timeWatched>0.00</timeWatched>
</domain>
</account>
</result>
Example:
Query for account-wide country data since the beginning of the month, limited to the top 40 countries,
ordered by timeWatched, decending, with output in csv:
http://www.ooyala.com/api/analytics?pcode=<pcode>&date=month&expires=<expiration>&format=csv&
granularity=total&limit=40&method=account.geoTotals&orderBy=timeWatched%2Cdesc&signature=<signature>
Result:
code,name,displays,plays,replays,timeWatched
US,United States,25127,10752,2791,129.57
TR,Turkey,3446,2130,90,21.05
GB,United Kingdom,2703,1504,441,14.93
DE,Germany,1653,766,178,9.91
CA,Canada,1229,594,159,8.31
BR,Brazil,819,472,74,6.09
FR,France,833,432,97,5.39
JP,Japan,745,329,87,4.90
MX,Mexico,510,265,48,4.45
IT,Italy,830,408,63,4.22
RU,Russian Federation,655,358,39,4.05
NL,Netherlands,622,312,68,3.66
AU,Australia,584,311,94,3.54
CN,China,375,197,67,2.89
CH,Switzerland,357,164,36,1.92
PL,Poland,225,144,42,1.78
SE,Sweden,322,148,27,1.61
AR,Argentina,191,110,28,1.59
HK,Hong Kong,206,94,13,1.19
TW,Taiwan,186,90,10,1.18
LV,Latvia,95,56,21,0.80
GR,Greece,92,55,21,0.75
TH,Thailand,65,44,21,0.72
ZA,South Africa,79,36,14,0.66
BE,Belgium,130,70,18,0.64
UA,Ukraine,63,33,12,0.64
NZ,New Zealand,107,55,13,0.55
Example:
Query for all behavior-related viewership data for one video over the account lifetime. Fields percentWatched, and segmentWatched are outputted in xml:
http://api.ooyala.com/api/analytics?pcode=<pcode>&date=all&expires=<expiration>&fields=percentWatched,segmentWatched&format=xml&granularity=total&limit=1&method=video.behavioral&video=<embedCode>&signature=<signature>
Result:
<result>
<video>
<embedCode>kxYm06gFKXEleIHdyXNKeefx-QAu2yVp</embedCode>
<title>how_to_fold_a_T_shirt.wmv</title>
<percentWatchedCounts>
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1
</percentWatchedCounts>
<segmentWatchedCounts>
2,4,4,3,3,3,3,3,3,3,3,3,2,2,2,2,2,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2
</segmentWatchedCounts>
</video>
</result>
Example:
Query for video totals across the account over the account lifetime and outputted in json:
http://api.ooyala.com/api/analytics?pcode=<pcode>&date=month&expires=<expiration>&format=json&granularity=total&method=account.videoTotals&signature=<signature>
Result:
{"account": {"video": [{"embedCode": "kxYm06gFKXEleIHdyXNKeefx-QAu2yVp", "title": "how_to_fold_a_T_shirt.wmv", "displays": 2, "plays": 2, "replays": 1, "timeWatched": "0.02", "pw25": 2, "pw50": 2, "pw75": 2, "pw100": 1}]}}
API queries are required to be signed in order to ensure account security. We present these steps as an example of generating a signed API request. The query produced in this example is valid and illustrates how to compose and sign a qualified request. A detailed signing example is available here
Account-specific codes for Provider ID (pcode) and Secret (secret) can be found in Backlot Account tab under Developers. The pcode is 28 characters long, and the Secret Code is 40 characters long. Both are case sensitive and include alphanumeric characters, dashes (-), and underscores (_). These codes are required to generate a signature for each request to and from the Ooyala servers.
Partner Code:Note: These parameters point to a shared account accessible via API to any Backlot partner for preliminary testing. Content and metadata uploaded to this account is visible to all users.lsNTrbQBqCQbH-VA6ALCshAHLWrVSecret Code:hn-Rw2ZH-YwllUYkklL5Zo_7lWJVkrbShZPb5CD1
The pcode, secret code, all required parameters, and all included optional parameters are used to generate a SHA-256 signature for the call. We present this example on how to generate a signature and URI-encode the parameters for the call.
hn-Rw2ZH-YwllUYkklL5Zo_7lWJVkrbShZPb5CD1<name>=<value> pairs to the string. The SHA-256 signature is generated with the result, which does not include the pcode.This example uses date=all, format=xml, granularity=day, and method=account.totals.
hn-Rw2ZH-YwllUYkklL5Zo_7lWJVkrbShZPb5CD1date=allexpires=4102448461format=xmlgranularity=daymethod=account.totalsuyKVgVILbgPOgp3ly5jU5NVRQsx2qaIoz%2FesiqyCJwYhttp://www.ooyala.com/api/analytics? and the Partner Code from the Developers area of your Backlot Account tab. Append the query parameters in alphabetic order, separated with & and end with signature=<signature> to include the digest computed in Step 3.
Note: All parameters must be URI-escaped before being added to the query. Parameters should be URI-escaped in the query, not when generating the signature.
http://api.ooyala.com/api/analytics?pcode=lsNTrbQBqCQbH-VA6ALCshAHLWrV&date=all&expires=4102448461&format=xml&granularity=day&method=account.totals&signature=uyKVgVILbgPOgp3ly5jU5NVRQsx2qaIoz%2FesiqyCJwYrequire "rubygems"
require "base64"
require "cgi"
require "digest/sha2"
require "open-uri"
module Ooyala
module Analytics
module API
# You can find your partner and secret code under the "Account > API Settings"
# subtab in Backlot.
OOYALA_PARTNER_CODE = "<Your Partner Code>"
OOYALA_SECRET_CODE = "<Your Secret Code>"
def self.query(params)
return send_request("analytics", params)
end "method" => "account.geoTotals",
private
def self.send_request(request_type, params)
# Add an expire time to the query if one was not provided
params["expires"] ||= (Time.now.to_i + 900).to_s
string_to_sign = OOYALA_SECRET_CODE
url = "http://www.ooyala.com/api/#{request_type}?pcode=#{OOYALA_PARTNER_CODE}"
params.keys.sort.each do |key|
string_to_sign += "#{key}=#{params[key]}"
url += "&#{CGI.escape(key)}=#{CGI.escape(params[key])}"
end
digest = Digest::SHA256.digest(string_to_sign)
signature = Base64::encode64(digest).chomp.gsub(/=+$/, "")
url += "&signature=#{CGI.escape(signature)}"
return open(url).readlines
end
end
end
end
augVideoData = Ooyala::Analytics::API::query(
"date" => "2008-08-18,2008-08-19",
"fields" => "displays,plays,timeWatched",
"format" => "xml",
"granularity" => "day",
"limit" => "2",
"method" => "video.totals",
"video" => "A5bjM6ugP5LWOxnmXxgk6fjJ22Kn36dw")
domainVideoInfo = Ooyala::Analytics::API::query(
"date" => "2008-07-01,2008-09-01",
"format" => "xml",
"granularity" => "total",
"limit" => "2",
"method" => "account.domainTotals")
accountTop40Countries = Ooyala::Analytics::API::query(
"date" => "month",
"format" => "xml",
"granularity" => "total",
"limit" => "40",
"orderBy" => "timeWatched,desc",
"output" => "csv")