: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
feat(data-warehouse): add arcade views, dropoff and total plays tables (#116960)
Tom Owersc6c8dc5342bb
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.mdindex 256c353d7081..9ef7d9a9b058 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@@ -823,10 +823,10 @@ Today (4): `company_leads`, `flow_engagement`, `teams`, `users`Diffed against: <https://docs.arcade.software/kb/leverage/advanced-features/rest-api/insights-api>-- [ ] `Views (POST /insights, type=views)` — supplies unique demo viewers, the denominator for conversion from viewing to playing (high)-- [ ] `Dropoff (POST /insights, type=dropoff)` — shows where viewers leave each demo and which steps prevent completion (high)-- [ ] `Authenticated Views (POST /insights, type=authenticatedViews)` — connects identified viewers and completion status to customer and sales records (high)-- [ ] `Total Plays (POST /insights, type=totalPlays)` — counts unique players across demos without double-counting people who play several flows (high)+- [x] `Views (POST /insights, type=views)` — supplies unique demo viewers, the denominator for conversion from viewing to playing (high)+- [x] `Dropoff (POST /insights, type=dropoff)` — shows where viewers leave each demo and which steps prevent completion (high)+- [x] `Authenticated Views (POST /insights, type=authenticatedViews)` — connects identified viewers and completion status to customer and sales records (high)+- [x] `Total Plays (POST /insights, type=totalPlays)` — counts unique players across demos without double-counting people who play several flows (high)- [ ] `Play Time (POST /insights, type=playTime)` — measures time spent in each demo to compare engagement quality (medium)- [ ] `Views by Custom Link (POST /insights, type=viewsByCustomLinkId)` — measures the audience reached by each shared demo link (medium)- [ ] `Plays by Custom Link (POST /insights, type=playsByCustomLinkId)` — compares plays, completions, and CTA clicks across shared demo links (medium)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/arcade.py b/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/arcade.pyindex 3727867fbba3..e0bc55c23f60 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/arcade.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/arcade.py@@ -1,6 +1,9 @@+from collections.abc import Iteratorfrom datetime import UTC, date, datetimefrom typing import Any, cast+from requests import Session+from posthog.dataclasses import frozenfrom products.warehouse_sources.backend.temporal.data_imports.sources.arcade.settings import (@@ -13,6 +16,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.arcade.setPLAN_ERROR,PROVISIONING_ERROR,)+from products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_sessionfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source import (RESTAPIConfig,rest_api_resource,@@ -61,6 +65,7 @@ class ArcadeResumeConfig:period_start: strperiod_end: strcompleted: bool = False+ flow_index: int = 0def parse_start_date(value: str) -> str:@@ -74,7 +79,13 @@ def parse_start_date(value: str) -> str:def get_resource(- config: ArcadeSourceConfig, name: str, period_start: str, period_end: str, *, probe: bool = False+ config: ArcadeSourceConfig,+ name: str,+ period_start: str,+ period_end: str,+ *,+ probe: bool = False,+ flow_id: str | None = None,) -> EndpointResource:if name not in ENDPOINTS:raise ValueError("Unknown Arcade table. Select a table from the source settings.")@@ -90,8 +101,12 @@ def get_resource(endpoint["method"] = "POST"payload: dict[str, Any] = {"type": definition.insight_type, "teamId": config.team_id}endpoint["json"] = payload+ if definition.windowed:+ payload.update({"from": period_start, "to": period_end})+ if flow_id is not None:+ payload["flowId"] = flow_idif name == "flow_engagement":- payload.update({"from": period_start, "to": period_end, "size": 1 if probe else PAGE_SIZE})+ payload["size"] = 1 if probe else PAGE_SIZEendpoint["paginator"] = cast(PaginatorConfig,{@@ -105,15 +120,19 @@ def get_resource(def add_context(row: dict[str, Any]) -> dict[str, Any]:if definition.insight_type:row = {**row, "team_id": config.team_id}- if name == "flow_engagement":+ if flow_id is not None:+ row = {**row, "flowId": flow_id}+ if definition.windowed:row = {**row, "period_start": period_start, "period_end": period_end}return rowreturn {"name": name, "endpoint": endpoint, "write_disposition": "replace", "data_map": add_context}-def rest_config(config: ArcadeSourceConfig, resource: EndpointResource) -> RESTAPIConfig:- return {+def rest_config(+ config: ArcadeSourceConfig, resource: EndpointResource, session: Session | None = None+) -> RESTAPIConfig:+ rest: RESTAPIConfig = {"client": {"base_url": BASE_URL,"auth": {"type": "api_key", "api_key": config.api_key, "name": "Authorization", "location": "header"},@@ -123,12 +142,19 @@ def rest_config(config: ArcadeSourceConfig, resource: EndpointResource) -> RESTA},"resources": [resource],}+ if session is not None:+ rest["client"]["session"] = session+ return restdef validate_credentials(config: ArcadeSourceConfig, team_id: int, schema_name: str | None) -> tuple[bool, str | None]:try:start = parse_start_date(config.start_date)- resource_config = get_resource(config, schema_name or "teams", start, datetime.now(UTC).isoformat(), probe=True)+ name = schema_name or "teams"+ # Per-flow insights need a flow ID, so probe the flow listing that supplies it with the same scope.+ if name in ENDPOINTS and ENDPOINTS[name].per_flow:+ name = "flow_engagement"+ resource_config = get_resource(config, name, start, datetime.now(UTC).isoformat(), probe=True)except ValueError as error:return False, str(error)resource = rest_api_resource(rest_config(config, resource_config), team_id, "arcade_validate", None)@@ -144,6 +170,50 @@ def validate_credentials(config: ArcadeSourceConfig, team_id: int, schema_name:return True, None+def flow_rows(+ config: ArcadeSourceConfig,+ name: str,+ team_id: int,+ job_id: str,+ manager: ResumableSourceManager[ArcadeResumeConfig],+ period_start: str,+ period_end: str,+ resume: ArcadeResumeConfig | None,+) -> Iterator[list[dict[str, Any]]]:+ # The Insights API has no flow list, so the paginated overviewPlays report supplies the flow IDs.+ first_page = resume.page if resume else 1+ skip = resume.flow_index if resume else 0+ session = make_tracked_session(redact_values=(config.api_key,), allow_redirects=False)+ flows = rest_api_resource(+ rest_config(config, get_resource(config, "flow_engagement", period_start, period_end), session),+ team_id,+ job_id,+ None,+ initial_paginator_state={"page": first_page},+ )+ page = first_page+ for page, flow_page in enumerate(flows, start=first_page):+ for index, flow in enumerate(flow_page):+ if page == first_page and index < skip:+ continue+ flow_resource = rest_api_resource(+ rest_config(+ config, get_resource(config, name, period_start, period_end, flow_id=flow["flowId"]), session+ ),+ team_id,+ job_id,+ None,+ )+ rows = [row for flow_rows_page in flow_resource for row in flow_rows_page]+ manager.save_state(+ ArcadeResumeConfig(page=page, period_start=period_start, period_end=period_end, flow_index=index + 1)+ )+ if rows:+ yield rows+ manager.safe_point()+ manager.save_state(ArcadeResumeConfig(page=page, period_start=period_start, period_end=period_end, completed=True))++def arcade_source(config: ArcadeSourceConfig,name: str,@@ -157,6 +227,12 @@ def arcade_source(resource_config = get_resource(config, name, period_start, period_end)if resume and resume.completed:return SourceResponse(name=name, items=lambda: iter(()), primary_keys=list(ENDPOINTS[name].primary_keys))+ if ENDPOINTS[name].per_flow:+ return SourceResponse(+ name=name,+ items=lambda: flow_rows(config, name, team_id, job_id, manager, period_start, period_end, resume),+ primary_keys=list(ENDPOINTS[name].primary_keys),+ )def save_state(state: dict[str, Any] | None) -> None:manager.save_state(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/canonical_descriptions.pyindex f19fe4adfcf4..adeb9b69eadf 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/canonical_descriptions.py@@ -46,4 +46,63 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"flows": "Flows played by viewers from this company.",},},+ "total_plays": {+ "description": "Engagement totals across every flow in the team during the requested period.",+ "docs_url": INSIGHTS_DOCS_URL,+ "columns": {+ "team_id": "Arcade team identifier supplied with the request.",+ "period_start": "Start of the requested engagement period, added by the connector.",+ "period_end": "End of the requested engagement period, added by the connector.",+ "players": "Unique viewers across all flows.",+ "plays": "Unique play sessions.",+ "completers": "Unique viewers who completed a flow.",+ "completions": "Sessions that completed a flow.",+ "anyCtaClickers": "Unique viewers who clicked any call to action.",+ "anyCtaClicks": "Clicks on any call to action.",+ "finalCtaClickers": "Unique viewers who clicked the final call to action.",+ "finalCtaClicks": "Clicks on the final call to action.",+ },+ },+ "flow_views": {+ "description": "Unique viewers of each flow during the requested period.",+ "docs_url": INSIGHTS_DOCS_URL,+ "columns": {+ "flowId": "Flow identifier, added by the connector.",+ "team_id": "Arcade team identifier supplied with the request.",+ "period_start": "Start of the requested engagement period, added by the connector.",+ "period_end": "End of the requested engagement period, added by the connector.",+ "viewers": "Unique viewers of the flow.",+ },+ },+ "flow_dropoff": {+ "description": "Step dropoff for each flow during the requested period.",+ "docs_url": INSIGHTS_DOCS_URL,+ "columns": {+ "flowId": "Flow identifier, added by the connector.",+ "stepId": "Step identifier.",+ "team_id": "Arcade team identifier supplied with the request.",+ "period_start": "Start of the requested engagement period, added by the connector.",+ "period_end": "End of the requested engagement period, added by the connector.",+ "reached": "Viewers who reached the step.",+ "droppedOff": "Viewers who left the flow at the step.",+ "transitions": "Viewer counts for each next step, keyed by step identifier.",+ },+ },+ "authenticated_views": {+ "description": "Identified viewers of each flow during the requested period, with completion status.",+ "docs_url": INSIGHTS_DOCS_URL,+ "columns": {+ "flowId": "Flow identifier, added by the connector.",+ "team_id": "Arcade team identifier supplied with the request.",+ "period_start": "Start of the requested engagement period, added by the connector.",+ "period_end": "End of the requested engagement period, added by the connector.",+ "email": "Viewer email address.",+ "userName": "Viewer name.",+ "userPhotoURL": "URL of the viewer photo.",+ "companyName": "Viewer company name.",+ "companyLogo": "URL of the viewer company logo.",+ "lastViewedDate": "Time the viewer last viewed the flow.",+ "completed": "Whether the viewer completed the flow.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/settings.pyindex fcd7fca238c5..7072947d1119 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/settings.py@@ -18,15 +18,44 @@ class ArcadeEndpoint:selector: strprimary_keys: tuple[str, ...]insight_type: str | None = None+ windowed: bool = False+ per_flow: bool = FalseENDPOINTS = {"teams": ArcadeEndpoint(path="teams", selector="teams", primary_keys=("id",)),"users": ArcadeEndpoint(path="users", selector="users", primary_keys=("id",)),"flow_engagement": ArcadeEndpoint(- path="insights", selector="$", primary_keys=("team_id", "flowId"), insight_type="overviewPlays"+ path="insights", selector="$", primary_keys=("team_id", "flowId"), insight_type="overviewPlays", windowed=True),"company_leads": ArcadeEndpoint(path="insights", selector="$", primary_keys=("team_id", "id"), insight_type="companiesForLeads"),+ "total_plays": ArcadeEndpoint(+ path="insights", selector="$", primary_keys=("team_id",), insight_type="totalPlays", windowed=True+ ),+ "flow_views": ArcadeEndpoint(+ path="insights",+ selector="$",+ primary_keys=("team_id", "flowId"),+ insight_type="views",+ windowed=True,+ per_flow=True,+ ),+ "flow_dropoff": ArcadeEndpoint(+ path="insights",+ selector="$",+ primary_keys=("team_id", "flowId", "stepId"),+ insight_type="dropoff",+ windowed=True,+ per_flow=True,+ ),+ "authenticated_views": ArcadeEndpoint(+ path="insights",+ selector="$",+ primary_keys=("team_id", "flowId", "email"),+ insight_type="authenticatedViews",+ windowed=True,+ per_flow=True,+ ),}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/source.pyindex c0b1ca4abbde..98b3a99af303 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/source.py@@ -91,7 +91,7 @@ class ArcadeSource(ResumableSource[ArcadeSourceConfig, ArcadeResumeConfig]):caption=("Requires an Arcade Enterprise workspace. Create an API key in Settings > Advanced. ""Enable insights access for engagement data. Enable User provisioning for teams and users. "- "All tables use full refresh. Flow engagement includes totals from your start date through each sync."+ "All tables use full refresh. Engagement tables include totals from your start date through each sync."),fields=cast(list[FieldType],diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/tests/test_arcade.py b/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/tests/test_arcade.pyindex cf13bafeeb04..7c2b27dd1e67 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/tests/test_arcade.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/arcade/tests/test_arcade.py@@ -91,6 +91,27 @@ def test_flow_pages_and_resume(config: ArcadeSourceConfig, resume_page: int | No"insights",{"type": "companiesForLeads", "teamId": "team-example"},),+ (+ "total_plays",+ {"players": 12, "plays": 20},+ [+ {+ "players": 12,+ "plays": 20,+ "team_id": "team-example",+ "period_start": "2025-01-01T00:00:00+00:00",+ "period_end": "2025-02-01T00:00:00+00:00",+ }+ ],+ "POST",+ "insights",+ {+ "type": "totalPlays",+ "teamId": "team-example",+ "from": "2025-01-01T00:00:00+00:00",+ "to": "2025-02-01T00:00:00+00:00",+ },+ ),],)def test_single_page_tables(@@ -115,7 +136,91 @@ def test_single_page_tables(assert result.saved_states[-1].completed[email protected]("name", ["teams", "flow_engagement"])+ ("name", "insight_type", "answers", "expected_rows"),+ [+ (+ "flow_views",+ "views",+ [{"viewers": 4}, {"viewers": 6}],+ [{"viewers": 4, "flowId": "flow-one"}, {"viewers": 6, "flowId": "flow-two"}],+ ),+ (+ "flow_dropoff",+ "dropoff",+ [[{"stepId": "step-a", "reached": 5}], []],+ [{"stepId": "step-a", "reached": 5, "flowId": "flow-one"}],+ ),+ (+ "authenticated_views",+ "authenticatedViews",+ [[], [{"email": "[email protected]", "completed": True}]],+ [{"email": "[email protected]", "completed": True, "flowId": "flow-two"}],+ ),+ ],+)[email protected]("resume_index", [None, 1])+def test_per_flow_tables_fan_out_over_flows(+ config: ArcadeSourceConfig,+ name: str,+ insight_type: str,+ answers: list[object],+ expected_rows: list[dict[str, Any]],+ resume_index: int | None,+) -> None:+ resume_state = (+ ArcadeResumeConfig(+ page=1,+ period_start="2025-01-01T00:00:00+00:00",+ period_end="2025-02-01T00:00:00+00:00",+ flow_index=resume_index,+ )+ if resume_index+ else None+ )+ flow_answers = answers[resume_index or 0 :]+ result = SourceDriver(ArcadeSource(), config).run(+ name,+ [+ ScriptedResponse(json=[{"flowId": "flow-one"}, {"flowId": "flow-two"}]),+ *(ScriptedResponse(json=answer) for answer in flow_answers),+ ScriptedResponse(json=[]),+ ],+ resume_state=resume_state,+ )++ assert result.raised is None+ expected_flows = ["flow-one", "flow-two"][resume_index or 0 :]+ assert result.rows == [+ {+ **row,+ "team_id": "team-example",+ "period_start": "2025-01-01T00:00:00+00:00",+ "period_end": "2025-02-01T00:00:00+00:00",+ }+ for row in expected_rows+ if row["flowId"] in expected_flows+ ]+ bodies = [request.json() for request in result.requests]+ assert [body["type"] for body in bodies] == [+ "overviewPlays",+ *[insight_type] * len(expected_flows),+ "overviewPlays",+ ]+ assert [body["page"] for body in (bodies[0], bodies[-1])] == [1, 2]+ for body, flow_id in zip(bodies[1:-1], expected_flows):+ assert body == {+ "type": insight_type,+ "teamId": "team-example",+ "flowId": flow_id,+ "from": "2025-01-01T00:00:00+00:00",+ "to": "2025-02-01T00:00:00+00:00",+ }+ assert [state.flow_index for state in result.saved_states[:-1]] == [1, 2][resume_index or 0 :]+ assert result.saved_states[-1].completed++[email protected]("name", ["teams", "flow_engagement", "flow_views"])def test_completed_resume_does_not_repeat_rows(config: ArcadeSourceConfig, name: str) -> None:result = SourceDriver(ArcadeSource(), config).run(name,@@ -199,11 +304,13 @@ def test_unknown_table_does_not_send_requests(config: ArcadeSourceConfig) -> Nonassert result.requests == []-def test_validation_uses_one_small_insights_page(config: ArcadeSourceConfig) -> None:[email protected]("name", ["flow_engagement", "flow_views"])+def test_validation_uses_one_small_insights_page(config: ArcadeSourceConfig, name: str) -> None:with scripted_network([ScriptedResponse(json=[{"flowId": "flow-one"}])]) as network:- assert validate_credentials(config, 1, "flow_engagement") == (True, None)+ assert validate_credentials(config, 1, name) == (True, None)assert len(network.requests_log) == 1+ assert network.requests_log[0].json()["type"] == "overviewPlays"assert network.requests_log[0].json()["size"] == 1