Skip to content

: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.

feat(warehouse-sources): add profound citation category and tag tables (#113864)

Tom Owers87f4e7e7e30c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index 28fa2a4a17ab..ae2fa3a3ed73 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -6971,6 +6971,15 @@ Diffed against: <https://developer.productboard.com/reference/listentityfieldval
Note: The source uses the v2 API where companies/features/components/objectives etc. are all entity types on GET /v2/entities, so those 14 tables come from one endpoint. The uncovered surface is the field-value, configuration and relationship sub-resources, which is where most of the analytical detail lives.
+## Profound — gaps
+
+Today (10): `Assets`, `Categories`, `CitationCategories`, `CitationTags`, `Citations`, `Domains`, `Models`, `Personas`, `Regions`, `Visibility`
+
+Diffed against: <https://docs.tryprofound.com/rest-api/changelog>
+
+- [x] `/v1/org/categories/{category_id}/citation-categories` — lookup for the `citation_category` filter values per category, built-in and custom (low)
+- [x] `/v1/org/categories/{category_id}/citation-tags` — lookup for the custom `citation_tag` filter values per category (low)
+
## PulumiCloud — gaps
Today (5): `audit_logs`, `deployments`, `resources`, `stack_updates`, `stacks`
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/profound/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/profound/canonical_descriptions.py
index 87121f0bfce8..f00de42a1cd8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/profound/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/profound/canonical_descriptions.py
@@ -65,6 +65,24 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"organization": "The organization the persona belongs to.",
},
},
+ "CitationCategories": {
+ "description": "The citation categories available in each category: the built-in buckets, such as Owned, Competition, and Earned Media, plus any custom ones.",
+ "docs_url": "https://docs.tryprofound.com/api-reference/organization/get-category-citation-categories",
+ "columns": {
+ "category_id": "The category this citation category belongs to, stamped on from the request.",
+ "value": "Value to pass to the v2 citations report `citation_category` filter.",
+ "name": "Display name of the citation category.",
+ },
+ },
+ "CitationTags": {
+ "description": "The custom citation tags defined in each category.",
+ "docs_url": "https://docs.tryprofound.com/api-reference/organization/get-category-citation-tags",
+ "columns": {
+ "category_id": "The category this citation tag belongs to, stamped on from the request.",
+ "value": "Value to pass to the v2 citations report `citation_tag` filter.",
+ "name": "Display name of the citation tag.",
+ },
+ },
"Visibility": {
"description": "Daily brand visibility per category: how often each brand appears in AI answers, with share of voice and average position.",
"docs_url": "https://docs.tryprofound.com/rest-api/reports/query-visibility-v2",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/profound/profound.py b/products/warehouse_sources/backend/temporal/data_imports/sources/profound/profound.py
index e70873686714..0b10614c204c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/profound/profound.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/profound/profound.py
@@ -9,6 +9,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.htt
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source import (
RESTAPIConfig,
rest_api_resource,
+ rest_api_resources,
+)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ rename_parent_fields,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
JSONResponseCursorPaginator,
@@ -98,6 +102,40 @@ def _reference_endpoint(config: ProfoundEndpointConfig) -> Endpoint:
return endpoint
+def _category_reference_resource(
+ config: ProfoundEndpointConfig,
+ api_key: str,
+ team_id: int,
+ job_id: str,
+) -> Any:
+ categories = PROFOUND_ENDPOINTS["Categories"]
+ endpoint = _reference_endpoint(config)
+ endpoint["params"] = {"category_id": {"type": "resolve", "resource": categories.name, "field": "id"}}
+ rest_config: RESTAPIConfig = {
+ "client": {
+ "base_url": PROFOUND_BASE_URL,
+ "headers": _headers(),
+ "auth": {"type": "api_key", "api_key": api_key, "name": "X-API-Key", "location": "header"},
+ "request_timeout": REQUEST_TIMEOUT_SECONDS,
+ # The API key rides a custom header, which requests would replay to a redirect target.
+ "allow_redirects": False,
+ },
+ "resource_defaults": {},
+ "resources": [
+ {"name": categories.name, "endpoint": _reference_endpoint(categories)},
+ {
+ "name": config.name,
+ "endpoint": endpoint,
+ # The response rows do not echo the category they belong to.
+ "include_from_parent": ["id"],
+ },
+ ],
+ }
+ resources = rest_api_resources(rest_config, team_id, job_id, None)
+ child = next(r for r in resources if r.name == config.name)
+ return child.add_map(rename_parent_fields(categories.name, {"id": "category_id"}))
+
+
def _report_endpoint(
config: ProfoundEndpointConfig,
category_id: str,
@@ -258,6 +296,17 @@ def profound_source(
column_hints=resource.column_hints,
)
+ if config.kind == "category_reference":
+ resource = _category_reference_resource(config, api_key, team_id, job_id)
+ return SourceResponse(
+ name=endpoint,
+ items=lambda: resource,
+ primary_keys=config.primary_keys,
+ partition_count=1,
+ partition_size=1,
+ column_hints=resource.column_hints,
+ )
+
end = today or datetime.now(UTC).date()
watermark = _to_report_date(db_incremental_field_last_value) if should_use_incremental_field else None
start = watermark or (end - timedelta(days=DEFAULT_REPORT_LOOKBACK_DAYS)).isoformat()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/profound/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/profound/settings.py
index bc9ec59d2151..a4f06a277bd7 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/profound/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/profound/settings.py
@@ -5,9 +5,10 @@ from posthog.dataclasses import frozen
from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType
-# Profound splits into two shapes: the organization reference lists, and the v2 report endpoints.
-# A report is a POST whose body names one category, so reports fan out over the category list.
-EndpointKind = Literal["reference", "report"]
+# Profound splits into three shapes: the organization reference lists, the per-category reference
+# lists, and the v2 report endpoints. The last two take one category each, so they fan out over the
+# category list.
+EndpointKind = Literal["reference", "category_reference", "report"]
@frozen
@@ -72,6 +73,22 @@ PROFOUND_ENDPOINTS: dict[str, ProfoundEndpointConfig] = {
kind="reference",
data_key="data",
),
+ # Per-category lists, keyed by `value` because these carry no id. `value` is unique only within a
+ # category, so the key needs `category_id` too.
+ "CitationCategories": ProfoundEndpointConfig(
+ name="CitationCategories",
+ path="/v1/org/categories/{category_id}/citation-categories",
+ kind="category_reference",
+ data_key="data",
+ primary_keys=["category_id", "value"],
+ ),
+ "CitationTags": ProfoundEndpointConfig(
+ name="CitationTags",
+ path="/v1/org/categories/{category_id}/citation-tags",
+ kind="category_reference",
+ data_key="data",
+ primary_keys=["category_id", "value"],
+ ),
# Reports, one row per category per day. `category_id` is injected from the fan-out because the
# response echoes only what was grouped on.
"Visibility": ProfoundEndpointConfig(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/profound/tests/test_profound.py b/products/warehouse_sources/backend/temporal/data_imports/sources/profound/tests/test_profound.py
index 07151d725c97..acf902c57462 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/profound/tests/test_profound.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/profound/tests/test_profound.py
@@ -189,6 +189,31 @@ class TestReferenceEndpoints:
assert [row["id"] for row in rows] == ["1"]
+ @parameterized.expand([("CitationCategories", "citation-categories"), ("CitationTags", "citation-tags")])
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_per_category_endpoints_fan_out_and_stamp_the_category(
+ self, endpoint: str, path_segment: str, MockSession
+ ) -> None:
+ # The rows carry only `value` and `name`, which repeat across categories, so `category_id`
+ # has to come from the request for the primary key to be unique.
+ session = MockSession.return_value
+ _wire(
+ session,
+ [
+ _json_response([{"id": "c1"}, {"id": "c2"}]),
+ _json_response({"data": [{"value": "owned", "name": "Owned"}]}),
+ _json_response({"data": [{"value": "owned", "name": "Owned"}]}),
+ ],
+ )
+
+ rows = _rows(_source(endpoint, _make_manager()))
+
+ urls = [c.args[0].url for c in session.send.call_args_list]
+ assert urls[1].endswith(f"/v1/org/categories/c1/{path_segment}")
+ assert urls[2].endswith(f"/v1/org/categories/c2/{path_segment}")
+ assert [(row["category_id"], row["value"]) for row in rows] == [("c1", "owned"), ("c2", "owned")]
+ assert all("_Categories_id" not in row for row in rows)
+
class TestSourceResponseShape:
@parameterized.expand(