In continuation to my last blog i.e. “Export Google Analytics Accounts, Properties and Views Name & ID automatically”, I am writing this blog as a solution of the third method to send GA accounts, properties and views name & id directly to data studio report.
Just a recap, in the last blog, I listed below three ways to get GA data.
Out of these three ways, I have explained the first two solutions. Here is the third one. The best part of this solution is that, in this solution, we will create connector to connect data studio directly to GA data.
Benefits – It will show real time data in data studio report. In future, if you create any new account, property or views, it will directly reflect in the report. No need to make any changes anywhere. Isn’t it nice? 😊
The first two solutions were not helping to get real time reports. But the third one will.
OK, before moving forward, I have one question, i.e. Have you ever heard about data studio connector before?
As per Google, Data Studio Community Connectors enable direct connections from Data Studio to any internet accessible data source
There are many connectors which are readymade and can be directly used. You can see all the available connectors here - https://datastudio.google.com/data. If there is no connector available which serves your requirement, you can create one for yourself.
Now, how to create a connector?
Solution - Few lines of appscript code. Best source to learn appscript is google developer’s site - https://developers.google.com/apps-script/overview
So, instead of explaining, what is appscript and its usage, let's just move directly on the required code and setup to execute the code.
Skelton of any connector - Below four functions, are the Skelton of any connector
• getAuthType() - This function returns the authentication method used by the connector .
What is authentication method - There are many data sources, which are not open to public and need some authentication to access their data. Suppose, you want to create a facebook datastudio connector, which can fetch data directly from facebook server & showcase it in data studio report.
Now, how to access data from facebook servers? Is it openly accessible without any credentials?
The answer is No. To access facebook data, you will require credentials, either some secret key or user access tokens & need to pass/write these credentials in the connector code.
The question is still there, what is authentication method? As outlined in the previous line, the secret key, the user access tokens are the methods to authenticate yourself to access the data. So, the method which we use to access the data is known as authentication method. If we use, access token to access the data, the authentication method will be user access token and similarly if we use secret key to access the data, the authentication method will be secret key or key.
So, this function just returns the authentication method used by the connector.
There are many authentication methods like OAuth 2.0, API key, username/password & username/token.
Note that, there are also many data sources, which are open to public, and doesn’t requires any credentials to access their data. In those cases, we don't use any authentication method, so we pass the authentication method as “NONE” in the getAuthType function.
Similarly, for our connector, the access response type will be NONE as we will be creating the connector in a login mode with the email id which have ADMIN access to Google Analytics. So, no access tokens or secret keys are required here. But, we need to write below function to confirm ourselves as an admin user.
• getConfig() – This function helps to enhance the configuration of your report. Suppose you have two GA accounts i.e. Account 1 and Account 2 and you want to create separate data studio reports for the accounts. Then in the config function, you can provide an option to select the Account name. So, while selecting the data source, you will get an option to select the account name for which you want to see the data.
In our case, we are showcasing all the data in one report, so, no modifications requires in the config function. Let's keep it with its basic structure.
• getSchema() – getSchema() & getData() are the main players of any connector. Before explaining the usage of this function, let me explain the role of field.
In a data studio, a chart displays data from one or more fields and these fields are either dimension or a metric.
Suppose we want to display Account Name, Account ID, Property Name, Property ID and View Name, View ID. So, here we have to declare 6 different fields for 6 different sets of data.
So, in this function getSchema(), we will just define all the fields, its name, label and data type i.e. either dimension or metric. In the next function i.e. getData(), we will assign data to each fields.
• getData() – Here we assign data to each field defined in the getSchema function and push data in a common array. This function returns the schema fields with the data mapped into it.
Combined code - Copy paste this combined code in code.gs file.
In next step, we need to update the manifest. In the Apps Script editor, select "Show manifest file" under View menu.
This will create a new appsscript.json manifest file. Replace the appscript.json code with the below code & save the project by selecting Save All under the File menu.
Note – Replace the logo urls, company name, company url, addonurl (privacy page link) & support url (contact us page) with the related urls of your site.
The connector is now ready to publish and get validated in a data studio report. Follow below steps to publish and validate the connector.
Step 1: Under Publish menu, select "Deploy from manifest" to open the deployment screen.
Don't worry, it is just an appscript development environment. No one can access this connector, until and unless you publish it as a partner connector or open source connector.
Step 2: Once deployed, a pop-up will appear with the connector link under "Latest Version". Click on the connector link and it will redirect you to the new tab.
Step 3: In the new tab, authorize the connector by clicking on "Authorize" button.
Step 4: Once the authorization is complete, you will see a configuration screen. Click the "Connect" button in the top right.
Step 5: Once clicked on the Connect button, you will see the field's screen. Click "Create Report" in the top right.
Step 6: Once clicked on "create report", you will be redirected to data studio dashboard environment. A pop-up will appear with the "Add to Report" button. Click on that "Add to Report" button. It will connect the data source to the report.
Step 7: All Set. Now create reports by following the steps in below GIF image.
Congratulations, you have created & validated your first data studio connector successfully 😊. You can create many more connectors for different purposes like Facebook connector to showcase facebook page insights, Twitter connector to showcase your twitter profile performance in the data studio reports.
I will be very happy to see you creating more connectors. If any help is required, please feel free to write us at firstname.lastname@example.org