: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
from typing import Optional, cast
from products.warehouse_sources.sources.outbrain._config import OutbrainSourceConfig
from products.warehouse_sources.sources.outbrain.outbrain import (
OutbrainResumeConfig,
outbrain_source,
validate_credentials as validate_outbrain_credentials,
)
from products.warehouse_sources.sources.outbrain.settings import ENDPOINTS, INCREMENTAL_FIELDS
from products.warehouse_sources.sources.sdk import (
CanonicalDescriptions,
DataWarehouseSourceCategory,
ExternalDataSourceType,
FieldType,
ReleaseStatus,
ResumableSource,
ResumableSourceManager,
SourceConfig,
SourceFieldInputConfig,
SourceFieldInputConfigType,
SourceInputs,
SourceRegistry,
SourceResponse,
SourceSchema,
build_endpoint_schemas,
detect,
)
@SourceRegistry.register
class OutbrainSource(ResumableSource[OutbrainSourceConfig, OutbrainResumeConfig]):
codebase_detection = detect(env=("^OUTBRAIN_",), script_hosts=("amplify.outbrain.com", "widgets.outbrain.com"))
supported_versions = ("v0.1",)
default_version = "v0.1"
api_docs_url = "https://developers.outbrain.com"
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
@property
def source_type(self) -> ExternalDataSourceType:
return ExternalDataSourceType.OUTBRAIN
def get_canonical_descriptions(self) -> CanonicalDescriptions:
from products.warehouse_sources.sources.outbrain.canonical_descriptions import CANONICAL_DESCRIPTIONS
return CANONICAL_DESCRIPTIONS
def get_non_retryable_errors(self) -> dict[str, str | None]:
return {
"401 Client Error: Unauthorized for url: https://api.outbrain.com/amplify/v0.1/login": "Outbrain authentication failed. Please check your username and password.",
"403 Client Error: Forbidden for url: https://api.outbrain.com": "Outbrain denied access. Please check that your account has Amplify API access (requested via your account manager).",
# A 400 on a well-formed, static request is deterministic, so retrying can never succeed.
# It surfaces when one of the marketers returned by /marketers can't be queried through
# the Amplify API, so match the stable prefix, not the volatile marketer id and query.
"400 Client Error: Bad Request for url: https://api.outbrain.com": "Outbrain rejected the request (400 Bad Request). One of the marketers on your account may not be accessible via the Amplify API. Please confirm your account's Amplify API access with your Outbrain account manager.",
}
@property
def get_source_config(self) -> SourceConfig:
return SourceConfig(
name=ExternalDataSourceType.OUTBRAIN,
category=DataWarehouseSourceCategory.ADVERTISING,
label="Outbrain",
caption="""Connect your Outbrain Amplify account to pull your advertising data into the PostHog Data warehouse.
Uses your Outbrain login credentials. Amplify API access must be enabled for your account — request it through your Outbrain account manager if API calls are rejected.""",
iconPath="/static/services/outbrain.png",
docsUrl="https://posthog.com/docs/cdp/sources/outbrain",
releaseStatus=ReleaseStatus.GA,
fields=cast(
list[FieldType],
[
SourceFieldInputConfig(
name="username",
label="Username",
type=SourceFieldInputConfigType.TEXT,
required=True,
placeholder="[email protected]",
secret=False,
),
SourceFieldInputConfig(
name="password",
label="Password",
type=SourceFieldInputConfigType.PASSWORD,
required=True,
placeholder="",
secret=True,
),
],
),
)
def get_schemas(
self,
config: OutbrainSourceConfig,
team_id: int,
with_counts: bool = False,
names: list[str] | None = None,
force_refresh: bool = False,
api_version: str | None = None,
) -> list[SourceSchema]:
return build_endpoint_schemas(ENDPOINTS, INCREMENTAL_FIELDS, names)
def validate_credentials(
self,
config: OutbrainSourceConfig,
team_id: int,
schema_name: Optional[str] = None,
api_version: str | None = None,
) -> tuple[bool, str | None]:
if validate_outbrain_credentials(config.username, config.password):
return True, None
return False, "Invalid Outbrain credentials"
def get_resumable_source_manager(self, inputs: SourceInputs) -> ResumableSourceManager[OutbrainResumeConfig]:
return ResumableSourceManager[OutbrainResumeConfig](inputs, OutbrainResumeConfig)
def source_for_pipeline(
self,
config: OutbrainSourceConfig,
resumable_source_manager: ResumableSourceManager[OutbrainResumeConfig],
inputs: SourceInputs,
) -> SourceResponse:
return outbrain_source(
username=config.username,
password=config.password,
endpoint=inputs.schema_name,
logger=inputs.logger,
resumable_source_manager=resumable_source_manager,
should_use_incremental_field=inputs.should_use_incremental_field,
db_incremental_field_last_value=inputs.db_incremental_field_last_value
if inputs.should_use_incremental_field
else None,
)