Google Data Studio connectors to fetch data from LinkedIn Marketing API.
There is a main connector called Core
: it retrieves and handles data to bring it properly for GDS and it also sets the authentication method.
Children connectors (like Company-followers) use Core functions and use specific functions they have 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
- Create a LinkedIn developer account
- Create an LinkedIn app
- When you're on your app overview, go to Products tab and add
Marketing Developer Platform
product - Go to Auth tab and set an
Authorized redirect URLs for your app
likehttps://access_token
. It will be useful to get back your access token - Take note of the Client ID and Client secret codes
- Execute this request to get a first token. You have to set
client_id
; if needed you could changescope
and changeredirect_url
to another redirect URL (that URL must match with the one set though step 4, and it must be encoded) - Execute this to get a 60 days token. You have to change
code
to the token you got step 6, setclient_id
andclient_secret
. If needed, changeredirect_url
like step 6 - Use the latter token to fill connector credentials
First, copy Company-followers
connector as template.
You can find the Marketing product documentation here.
Then you have 3 things to change:
- Change
endpoint
global var to the GET method you want and the parameters.
// core.gs
var endpoint = ['networkSizes/urn:li:organization:', '?edgeType=CompanyFollowedByMember'];
- Put fetchable fields from API
// fields.gs
function getFields(request) {
var fields = cc.getFields();
var types = cc.FieldType;
var aggregations = cc.AggregationType;
fields.newMetric()
.setId('LinkedIn_company_followers')
.setType(types.NUMBER); // BOOLEAN, NUMBER, ...
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 'LinkedIn_JSON_index_name':
rows.push(response.JSON_index_name);
break;
default:
break;
}
});
return rows.map(function(row) {
return { values: [row] };
});
}