I'm building a JS app using the youTube Analytics api and am struggling with this query. I want to filter by video and by country (so just return the views for that video in GB (in this case)).
The documentation suggests the following for a URL request...
A list of filters that should be applied when retrieving YouTube Analytics data. The Available Reports document identifies the dimensions that can be used to filter each report, and the Dimensions document defines those dimensions. If a request uses multiple filters, join them together with a semicolon (;), and the returned result table will satisfy both filters. For example, a filters parameter value of video==dMH0bHeiRNg;country==IT restricts the result set to include data for the given video in Italy.
But I need to write it in Javascript. Have tried the following but get a bad result.
var request = gapi.client.youtubeAnalytics.reports.query({
'start-date': datePublished,
'end-date': endDate,
ids: 'channel==' + channelId,
dimensions: 'video',
metrics: metric,
filters: 'video=='+videoId&&'country==GB',
});
Have also tried using 2 dimensions (video and country) - this method ignores video and just uses country. I think the problem is in the syntax on filters - any ideas?
Thanks
Will
From official documentation:
If a request uses multiple filters, join them together with a semicolon (;), and the returned result table will satisfy both filters.
For example, a filters parameter value of video==dMH0bHeiRNg;country==IT restricts the result set to include data for the given video in Italy.
Hence the js request should be something like:
var request = gapi.client.youtubeAnalytics.reports.query({
'start-date': datePublished,
'end-date': endDate,
ids: 'channel==' + channelId,
dimensions: 'video',
metrics: metric,
filters: 'video=='+videoId+';country==GB',
});