Skip to content

bug: Process product custom_targeting_keys through targeting manager for GAM line items #1034

@lclaudon

Description

@lclaudon

Bug:
Approving a media buy with a GAM product that has custom_targeting_keys in the "groups" format fails with:

Order created but failed to create line items: 'groups'

Root cause:
In src/adapters/gam/managers/orders.py (lines 467-473), product-level custom_targeting_keys from implementation_config are merged raw into the GAM line item's customTargeting dict by iterating over the dict keys. When the targeting uses the "groups" format ({"groups": [{"criteria": [...]}]}), the key "groups" is inserted directly into what should be a GAM CustomCriteriaSet structure (which expects xsi_type, logicalOperator, children). When zeep serializes this to the GAM SOAP API, it encounters the unknown "groups" field and raises KeyError('groups').

The targeting manager (src/adapters/gam/managers/targeting.py) already has _build_custom_targeting_structure() which correctly handles all three custom targeting formats (legacy, enhanced, groups) and produces valid GAM structures - but it was not being used for product-level custom targeting in the line item creation path.

Proposed Fix:
Route product custom_targeting_keys through targeting_manager._build_custom_targeting_structure() before merging with buyer targeting. When both buyer and product targeting exist, combine them under an AND CustomCriteriaSet. Pass the targeting manager from google_ad_manager.py into create_line_items().

Files changed:

  • src/adapters/gam/managers/orders.py — replace raw dict merge with proper targeting manager processing
  • src/adapters/google_ad_manager.py — pass targeting_manager to create_line_items()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Ready for Dev

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions