:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
REDIS_TTL_SECONDS: int = 12 * 60 * 60 # 12h
SALESFORCE_ACCOUNTS_CACHE_KEY: str = "salesforce-enrichment:global:accounts"
SALESFORCE_ORG_MAPPINGS_CACHE_KEY: str = "salesforce-enrichment:global:org_mappings"
SALESFORCE_STRIPE_ENRICHMENT_WATERMARK_KEY: str = "salesforce-enrichment:stripe:last_watermark"
ORG_MAPPINGS_CACHE_MISSING_ERROR_TYPE: str = "OrgMappingsCacheMissing"
HARMONIC_BASE_URL: str = "https://api.harmonic.ai"
YC_INVESTOR_NAME: str = "y combinator"
HARMONIC_REQUEST_TIMEOUT_SECONDS: int = 30
HARMONIC_BATCH_SIZE: int = 100
HARMONIC_DOMAIN_VARIATIONS: list[str] = ["", "www."] # Try exact domain first, then with www prefix
SALESFORCE_UPDATE_BATCH_SIZE: int = 200 # Max records per sObject Collections API call
DEFAULT_CHUNK_SIZE: int = 5000
# Harmonic GraphQL query for company enrichment
_HARMONIC_ENRICHMENT_QUERY_HEAD = """
mutation($identifiers: CompanyEnrichmentIdentifiersInput!) {
enrichCompanyByIdentifiers(identifiers: $identifiers) {
companyFound
enrichmentUrn
company {
name
companyType
website {
url
domain
}
headcount
description
ownershipStatus
customerType
fundingAttributeNullStatus
relatedCompanies {
acquiredBy {
companyUrn
}
subsidiaryOf {
companyUrn
}
}
location {
city
country
state
}
foundingDate {
date
granularity
}
funding {
fundingTotal
numFundingRounds
lastFundingAt
lastFundingType
lastFundingTotal
fundingStage
investors {
... on Company {
name
}
... on Person {
fullName
}
}
}
tractionMetrics {
webTraffic {
latestMetricValue
metrics {
timestamp
metricValue
}
}
linkedinFollowerCount {
latestMetricValue
metrics {
timestamp
metricValue
}
}
twitterFollowerCount {
latestMetricValue
metrics {
timestamp
metricValue
}
}
headcount {
latestMetricValue
metrics {
timestamp
metricValue
}
}
headcountEngineering {
latestMetricValue
metrics {
timestamp
metricValue
}
}
}
tags {
type
displayValue
dateAdded
isPrimaryTag
}
tagsV2 {
type
displayValue
dateAdded
}
"""
_HARMONIC_ENRICHMENT_QUERY_TAIL = """ }
}
}
"""
HARMONIC_COMPANY_ENRICHMENT_QUERY = _HARMONIC_ENRICHMENT_QUERY_HEAD + _HARMONIC_ENRICHMENT_QUERY_TAIL
# The Salesforce Account job also writes the company's LinkedIn page. It has its own query so that the payload the
# other callers of the client fetch, and archive, does not include it.
HARMONIC_ACCOUNT_ENRICHMENT_QUERY = (
_HARMONIC_ENRICHMENT_QUERY_HEAD
+ """ socials {
linkedin {
url
}
}
"""
+ _HARMONIC_ENRICHMENT_QUERY_TAIL
)
# Canonical Account fields that the Harmonic enrichment writes only when they hold no value. The job reads their
# current values immediately before it writes.
ACCOUNT_FILL_FIELDS: tuple[str, ...] = (
"Industry",
"NumberOfEmployees",
"Company_LinkedIn__c",
"LinkedIn_Engineer_Count__c",
"LinkedIn_Rolecount__c",
)
# Salesforce query for accounts with websites
SALESFORCE_ACCOUNTS_QUERY = """
SELECT Id, Name, Website, CreatedDate
FROM Account
WHERE Website != null
ORDER BY CreatedDate DESC
"""
METRIC_PERIODS = {"90d": 90, "180d": 180}
# PostHog usage enrichment constants
POSTHOG_ORG_GROUP_TYPE_INDEX = 0 # Organizations are group_type_index 0 in PostHog's groups table
POSTHOG_ORG_ID_FIELD = "Posthog_Org_ID__c"
POSTHOG_USAGE_ENRICHMENT_BATCH_SIZE = 100
POSTHOG_FETCH_MAPPINGS_PAGE_SIZE = 10_000 # Page size for fetching org mappings, kept under Temporal's 4 MB gRPC limit
POSTHOG_ORG_REGION_FIELD = "Posthog_Org_Region__c"
ORG_REGION_BY_LICENSE_ID: dict[int, str] = {1: "EU", 2: "US"}
# Salesforce field mappings for PostHog usage signals
# Format: internal_field_name -> salesforce_custom_field_name
POSTHOG_USAGE_FIELD_MAPPINGS = {
# Events-based metrics (7-day)
"total_events_7d": "posthog_total_events_7d__c",
"events_avg_daily_7d": "posthog_events_avg_daily_7d__c",
"products_activated_7d": "posthog_products_7d__c",
"events_7d_momentum": "posthog_events_7d_momentum__c",
# Events-based metrics (30-day)
"total_events_30d": "posthog_total_events_30d__c",
"events_avg_daily_30d": "posthog_events_avg_daily_30d__c",
"products_activated_30d": "posthog_products_30d__c",
"events_30d_momentum": "posthog_events_30d_momentum__c",
}
# Both momentum fields are Number(7, 2) in Salesforce, which rejects the whole record for a value above
# 99,999.99. Momentum is a percentage change, so growth from a nearly empty previous period exceeds it.
SALESFORCE_MOMENTUM_MAX = 99_999.99
STRIPE_ENRICHMENT_PAGE_SIZE: int = 5_000
# Account.Name is not mapped, because the billing customer's name is the organization's name and not the company's.
STRIPE_ENRICHMENT_FIELD_MAPPINGS: dict[str, str] = {
"stripe_customer_id": "Stripe_id__c",
"address_city": "BillingCity",
"address_state": "BillingState",
"address_postal_code": "BillingPostalCode",
"address_country": "BillingCountry",
}
CONVERSATIONS_SLACK_ENRICHMENT_BATCH_SIZE: int = 100
CONVERSATIONS_SLACK_FIELD_MAPPINGS: dict[str, str] = {
"slack_channel_url": "Slack_Channel__c",
"slack_issue_count": "slack_issue_count__c",
"slack_user_count": "slack_user_count__c",
"last_slack_activity": "last_slack_activity__c",
"most_recent_support_ticket_url": "Most_Recent_Support_Ticket__c",
"last_customer_message_at": "last_customer_message_at__c",
"slack_bot_joined_at": "slack_bot_joined_at__c",
}
PERSONAL_EMAIL_DOMAINS = {
"gmail.com",
"yahoo.com",
"hotmail.com",
"outlook.com",
"aol.com",
"icloud.com",
"protonmail.com",
"zoho.com",
"yandex.com",
"live.com",
"msn.com",
"me.com",
"mac.com",
"gmx.com",
"yahoo.co.uk",
"yahoo.co.jp",
"yahoo.co.in",
"yahoo.com.au",
"yahoo.com.sg",
"yahoo.com.ph",
"yahoo.com.my",
"yahoo.com.hk",
"yahoo.com.tw",
"yahoo.com.vn",
"yahoo.com.br",
"yahoo.com.ar",
"yahoo.com.mx",
"yahoo.com.tr",
"yahoo.com.ua",
"yahoo.com.eg",
"yahoo.com.sa",
"yahoo.com.ae",
"yahoo.com.kr",
"yahoo.com.cn",
"yahoo.com.ru",
"yahoo.com.id",
"yahoo.com.th",
"yahoo.com.ve",
"yahoo.com.pe",
"yahoo.com.cl",
"yahoo.com.co",
"yahoo.com.ec",
"yahoo.com.uy",
"yahoo.com.py",
"yahoo.com.bo",
"yahoo.com.do",
"yahoo.com.pr",
"yahoo.com.gt",
"yahoo.com.sv",
"yahoo.com.hn",
"yahoo.com.ni",
"yahoo.com.cr",
"yahoo.com.pa",
}