Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Mage ai Mage ai Google Ads Discover

From Leeroopedia


Knowledge Sources
Domains Data_Integration, Google_Ads, Discovery
Last Updated 2026-02-09 00:00 GMT

Overview

Discovery module for the Mage Google Ads source connector, responsible for dynamically building the resource schema from the Google Ads API metadata and generating Singer catalog entries for all available streams and reports.

Description

This module implements the discovery phase of the Google Ads tap. It queries the GoogleAdsFieldService to introspect all available API resources, attributes, segments, and metrics, then builds a comprehensive resource schema used for catalog generation and field exclusion discovery.

Key operations:

  • get_api_objects - Queries the GoogleAdsFieldService with a GAQL query to retrieve all field metadata (name, category, data_type, selectable, filterable, sortable, selectable_with, metrics, segments, attribute_resources).
  • build_resource_metadata - Constructs metadata for each resource including its attributes, JSON schema types (mapped from Google's data type enum to JSON schema), and selectability information.
  • create_resource_schema - The main function that builds the complete resource schema. It iterates through all API objects, builds metadata, discovers field segments, and for each of the 40+ predefined STREAMS, determines field compatibility and incompatible field combinations based on selectable_with relationships.
  • do_discover - Entry point that generates catalog entries for both core streams and report streams by calling do_discover_streams.

The module defines a CATEGORY_MAP (UNSPECIFIED, UNKNOWN, RESOURCE, ATTRIBUTE, SEGMENT, METRIC) and a data_type_map mapping Google Ads data types to JSON schema types.

Usage

Called during the discovery phase to build the Singer catalog. The resource schema is also used during sync to construct valid GAQL queries.

Code Reference

Source Location

  • Repository: mage-ai
  • File: mage_integrations/mage_integrations/sources/google_ads/tap_google_ads/discover.py
  • Lines: 1-269

Signature

def get_api_objects(config):
def get_attributes(api_objects, resource):
def get_segments(resource_schema, resource):
def build_resource_metadata(api_objects, resource):
def create_resource_schema(config):
def do_discover_streams(stream_name_to_resource):
def do_discover(resource_schema):

Import

from mage_integrations.sources.google_ads.tap_google_ads.discover import (
    create_resource_schema, do_discover,
)

I/O Contract

Key Functions

Function Inputs Output Description
create_resource_schema(config) config dict dict Builds complete resource schema with fields, exclusions, and metadata for all streams
do_discover(resource_schema) resource_schema dict dict Returns Singer catalog with streams list containing schema and metadata
get_api_objects(config) config dict API response Queries GoogleAdsFieldService for all available fields
build_resource_metadata(api_objects, resource) api_objects, resource dict Constructs metadata for a single resource with attributes and JSON schema

Supported Streams

The module defines 40+ predefined streams including: accessible_bidding_strategy, ad_group, ad_group_ad, ad_group_criterion, campaign, campaign_budget, customer, keyword_view, click_view, video, and many more.

Data Type Mapping

Google Type ID JSON Schema Type
2 boolean
3 string (date-time format)
4, 5, 6, 11 string
7, 8, 12 integer
9, 10 string (with properties)

Usage Examples

from mage_integrations.sources.google_ads.tap_google_ads.discover import create_resource_schema, do_discover

# Build resource schema from Google Ads API metadata
resource_schema = create_resource_schema(config)

# Generate Singer catalog
catalog = do_discover(resource_schema)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment