How to set up Hubspot reports
Jun 25, 2024
Creating and analyzing reports of Hubspot data along with product data helps you better understand your customers and close more deals.
In this tutorial, we show how you can create Hubspot reports in PostHog by connecting it as a data source and then creating insights like the number of contacts, deals by stage, usage by leads, and more.
Linking Hubspot data to PostHog
To start, you need both Hubspot and PostHog accounts. Once you have those, head to PostHog's data warehouse tab and:
- Click Link source
- Choose the Hubspot option by clicking Link
- Choose the Hubspot account you want to link
- Add a table prefix like
prod_
(optional) and press Next - Select all the tables, choose your sync method, and press Import
Once done, PostHog will automatically pull and format your Hubspot data for querying. You can adjust the sync frequency, see the last successful run, and more in data warehouse settings.
Note: If you are missing a table, make sure you have data for that table in Hubspot and check your data warehouse settings to make sure it synced correctly.
Creating insights for your Hubspot report
Now that your Hubspot data is synced into PostHog, you can use it to create insights for your report. Each requires you to create a new insight in the product analytics tab.
Want to get started fast? Check out our Hubspot starter report template.
Deal count
To start, we create a trend of deal count over time.
On the trends tab, click the data series, go to the Data Warehouse tab, hover over the hubspot_deals
table, change the timestamp to createdate
, and click Select.
You can breakdown the trend this creates by any of the deal's properties like dealstage
or amount
. To do this, click Add breakdown, go to the data warehouse properties tab, and choose your property.
You can also visualize other tables like hubspot_companies
and hubspot_contacts
.
Usage by lead
The best part of adding your Hubspot data to PostHog is querying it next to usage data.
An example of this is figuring out the leads with the most usage. To do this, we create an SQL insight where we get leads from hubspot_contacts
, join their email with PostHog's distinct_id
, and get a count of events.
This gets us a list of Hubspot emails ordered by their PostHog event count.
Leads who visit specific pages
We can do something similar to get a list of leads who visit important pages like your pricing or signup page. This requires us to filter for $pageview
events where the $current_url
contains /pricing
.
withleads as (select emailfrom hubspot_contactswhere lifecyclestage = 'lead'),pricing_pageviews as (select count(*) as pageviews, distinct_idfrom eventswhereevent = '$pageview'and properties.$current_url like '%pricing'group by distinct_id)select email, pageviewsfrom leadsleft join pricing_pageviews on pricing_pageviews.distinct_id = leads.emailorder by pageviews desc
You can modify this query to track other important types of events such as billing page visits or recent user signups.
Getting revenue from closed deals by joining with Stripe
Beyond PostHog data, you can also join and query data from other sources like Stripe if you have them set up.
An example of this is getting the revenue from closed deals. We can get the email and recent_deal_amount
from the hubspot_contacts
table and the amount_paid
and billing email from stripe_charge
to compare the revenue and predicted deal amount.
withclosed_deals as (select email, recent_deal_amountfrom hubspot_contactswhere lifecyclestage = 'customer'),revenue as (selectsum(amount) / 100 as amount_paid,JSONExtractString(billing_details, 'email') as stripe_emailfrom stripe_chargewhere status = 'succeeded'group by stripe_email)select email, recent_deal_amount, amount_paidfrom closed_dealsleft join revenue on revenue.stripe_email = closed_deals.email
You can modify this to fit the financial and sales metrics you want to track.