Building your Custom Connector on Google Data Studio

Building your Custom Connector on Google Data Studio

Disclaimer – This is going to be a slightly technical post. If code scares you, then I’d suggest you skip this one. However, if data excites you, read on fellow adventurer!

When Google launched Google Data Studio, I had written an in-depth post about how one can create dashboards in Data Studio and some of the easy to use dashboard templates that Data Studio has to offer. As the product evolved, one of the most powerful features that this product had to offer was the ability to create custom data connectors to your own datasets.

What does a custom connector do?

A custom connector enables a user to access their own data source within Google Data Studio. Let’s take an example of a marketing research associate who wants to present her findings. One approach she could use would be to put all that data in Google Sheets, and then use one of the in-built connectors.

However, what would she do if her data set was large and does not fit in Google Sheet or Excel? Or if her data set included multiple surveys which are inter-related to each other?

What if this data was in a database, or available as an API? This is where the custom connector for Google Data Studio works.

I wrote my first connector a year back, and I had to do some digging around. I thought that I should pen down my notes so that more people can do this much more easily. Here are my notes for the same.

Building a custom connector

Before you jump into the implementation bit, know that this is based in JavaScript and you need to be comfortable with Google App Scripts. It’s okay if you do not know this, but JavaScript is a must.

Google has official documentation on the developer site of how to build a Community Connector, this is a pretty good resource to start. It has a step by step video and instruction guide as well.

Let’s look into what makes different parts of a connector, here is a link to a sample connector code on Github.

Community Connector sections

Each community connector is a separate Google Apps script that you deploy using Google App scripts. The connector is in itself made of the following sections –

  • Configuration section – This is to flesh out all the meta information about the community connector. Use this section to take any inputs from the user e.g API Secret and key if you don’t wish to store this in your code.
  • Authentication section – This is to authorize the app script. If your data is lying behind a secure mechanism, then use this section to authorize the script to access the data. This supports OAuth2 as well.
  • Schema section – This is used to define the structure to the data you are importing into Data Studio. Use this section to outline which fields and what data types are they. You can also add more information on what kind of aggregation do you want this field to be have (Sum, Average, Min, Max, etc).
  • Data section – This section is used to fetch the data that you are importing. Use this section for data validations or if you want to do any last minute data tweaks (e.g date conversions from string to date).

That’s all there is to it. Now, let us get into the actual flow of the script.

Connector code flow

When you are writing your connector, be sure to go through the developer reference first. In your script, you will have to include the following functions –

  1. getConfig() – this returns the configurable user options for the connector, this will be shown to the user when the user is adding the connector to their Google Data Studio accounts.
  2. getAuthType() – this is the function which is used to check if any authentication is required. If OAuth is set, then the community connector interface would check for the OAuth details
  3. getSchema() – this returns the schema of the data that is being access, this will be shown to the user when the data is being explored (where we can see the dimensions and metrics).
  4. getData() – this is the function which is used to access the data, the data format that is expected is outlined here. Normally, it is advised that the programmer write a separate function for fetching the data, a post processing function for setting up the return values, and finally call those in the correct order in this function.

Do note, that these functions will be called in the same order as they are listed. As long as you have these functions in your code, you have a functioning connector. Once you have this, you will have to deploy the code.

That’s it. Now, add this community connector to your Google Data Studio account, and make the reports you want to!

Using Data Studio to create beautiful Reports

In the month of November 2016, Data Studio was made available for all users in India. The product was launched quite some time back, however, it was only accessible in the US and for premium Google Analytics 360 users.

However, as of today, anyone can use Google Data Studio to create dazzling reports that can be shared with teams and clients.

So how does one go about creating awesome reports?

That’s where Data Studio shines, it allows users to create one template which can be utilized across multiple data sources. I tried to create a quick report using one of the default templates provided, here’s a step by step guide onĀ using Data Studio to create reports.

An update: As of 2nd Feb 2017, Data Studio has been declared a free product for everyone to use.

Adding a Data Source

First, we need to add our data source (in this case my site’s Google Analytics account) to the Data Studio.

Choose the Data Source menu from the Dashboard
Choose the Data Source menu from the Dashboard

Once you click on the menu, you would be directed to a screen listing all the data sources that you have added to your account.

Note, by default Google keeps some data sources in your account, so that one can practice on the product before moving on to your own data sources.

List of Data Sources
List of Data Sources

As all Google products, you can see the clear use of Material Design in this interface. Use the blue floating action button at the bottom right of your screen to add your own custom data source.

Connecting GA as Data Source
Connecting GA as Data Source

As the screenshot above shows, that most of the Google products can easily be integrated to this product. What’s more you can even use a MySQL database or a Google Spreadsheet (Excel ahoy!).

So, I could do most of my number crunching in existing styles, and use this tool only as a slick presentation layer.

After I press connect, this GA property of my site is now added to Data Studio as a source of data.

The minute you choose the right property, you would see all the dimensions and metrics that Google Analytics has. This is a pretty exhaustive list and you can import most of these into Data Studio.

GA Fields Imported as Dimensions and Metrics
GA Fields Imported as Dimensions and Metrics

Now that the important fields are linked (do check the respective fields you want to pull), we can go on to using a report template.

List of my Data Sources
List of my Data Sources

The screenshot shows the recently added data source. Great! We are all set to creating awesome reports!

Using Report Templates

We would be using the Acme Marketing template that’s there in the account. It broadly shows basic user level data in one simple report.

Keep in mind that Data Studio reports can span across multiple pages, but for this guide we are sticking to a one-pager.

Go back to your dashboard and choose the Acme Report template.

Acme Data Studio Template
Acme Data Studio Template

Click on the Use Template button, and now this is the most important point when it comes to using Data Studio report templates, choose your own data source.

Selecting the right Data Source
Selecting the right Data Source

Something for beginners to keep in mind again, is that if you choose the wrong data source (for e.g. of the default ones provided), then the report would be generated, however the data won’t be yours!

If in case, you have done this, it’s easy to change the data source after you have created the report.

Let’s move on to customizing the report

 

Customizing the Report
Customizing the Report

What I did was choose the Acme logo, and change it to the Big Fat Geek logo! A small change in the header color, and I have a branded look for the template.

This is what the finished report now looks like –

Finished Report
Finished Report

Using Data Studio

The cool part of Data Studio now shines through. What I have is a report which talks to data in real time. So I can change my data range, and my report updates!

This report can now be shared with my team or my reporting manager or clients without worrying about giving access to all the dimensions and metrics.

Data Studio Working Report
Data Studio Working Report

That’s all for today folks! It’s your turn to go and try out this tool and churn out spectacular looking reports.