Google Data Studio connectors to fetch data from YouTube Data API.
There is a main connector called Core
: it retrieves and handles data to bring it properly for GDS and it sets the authentication method.
Children connectors (like Channels-data) use Core functions and also use specific functions for their API endpoint.
- Go to Google Apps Script
- Create a new project
- Name it
- Go to project settings
- Check
Display appsscript.json manifest file
- Take note about Script ID (useful for children connectors)
- Go back to code window
- Create files and set code for Core connector
- Go to Google Apps Script
- Create a new project
- Name it
- Go to project settings
- Check
Display appsscript.json manifest file
- Go back to code window
- Create files and set code for the child connector
- In
appsscript.json
, changeDependencies
>Libraries
>LibraryID
to the Core script ID you took note - Deploy it (easiest by going through
Use old editor
button >Publish
>Publish from manifest file
)
- Go to Google Data Studio
- Create > Data source
- Search for your deployed child connector
- Fill credentials
- Now you can import it in your GDS reports
- Check this video
- Use API key to fill your connector credentials
First, copy Channels-data connector as template.
You can find the documentation here.
Then you have 4 things to change:
- Change
endpoint
global var to the GET method you want.
// core.gs
var endpoint = 'channels';
- Change
fields
array items: fields can be found in each endpoint list page > Parameters section >part
required parameter.
// core.gs
var fields = ['brandingSettings','contentDetails','contentDetails','id', ...];
- Put fetchable fields from API
// fields.gs
function getFields(request) {
var fields = cc.getFields();
var types = cc.FieldType;
var aggregations = cc.AggregationType;
fields.newDimension()
.setId('YouTube_Data_Channels_id')
.setType(types.TEXT); // BOOLEAN, TEXT, ...
fields.newDimension()
.setId('Users-followers_field_example')
.setType(types.TEXT); // BOOLEAN, NUMBER, ...
// put all fetchable fields
return fields;
}
- Handle each data row
// dataHandler.gs
function responseToRows(requestedFields, response) {
var rows = new Array();
var fields = requestedFields.asArray();
// Filter for requested fields
fields.forEach(function (field) {
switch (field.getId()) {
case 'YouTube_Data_Channels_field_example':
rows.push(response.field_example);
break;
default:
break;
}
});
return rows.map(function(row) {
return { values: [row] };
});
}