PostHog Handbook Library / Growth

2,179 words. Estimated reading time: 10 min.

# Automations

Auto TL;DR

## At a Glance

This long page covers these main areas. The list is generated from the article headings, so it updates with every handbook rebuild.

1. Connecting everything together
2. Vitally Segmentation
3. Vitally Zendesk/HubSpot Automation
4. Ensuring that Vitally Accounts have corresponding Zendesk Organization and HubSpot Companies associated with them
5. Tagging Zendesk Organizations based on Segment and Subscription information
6. Setting the correct organization in Zendesk for new tickets
7. [Deprecated] HubSpot and Zendesk tagging
8. Billing trial activated event HubSpot and Zendesk

## Automations

As Vitally connects all of our Product, Stripe, Zendesk and HubSpot data together it's the best place to trigger automations via Playbooks. These Playbooks can call a webhook after Accounts or Users meet certain criteria. This allows us to call out to Zapier to use their inbuilt actions to update Zendesk, HubSpot, Slack and more. We use Zapier extensively throughout the company for automation. There is a shared Zapier login in 1Password.

### Connecting everything together

Vitally requires a consistent `external_id` to be present to link everything together. For Accounts, we use the `posthog_organization_id` and for Users it's their `email`.

### Vitally Segmentation

Vitally uses Playbooks to put Accounts and Users into Segments, which are useful for reporting as well as targeting of Playbooks. We have the following Segmentation Playbooks defined:

1. Segment Name: $60K ARR

- Playbook Link
- Criteria
- Account not in Startups Segment
- ARR >= $60K

1. Segment Name: $20K ARR

- Playbook Link
- Criteria
- Account not in Startups Segment
- ARR >= $20K AND ARR < $60K

1. Segment Name: Startup Plan

