HubSpot is a completely managed cloud-based service for customer relationship management. It can be used to manage marketing, sales and service.
- Software-as-a-Service’ products like HubSpot spare businesses the effort of building custom solutions but at the same time rob them of the opportunity to run custom analytics and reporting on their data.
- Looker Studio ( Google Data Studio) helps businesses create dashboards and reports for executive decision-making.
- It can connect to a number of data sources including on-premise and cloud-based ones. This post is about the steps involved in connecting HubSpot to Looker Studio.
Methods to Connect HubSpot to Looker Studio
- Looker Studio does not provide a HubSpot connector but it allows data to be uploaded in the form of Google Sheets.
- HubSpot also provides APIs that allow data to be downloaded into many file formats. In this article, you will learn how to use different API’s provided by Google Sheets and HubSpot to move data into Google Data Studio.
Pre-requisites
- A HubSpot admin account and API token generated from that account
- A Google account
- Basic understanding of business intelligence tools
Using a CSV File Generated via HubSpot APIs
This method uses Google Sheet’s app script mechanism to fetch data from HubSpot APIs to feed data to Data Studio.
- Go to the HubSpot Admin section and generate API keys. For this, go to Settings > Integrations > Generate API keys.
- Go to Google Sheets and create a new sheet. In the new sheet, go to Tools 》Script Editor and start editing the script. You will begin by adding the header for Google Sheet.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Blad1');
sheet.clear();
sheet.appendRow(["Dealname", "Dealstage", "Close date", "Amount"]);
var ss = SpreadsheetApp.getActiveSpreadsheet();
:
- Gets the currently active spreadsheet and stores it in the variable
ss
.
var sheet = ss.getSheetByName('Blad1');
:
- Accesses a specific sheet named
Blad1
within the active spreadsheet and stores it in the variable sheet
.
sheet.clear();
:
- Clears all the contents and formatting of the
Blad1
sheet.
sheet.appendRow(["Dealname", "Dealstage", "Close date", "Amount"]);
:
- Appends a new row with the headers
Dealname
, Dealstage
, Close date
, and Amount
to the Blad1
sheet.
- You will now write a function to fetch JSON from HubSpot API. For this exercise, we will be using the deals API of HubSpot.
var offset = 0;
var queryParams = '&limit=250&offset=' + offset + '&properties=dealname&properties=dealstage&properties=closedate&properties=amount'
var _url = 'https://api.hubapi.com/deals/v1/deal/paged?hapikey=' + api_key
var options = { "method": "GET", "muteHttpExceptions": true };
var apiResponse = UrlFetchApp.fetch(url + endpoint,options);
var output_json = JSON.parse(apiResponse);
var offset = 0;
:
- Initializes a variable
offset
to 0, which is used for pagination in API requests.
var queryParams = '&limit=250&offset=' + offset + '&properties=dealname&properties=dealstage&properties=closedate&properties=amount'
:
- Constructs a string of query parameters:
limit=250
: Limits the number of results returned to 250.
offset
: Uses the current value of offset
for pagination.
properties
: Specifies the properties of deals to retrieve (dealname
, dealstage
, closedate
, and amount
).
var _url = 'https://api.hubapi.com/deals/v1/deal/paged?hapikey=' + api_key
:
- Constructs the base URL for the HubSpot API, appending the API key (
api_key
).
var options = { "method": "GET", "muteHttpExceptions": true };
:
- Defines the options for the API request:
method: "GET"
: Specifies that this is a GET request.
muteHttpExceptions: true
: Prevents exceptions from being thrown on HTTP errors, allowing you to handle them manually.
var apiResponse = UrlFetchApp.fetch(url + endpoint, options);
:
- Sends the GET request to the constructed URL with the specified options and stores the response in
apiResponse
.
var output_json = JSON.parse(apiResponse);
:
- Parses the JSON response from the API into a JavaScript object.
- You will now write values to the sheet we created using the below snippet.
while (output_json.status !== "error" && i < output_json.deals).length) {
var dealname = output_json.deals[i].properties.dealname.value;
var dealstage = output_json.deals[i].properties.dealstage.value;
var closedate = new Date((output_json.deals[i].properties.closedate.value));
var amount = output_json.deals[i].properties.amount.value;
var deals = [dealname, dealstage, closedate, amount];
sheet.appendRow(deals);
}
while (output_json.status !== "error" && i < output_json.deals.length)
:
- Loops while the API response does not indicate an error and the index
i
is less than the total number of deals in output_json.deals
.
var dealname = output_json.deals[i].properties.dealname.value;
:
- Retrieves the
dealname
property value for the current deal (indexed by i
).
var dealstage = output_json.deals[i].properties.dealstage.value;
:
- Retrieves the
dealstage
property value for the current deal.
var closedate = new Date((output_json.deals[i].properties.closedate.value));
:
- Converts the
closedate
property value to a JavaScript Date
object.
var amount = output_json.deals[i].properties.amount.value;
:
- Retrieves the
amount
property value for the current deal.
var deals = [dealname, dealstage, closedate, amount];
:
- Creates an array called
deals
containing the extracted values (dealname
, dealstage
, closedate
, and amount
).
sheet.appendRow(deals);
:
- Appends the
deals
array as a new row in the spreadsheet.
You can set this function to be run based on a periodic trigger or use the custom function itself in the Google Sheet cell.
- The next step is to go to Data Studio connections and add the above Google Sheet as the source. To do this go to Data Studio and click on “Report” .
- Select Google Sheet when Data Studio asks for the data source and select the relevant sheet.
Once the sheet is selected, you should be able to create reports using data from HubSpot. The advantage of this approach is that you can ensure the sheet has the latest data by configuring the script to execute periodically or on-demand.
Download the Guide on How to Set Up a Data Analytics Stack
Learn how to build a self-service data analytics stack for your use case.
Limitations of this Approach
The above approach comes with its own share of pitfalls too:
- This method currently handles only the first page of results from HubSpot API. You will need additional custom development to implement pagination and get hold of your complete data. In other words, getting this to production needs an expert developer.
- In most cases, companies will need transformations to be executed on source data before creating reports in Data Studio. Such transformations are difficult to handle in the above approach.
- Other than the deals API, HubSpot provides a number of APIs to extract data. Using all these APIs and integrating to Data Studio will need a herculean effort in developing as well as learning HubSpot APIs.
Hevo is a No-Code Data Pipeline. You can easily load your data from HubSpot (Free Data Source) and multiple other sources in real-time for easy visualization in Google Data Studio. Hevo makes sure that you fulfill your needs at a reasonable price. It offers pre-built data integrations from 150+ data sources, including HubSpot. It helps transfer data from HubSpot to a destination of your choice for free.
Get started with hevo for free
Let’s look at some unbeatable features of Hevo:
- Easy Implementation: Hevo offers a simple and intuitive user interface.
- Fully-Automated: You can automate your entire ETL process without writing any custom code.
- Zero Maintenance: Once you’re done with the setup, Hevo manages all future tasks automatically.
- Fault-Tolerant: Hevo can automatically detect anomalies from the incoming data and informs you immediately.
- Security: Hevo makes sure that your data is secured by using two-factor authentication and end-to-end encryption.
- Zero Data Loss: Hevo makes sure that data is transferred from source to destination in real-time without any loss or change in data.
Learn More About:
Setup Looker HubSpot Integration in Quick Simple Steps
Conclusion
- You have learned how you can move data from HubSpot to Google Sheets and then pull this data into Looker Studio ( Google Data Studio ).
- However, it involves many steps and can be tedious. A simpler solution could be to integrate data from HubSpot and different sources so that data is analysis-ready and can be visualized easily in Data Studio.
Frequently Asked Questions
1. Does Google Data Studio connect to HubSpot?
Yes, Google Data Studio can connect to HubSpot. You can use the HubSpot connector available in Data Studio to visualize your HubSpot data.
2. Can HubSpot integrate with Google?
Yes, HubSpot integrates with various Google products, including Google Analytics, Google Ads, and Google Sheets. This integration allows for seamless data transfer and reporting.
3. How do I connect my HubSpot domain to Google?
To connect your HubSpot domain to Google (e.g., for Google Analytics):
-Go to your HubSpot account settings.
-Navigate to Tracking & Analytics > Analytics Tools.
-Enter your Google Analytics tracking ID.
-Follow the prompts to complete the integration.
For connecting your domain to Google Search Console, verify ownership through the domain settings in HubSpot or by adding a TXT record to your DNS.
Talha is a Software Developer with over eight years of experience in the field. He is currently driving advancements in data integration at Hevo Data, where he has been instrumental in shaping a cutting-edge data integration platform for the past four years. Prior to this, he spent 4 years at Flipkart, where he played a key role in projects related to their data integration capabilities. Talha loves to explain complex information related to data engineering to his peers through writing. He has written many blogs related to data integration, data management aspects, and key challenges data practitioners face.