- Playbook Link
- Used to track companies either on PostHog for Startups or the YC Program
- Criteria
- Stripe Account Balance < 0 (e.g. they have credit remaining)
- Stripe Credit Expires at > 0 days from today (e.g. it hasn't expired yet)
- Stripe Is Startup Plan Metadata is not false or null (e.g. they haven't been marked as being on a paid annual plan)

1. Segment Name: Annual Plan

- Playbook Link
- Criteria
- Stripe Subscription interval is yearly
- OR
- Stripe Account Balance < 0 (e.g. they have credit remaining)
- Stripe Credit Expires at > 0 days from today (e.g. it hasn't expired yet)
- Stripe Is Startup Plan Metadata is false or null (e.g. they haven't been marked as being on the startup plan)

1. Segment Name: Active Trial

- Playbook Link
- Criteria
- Free Trial Until is greater than 0 days from now (comes from the Billing Postgres connection)

1. Segment Name: First payment forecasted this month

- Playbook Link
- Criteria
- Lifetime Value (LTV) is 0 (e.g. they have never paid us)
- Stripe current period end is greater than 0 days from now
- Forecasted MRR > $1

### Vitally -> Zendesk/HubSpot Automation

As Vitally has Subscription/Segment information it's the best place to drive Zendesk tagging and other activities.

#### Ensuring that Vitally Accounts have corresponding Zendesk Organization and HubSpot Companies associated with them

The New Orgs to Zendesk and HubSpot via Zapier playbook triggers on Accounts where there is _no associated Zendesk ID_ but there _is a Stripe Customer email_, so that we can look up the contact and company information in HubSpot. When these criteria are matched the playbook sends the following traits to a webhook which triggers the Vitally Webhook to New Zendesk Org and HubSpot Zap:

- orgName - PostHog Organization Name
- orgID - PostHog Organization ID
- customerID - Billing Customer ID
- email - Stripe Email
- siteURL - the URL of the PostHog Cloud they're on (useful to have in Zendesk)

The Zap then:

1. Tries to find a HubSpot contact matching the email
2. If successful, looks up the associated HubSpot Company
3. Sets the posthog_organization_id property in HubSpot so that Vitally will be able to link to the Company
4. Creates a Zendesk Organization with the following properties:

- `name` - Billing Customer ID - PostHog Organiation Name (e.g. 12345 - PostHog) which guarantees uniqueness
- `external_id` - PostHog Organization ID
- `ph_external_id_org` - PostHog Organization ID custom field (because `external_id` cannot be used in triggers and automations)
- `domain` - The domain name from the HubSpot Company Object (which might not exist - see below)

There are some scenarios (e.g. gmail signups) where HubSpot doesn't have an associated company record and as such there won't be a domain to supply to Zendesk. In this case the automation completes but also adds the Email and Zendesk org information to the Zendesk Orgs Without a Domain table. For each row there are two buttons:

- Add Domain to Org - Will fire a Zap to extract the company name from the email and set it on the Zendesk Organization. Use this one if it's clearly the right company domain.
- Add User to Org - Will fire a Zap which adds that individual user to the Zendesk Organization. Use this if it's a webmail provider (e.g. gmail) as we don't everyone with a @gmail.com email creating tickets for this Organization, but do want this user to get the right level of support for their Organization.

#### Tagging Zendesk Organizations based on Segment and Subscription information

As Vitally is the best source of truth for Active Subscription / Payment information which informs our Zendesk ticket prioritization, there are a number of Vitally playbooks which will trigger the webhook associated with the Vitally Webhook to Zendesk Tags Zap, passing along the following traits:

- zendesk_id - The Zendesk Organization ID (internal, not external_id)
- playbook name - The tags to set on the Zendesk Organization

The Zap then updates the specific Zendesk Organization with the requested tags.

1. Zendesk Tag: `priority_customer`

- Playbook Link
- Criteria
- Account is PostHog
- Account not in Startup Plan Segment
- ARR >= $20K
- Zendesk Org ID is set

1. Zendesk Tag: `paying_customer`

- Playbook Link
- Criteria
- Account not in Startup Plan Segment
- ARR > 0 and < $20K
- Zendesk Org ID is set

1. Zendesk Tag: `non_paying`

- Playbook Link
- Criteria
- Account is not PostHog
- Account not in Startup Plan or Active Trial Segments
- ARR = 0
- Zendesk Org ID is set

1. Zendesk Tag: `churned`

- Playbook Link
- Criteria
- Account is not PostHog
- Account not in Active Trial Segment
- Stripe Subscription Status is Cancelled
- Zendesk Org ID is set

1. Zendesk Tag: `startup_plan`

- Playbook Link
- Criteria
- Account in Startup Plan Segment
- Zendesk Org ID is set

1. Zendesk Tag: `trial`

- Playbook Link
- Criteria
- Account in Active Trial Segment
- Zendesk Org ID is set

#### Setting the correct organization in Zendesk for new tickets

Zendesk uses the requester's email domain to associate the ticket and the requester with an organization in Zendesk. To mitigate the problems this causes, we have a Zap named Set user's correct organization ID which:

- Checks each new ticket for a value in the custom ticket field `organization_id`. (This ID is added to each support ticket submitted via our Help sidebar `Email an engineer` form, and community questions.)
- Looks for a Zendesk org with an `external_id` which matches the value of the custom ticket field `organization_id`
- If no match is found, the Zap stops and does nothing
- If a match is found, the Zap sets the user's Zendesk organization accordingly, and then sets an `org-checked` tag to prevent the Zap from running repeatedly on the same ticket.

### [Deprecated] HubSpot and Zendesk tagging

The Zaps in this folder have been mostly turned off in favour of the Vitally automations above, however there are some which are still enabled as we need to figure out how to handle them via Vitally.

#### Billing trial activated event -> HubSpot and Zendesk

_This needs to be moved to Vitally_

This Zap is triggered when a trial is activated in the Billing UI (triggered by the Billing trial activated action).

1. Looks up the associated email in Clearbit
2. Continues only if there is an associated Company in the Clearbit payload
3. Calls the Update tags on Zendesk org Sub Zap to create/update a Zendesk org with the Name and Domain from Clearbit and Organization ID as the Zendesk External ID (so that it will link the Zendesk org to the Vitally Account)
4. Finds the Company by name in HubSpot
5. Sets the Organization ID and Trial end date in HubSpot.
6. Creates an engagement (Task) in HubSpot for Simon reminding him of the trial end date.

### HubSpot Automation

There are three zaps in this folder which create follow-on deals when any hands-on pipeline deal is closed:

1. HubSpot Inbound Hands-on Deal Closed to Renewal Deal (Zapier automation details)
2. HubSpot PQL Hands-on Deal Closed to Renewal Deal (Zapier automation details)
3. HubSpot Renewal Deal Closed to Renewal Deal (Zapier automation details)

They're triggered by a deal closing in the respective pipeline. It figures out the new deal close date based on the term in the existing deal (1,2,3 years) and then creates a new deal in the renewal pipeline, with amounts and ownership copied over too.

### Sales Pipeline Events to PostHog

This folder contains Zaps which ensure we are tracking pipeline updates as PostHog events, so that we can model our sales pipeline as a funnel.

#### Calendly Event Scheduled to PostHog

This Zap is triggered when a new event is created via Calendly, this:

1. Looks up the PostHog Distinct ID via the email address of the person
2. Captures a `calendly.event_scheduled` event in PostHog with either the Distinct ID above or email address as the Distinct ID if there wasn't a match.

#### HubSpot Deal Stage Changes to PostHog

This Zap is triggered when a deal stage is updated in HubSpot, this:

1. Transforms the HubSpot ID of the Pipeline and Stage to the names via lookup tables and only carries on if matches are found
2. Gets the Deal Contact and Owner information
3. Captures a `<pipeline-name> <stage-name>` event in PostHog with the Contact email as the Distinct ID

### Annual Plan Automation

To ensure consistency in the setup of annual plans we have Zapier Automation to take care of all of the Stripe-related object setup.

#### Load Contract Details to Annual Plan Table

Once an Order Form is closed in PandaDoc, This Zap will add a new row to the Annual Plan Table with the following information set:

1. Order Form ID
2. Customer Email
3. Customer Address
4. Company Domain
5. Contract Start Date
6. Contract Term (months)
7. Credit Amount
8. Discount
9. Price

#### Create or Update Stripe Customer

If the Customer has an existing record in Stripe (e.g. they are already subscribed to PostHog) then copy their Customer ID (starts `cus_`) from Stripe to the _Stripe Customer ID_ column. If they don't have an existing Customer in Stripe then click the _Create Stripe Customer_ button in the table to trigger a Zap to create one. The Zap also automatically adds the ID to the table.

#### Create Invoice

Once you click the Create Invoice button this Zap will create a Stripe Invoice in draft format. The following table fields need to be populated for this to work so check them before clicking the button:

1. Start Date
2. Term (months)
3. Credit Amount
4. Price

Once it's completed it'll populate the table with the Invoice ID and Link. Review this in Stripe, and when you are ready send the Invoice to the customer.

Note: You need to send the invoice to the customer before you apply the credit below. If you apply the credit whilst the Invoice is in a draft state it'll just pay the invoice with the credit, which defeats the purpose

#### Apply Stripe Credit / Zendesk Tags

Here you can click _Apply Credit_ to trigger a Zap which applies the Stripe Credit and Zendesk tags using the corresponding Sub Zaps. It will apply the `priority_customer` tag if the price is above $20k, and `paying_customer` otherwise.

#### Schedule Subscription

If the customer doesn't already have a running monthly subscription this Zap will create one with the desired configuration of paid products. Select the products you want to include and then click the Schedule Subscription button. It'll create a Subscription which is either Scheduled if the Start Date is in the future, or live if it is in the past.

Remember to update the Subscription in the Billing Admin Portal

Note: It has the current default Stripe Price IDs hardcoded in the Zap so if we update those we need to remember to update them in this Zap too.

### YC Program

This process is documented on the YC Onboarding page.

### PostHog for Startups

_Work in progress_

### Sub-Zaps

These are used in a few different places to ensure we do things in a consistent manner. It also ensures repetitive tasks are easy to update if needed.

#### [Deprecated] Update tags on Zendesk org

_Mostly deprecated as we use Vitally for this now_

This Zap ensures that a Zendesk org is created and tagged correctly

1. Accepts the following inputs:
2. Company name (required)
3. Domain (required)
4. Tags
5. Organization ID
6. Instance
7. Startup plan or Trial ends at
8. Formats tags and startup/trial ends at in case of missing data
9. Formats startup/trial end in YYYY-MM-DD
10. Creates or Updates an organization with the information above

#### Apply Stripe Credit

This Zap applies credit and associated metadata to a Stripe Customer object

1. Accepts the following inputs:
2. Duration (e.g. 1 year or 6 months)
3. Stripe Customer ID
4. Amount (dollars)
5. Description (optional)
6. Credit start date
7. Is startup credit
8. Calculates the credit end date from the Start Date + Duration
9. Converts Dollars to Cents (for Stripe)
10. Adds the credit balance via the Stripe API
11. Updates the following metadata on the Customer Object:
12. `credit_expires_at`
13. `is_startup_plan_customer`

Canonical URL: https://posthog.com/handbook/growth/sales/automations

GitHub source: contents/handbook/growth/sales/automations.md

Content hash: `bcc51066880f1288`

Static reader notes

- `MDX_COMPONENT_STATIC_ADAPTER`: Adapted interactive MDX components for static reading: PrivateLink.