adloop 0.37.1__tar.gz → 0.38.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. {adloop-0.37.1 → adloop-0.38.1}/PKG-INFO +2 -2
  2. {adloop-0.37.1 → adloop-0.38.1}/README.md +1 -1
  3. {adloop-0.37.1 → adloop-0.38.1}/pyproject.toml +1 -1
  4. {adloop-0.37.1 → adloop-0.38.1}/pyproject.toml.orig +1 -1
  5. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/assets.py +40 -3
  6. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/write.py +95 -83
  7. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/rules/adloop.md +2 -2
  8. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/server.py +25 -6
  9. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/__init__.py +0 -0
  10. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/__main__.py +0 -0
  11. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/_mcp_patches.py +0 -0
  12. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/__init__.py +0 -0
  13. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/ai_max.py +0 -0
  14. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/audiences.py +0 -0
  15. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/brands.py +0 -0
  16. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/campaign_settings.py +0 -0
  17. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/client.py +0 -0
  18. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/conversion_actions.py +0 -0
  19. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/currency.py +0 -0
  20. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/custom_conversion_goals.py +0 -0
  21. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/enums.py +0 -0
  22. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/forecast.py +0 -0
  23. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/gaql.py +0 -0
  24. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/image_fetch.py +0 -0
  25. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/pmax.py +0 -0
  26. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/read.py +0 -0
  27. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/recommendation_subscriptions.py +0 -0
  28. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/recommendations.py +0 -0
  29. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/shopping.py +0 -0
  30. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/snippet_headers.py +0 -0
  31. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ads/validate_only.py +0 -0
  32. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/auth.py +0 -0
  33. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/cli.py +0 -0
  34. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/config.py +0 -0
  35. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/crossref.py +0 -0
  36. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/diagnostics.py +0 -0
  37. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ga4/__init__.py +0 -0
  38. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ga4/client.py +0 -0
  39. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ga4/reports.py +0 -0
  40. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ga4/tracking.py +0 -0
  41. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/ga4/write.py +0 -0
  42. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/gsc/__init__.py +0 -0
  43. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/gsc/client.py +0 -0
  44. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/gsc/reports.py +0 -0
  45. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/gtm/__init__.py +0 -0
  46. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/gtm/client.py +0 -0
  47. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/gtm/entities.py +0 -0
  48. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/gtm/read.py +0 -0
  49. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/gtm/write.py +0 -0
  50. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/merchant/__init__.py +0 -0
  51. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/merchant/client.py +0 -0
  52. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/merchant/read.py +0 -0
  53. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/pagespeed.py +0 -0
  54. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/reddit/__init__.py +0 -0
  55. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/reddit/auth.py +0 -0
  56. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/reddit/client.py +0 -0
  57. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/reddit/read.py +0 -0
  58. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/reddit/schedule.py +0 -0
  59. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/reddit/write.py +0 -0
  60. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/rules/__init__.py +0 -0
  61. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/rules/commands/analyze-performance.md +0 -0
  62. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/rules/commands/budget-plan.md +0 -0
  63. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/rules/commands/create-ad.md +0 -0
  64. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/rules/commands/create-campaign.md +0 -0
  65. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/rules/commands/diagnose-tracking.md +0 -0
  66. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/rules/commands/optimize-campaign.md +0 -0
  67. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/rules_install.py +0 -0
  68. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/runtime.py +0 -0
  69. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/safety/__init__.py +0 -0
  70. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/safety/approval.py +0 -0
  71. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/safety/approval_card.html +0 -0
  72. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/safety/audit.py +0 -0
  73. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/safety/guards.py +0 -0
  74. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/safety/preview.py +0 -0
  75. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/tracking.py +0 -0
  76. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/upload_card.html +0 -0
  77. {adloop-0.37.1 → adloop-0.38.1}/src/adloop/uploads.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: adloop
3
- Version: 0.37.1
3
+ Version: 0.38.1
4
4
  Summary: The AI command center for Google Ads, Reddit Ads, GA4, and tracking code.
5
5
  Keywords: mcp,google-ads,reddit-ads,google-analytics,ga4,cursor,marketing
6
6
  Author: Daniel Klose
@@ -316,7 +316,7 @@ All write operations follow a **draft → preview → confirm** workflow. Nothin
316
316
  | `add_ad_schedule` | Add ad schedule windows to a campaign; overlaps are refused, and a campaign's first schedule needs a double confirmation. |
317
317
  | `draft_promotion` / `update_promotion` | Create a promotion asset, or edit one in place without losing the fields you don't pass; amounts in the account currency. |
318
318
  | `draft_price_asset` | Create a price asset with 3-8 offerings, in the account currency. |
319
- | `draft_image_assets` | Create campaign image assets from local files, public image URLs or uploads (PNG, JPEG, or GIF). |
319
+ | `draft_image_assets` | Create campaign image assets from local files, public image URLs or uploads (PNG, JPEG, or GIF); a business logo can also go on the account. |
320
320
  | `draft_keywords` | Propose keyword additions with match types. Proactively checks bidding strategy — flags BROAD match on campaigns without Smart Bidding as dangerous in the preview. |
321
321
  | `add_negative_keywords` | Propose negative keywords directly on a campaign |
322
322
  | `add_negative_locations` | Propose negative geo exclusions on a campaign — exclude cities/regions while keeping broader positive targets |
@@ -288,7 +288,7 @@ All write operations follow a **draft → preview → confirm** workflow. Nothin
288
288
  | `add_ad_schedule` | Add ad schedule windows to a campaign; overlaps are refused, and a campaign's first schedule needs a double confirmation. |
289
289
  | `draft_promotion` / `update_promotion` | Create a promotion asset, or edit one in place without losing the fields you don't pass; amounts in the account currency. |
290
290
  | `draft_price_asset` | Create a price asset with 3-8 offerings, in the account currency. |
291
- | `draft_image_assets` | Create campaign image assets from local files, public image URLs or uploads (PNG, JPEG, or GIF). |
291
+ | `draft_image_assets` | Create campaign image assets from local files, public image URLs or uploads (PNG, JPEG, or GIF); a business logo can also go on the account. |
292
292
  | `draft_keywords` | Propose keyword additions with match types. Proactively checks bidding strategy — flags BROAD match on campaigns without Smart Bidding as dangerous in the preview. |
293
293
  | `add_negative_keywords` | Propose negative keywords directly on a campaign |
294
294
  | `add_negative_locations` | Propose negative geo exclusions on a campaign — exclude cities/regions while keeping broader positive targets |
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "adloop"
3
- version = "0.37.1"
3
+ version = "0.38.1"
4
4
  description = "The AI command center for Google Ads, Reddit Ads, GA4, and tracking code."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "adloop"
3
- version = "0.37.1"
3
+ version = "0.38.1"
4
4
  description = "The AI command center for Google Ads, Reddit Ads, GA4, and tracking code."
5
5
  readme = "README.md"
6
6
  authors = [
@@ -320,6 +320,35 @@ def draft_business_name_asset(
320
320
  return preview
321
321
 
322
322
 
323
+ def _account_logo_refusal(config: AdLoopConfig, customer_id: str, new_logos: int) -> str:
324
+ """Why the account cannot take ``new_logos`` more business logos, or "".
325
+
326
+ Google allows one enabled account-level business logo and answers a
327
+ second only at the dry run, with RESOURCE_LIMIT
328
+ (ENABLED_FAVICON_ASSET_LINKS_PER_CUSTOMER). Say it at the draft instead,
329
+ with the link to remove.
330
+ """
331
+ from adloop.ads.gaql import execute_query
332
+
333
+ if not new_logos:
334
+ return ""
335
+ if new_logos > 1:
336
+ return f"Google allows one business logo per account; this draft links {new_logos}."
337
+ rows = execute_query(config, customer_id, (
338
+ "SELECT asset.id, asset.name FROM customer_asset "
339
+ "WHERE customer_asset.field_type = 'BUSINESS_LOGO' AND customer_asset.status = 'ENABLED'"))
340
+ if not rows:
341
+ return ""
342
+ asset_id = rows[0].get("asset.id")
343
+ name = rows[0].get("asset.name")
344
+ current = f"asset {asset_id} '{name}'" if name else f"asset {asset_id}"
345
+ return (
346
+ f"The account already has a business logo ({current}), and Google allows one per "
347
+ "account. To replace it, remove its account link first with remove_entity("
348
+ f'entity_type="customer_asset", entity_id="{asset_id}~BUSINESS_LOGO"), then draft again.'
349
+ )
350
+
351
+
323
352
  def link_asset_to_customer(
324
353
  config: AdLoopConfig,
325
354
  *,
@@ -376,6 +405,12 @@ def link_asset_to_customer(
376
405
  )
377
406
  elif row.get("asset.name"):
378
407
  link["asset_name"] = row["asset.name"]
408
+ if not errors:
409
+ refusal = _account_logo_refusal(
410
+ config, customer_id, sum(link["field_type"] == "BUSINESS_LOGO" for link in validated)
411
+ )
412
+ if refusal:
413
+ errors.append(refusal)
379
414
  if errors:
380
415
  return {"error": "Validation failed", "details": errors}
381
416
 
@@ -609,7 +644,8 @@ def _create_and_link(client, cid: str, assets: list[dict], field_type, populate,
609
644
  """Create assets and link them at the plan's scope in one Mutate.
610
645
 
611
646
  Plans from before scopes existed have no ``scope`` and link to their
612
- campaign, as they always did.
647
+ campaign, as they always did. ``field_type`` is one enum value for all
648
+ assets, or a function of the asset's payload.
613
649
  """
614
650
  scope = changes.get("scope") or "campaign"
615
651
  asset_service = client.get_service("AssetService")
@@ -621,9 +657,10 @@ def _create_and_link(client, cid: str, assets: list[dict], field_type, populate,
621
657
  asset.resource_name = asset_service.asset_path(cid, str(-(i + 1)))
622
658
  populate(asset, payload)
623
659
  operations.append(op)
624
- for i in range(len(assets)):
660
+ for i, payload in enumerate(assets):
625
661
  operations.append(_link_operation(
626
- client, cid, asset_service.asset_path(cid, str(-(i + 1))), field_type, scope,
662
+ client, cid, asset_service.asset_path(cid, str(-(i + 1))),
663
+ field_type(payload) if callable(field_type) else field_type, scope,
627
664
  changes.get("campaign_id", ""), changes.get("ad_group_id", ""),
628
665
  ))
629
666
  response = googleads_service.mutate(customer_id=cid, mutate_operations=operations)
@@ -2590,14 +2590,27 @@ def draft_image_assets(
2590
2590
  image_paths: list[str] | None = None,
2591
2591
  image_urls: list[str] | None = None,
2592
2592
  upload_ids: list[str] | None = None,
2593
+ scope: str = "",
2594
+ field_types: list[str] | None = None,
2593
2595
  ) -> dict:
2594
- """Draft campaign image assets from local files, public image URLs and/or uploads.
2596
+ """Draft image assets from local files, public image URLs and/or uploads.
2595
2597
 
2596
2598
  URL images are fetched now (public addresses only, pinned against DNS
2597
2599
  rebinding, capped at Google's 5120 KB limit) and their sha256 is kept
2598
2600
  in the plan; apply re-fetches and refuses if the bytes changed. Uploads
2599
2601
  (``up_...`` ids from the upload card or link) are pinned the same way.
2602
+
2603
+ Google links AD_IMAGE to campaigns and BUSINESS_LOGO to campaigns or the
2604
+ account. A campaign link defaults to AD_IMAGE. Account scope has to be
2605
+ explicit (``scope="account"``) and takes BUSINESS_LOGO only, named in
2606
+ ``field_types``: one entry per image, in the order uploads, paths, URLs.
2600
2607
  """
2608
+ from adloop.ads.assets import (
2609
+ _account_logo_refusal,
2610
+ _account_scope_warning,
2611
+ resolve_scope,
2612
+ scope_entity,
2613
+ )
2601
2614
  from adloop.runtime import deployment_mode
2602
2615
  from adloop.safety.guards import SafetyViolation, check_blocked_operation
2603
2616
  from adloop.safety.preview import ChangePlan, store_plan
@@ -2619,25 +2632,41 @@ def draft_image_assets(
2619
2632
  except SafetyViolation as e:
2620
2633
  return {"error": str(e)}
2621
2634
 
2622
- validated_images, errors = _validate_image_assets(
2623
- campaign_id, image_paths, image_urls, list(upload_ids or [])
2635
+ scope, campaign_id, _, errors = resolve_scope(scope, campaign_id, "", allowed=("campaign", "account"))
2636
+ validated_images, image_errors = _validate_image_assets(
2637
+ image_paths, image_urls, list(upload_ids or [])
2624
2638
  )
2639
+ errors.extend(image_errors)
2640
+ if not errors:
2641
+ errors.extend(_assign_image_field_types(validated_images, scope, field_types))
2642
+ if not errors and scope == "account":
2643
+ refusal = _account_logo_refusal(
2644
+ config, customer_id, sum(image["field_type"] == "BUSINESS_LOGO" for image in validated_images)
2645
+ )
2646
+ if refusal:
2647
+ errors.append(refusal)
2625
2648
  if errors:
2626
2649
  return {"error": "Validation failed", "details": errors}
2627
2650
 
2651
+ entity_type, entity_id = scope_entity(scope, customer_id, campaign_id, "")
2628
2652
  plan = ChangePlan(
2629
2653
  operation="create_image_assets",
2630
- entity_type="campaign_asset",
2631
- entity_id=campaign_id,
2654
+ entity_type=entity_type,
2655
+ entity_id=entity_id,
2632
2656
  customer_id=customer_id,
2633
2657
  changes={
2658
+ "scope": scope,
2634
2659
  "campaign_id": campaign_id,
2635
2660
  "images": validated_images,
2636
2661
  "summary": [_describe_image(image) for image in validated_images],
2662
+ "field_types": [image["field_type"] for image in validated_images],
2637
2663
  },
2638
2664
  )
2639
2665
  store_plan(plan)
2640
- return plan.to_preview()
2666
+ preview = plan.to_preview()
2667
+ if scope == "account":
2668
+ preview["warnings"] = [_account_scope_warning("business logos")]
2669
+ return preview
2641
2670
 
2642
2671
 
2643
2672
  def draft_sitelinks(
@@ -2646,8 +2675,12 @@ def draft_sitelinks(
2646
2675
  customer_id: str = "",
2647
2676
  campaign_id: str = "",
2648
2677
  sitelinks: list[dict] | None = None,
2678
+ scope: str = "",
2649
2679
  ) -> dict:
2650
- """Draft sitelink extensions for a campaign — returns preview, does NOT execute.
2680
+ """Draft sitelink extensions for a campaign or the account — returns preview, does NOT execute.
2681
+
2682
+ The scope follows campaign_id; account level has to be explicit
2683
+ (``scope="account"``), it is never inferred from an empty campaign_id.
2651
2684
 
2652
2685
  sitelinks: list of dicts, each with:
2653
2686
  - link_text (str, required, max 25 chars) — the clickable text
@@ -2656,6 +2689,7 @@ def draft_sitelinks(
2656
2689
  - description2 (str, optional, max 35 chars) — second description line
2657
2690
  campaign_id: the campaign to attach sitelinks to
2658
2691
  """
2692
+ from adloop.ads.assets import _account_scope_warning, resolve_scope, scope_entity
2659
2693
  from adloop.safety.guards import SafetyViolation, check_blocked_operation
2660
2694
  from adloop.safety.preview import ChangePlan, store_plan
2661
2695
 
@@ -2664,12 +2698,12 @@ def draft_sitelinks(
2664
2698
  except SafetyViolation as e:
2665
2699
  return {"error": str(e)}
2666
2700
 
2667
- if not campaign_id:
2668
- return {"error": "campaign_id is required"}
2701
+ scope, campaign_id, _, errors = resolve_scope(scope, campaign_id, "", allowed=("campaign", "account"))
2702
+ if errors:
2703
+ return {"error": "Validation failed", "details": errors}
2669
2704
  if not sitelinks:
2670
2705
  return {"error": "At least one sitelink is required"}
2671
2706
 
2672
- errors = []
2673
2707
  warnings = []
2674
2708
  validated = []
2675
2709
 
@@ -2733,12 +2767,16 @@ def draft_sitelinks(
2733
2767
  f"maximum ad real estate."
2734
2768
  )
2735
2769
 
2770
+ if scope == "account":
2771
+ warnings.append(_account_scope_warning("sitelinks"))
2772
+
2773
+ entity_type, entity_id = scope_entity(scope, customer_id, campaign_id, "")
2736
2774
  plan = ChangePlan(
2737
2775
  operation="create_sitelinks",
2738
- entity_type="campaign_asset",
2739
- entity_id=campaign_id,
2776
+ entity_type=entity_type,
2777
+ entity_id=entity_id,
2740
2778
  customer_id=customer_id,
2741
- changes={"campaign_id": campaign_id, "sitelinks": validated},
2779
+ changes={"scope": scope, "campaign_id": campaign_id, "sitelinks": validated},
2742
2780
  )
2743
2781
  store_plan(plan)
2744
2782
  preview = plan.to_preview()
@@ -3514,15 +3552,45 @@ def image_payloads(
3514
3552
  return validated, errors
3515
3553
 
3516
3554
 
3555
+ # Where Google links each image field type ("Asset types linked to customers,
3556
+ # campaigns, and ad groups" in the Google Ads API assets overview).
3557
+ _IMAGE_FIELD_TYPE_SCOPES = {
3558
+ "AD_IMAGE": ("campaign",),
3559
+ "BUSINESS_LOGO": ("campaign", "account"),
3560
+ }
3561
+
3562
+
3563
+ def _assign_image_field_types(
3564
+ images: list[dict[str, object]], scope: str, field_types: list[str] | None
3565
+ ) -> list[str]:
3566
+ """Set each image's ``field_type``; returns what was wrong with the request."""
3567
+ if field_types is None:
3568
+ if scope == "account":
3569
+ return ['scope="account" needs field_types: only BUSINESS_LOGO links at account level']
3570
+ field_types = ["AD_IMAGE"] * len(images)
3571
+ if len(field_types) != len(images):
3572
+ return [f"field_types has {len(field_types)} entries for {len(images)} images; pass one per image"]
3573
+ errors = []
3574
+ for index, (image, raw) in enumerate(zip(images, field_types), start=1):
3575
+ field_type = str(raw).strip().upper()
3576
+ scopes = _IMAGE_FIELD_TYPE_SCOPES.get(field_type)
3577
+ if scopes is None:
3578
+ errors.append(
3579
+ f"Image {index}: field type '{field_type}' is not supported; "
3580
+ f"allowed: {sorted(_IMAGE_FIELD_TYPE_SCOPES)}"
3581
+ )
3582
+ elif scope not in scopes:
3583
+ errors.append(f"Image {index}: {field_type} cannot be linked at {scope} level")
3584
+ image["field_type"] = field_type
3585
+ return errors
3586
+
3587
+
3517
3588
  def _validate_image_assets(
3518
- campaign_id: str,
3519
3589
  image_paths: list[str],
3520
3590
  image_urls: list[str] | None = None,
3521
3591
  upload_ids: list[str] | None = None,
3522
3592
  ) -> tuple[list[dict[str, object]], list[str]]:
3523
3593
  errors = []
3524
- if not campaign_id:
3525
- errors.append("campaign_id is required")
3526
3594
  if not image_paths and not image_urls and not upload_ids:
3527
3595
  errors.append("At least one image (image_paths, image_urls or upload_ids) is required")
3528
3596
  validated, image_errors = image_payloads(image_paths, image_urls, upload_ids)
@@ -5516,56 +5584,6 @@ def _apply_status_change(
5516
5584
  return {"resource_name": response.results[0].resource_name}
5517
5585
 
5518
5586
 
5519
- def _apply_campaign_assets(
5520
- client: object,
5521
- cid: str,
5522
- campaign_id: str,
5523
- assets: list[dict],
5524
- field_type: object,
5525
- populate_asset: object,
5526
- ) -> dict:
5527
- """Create assets and link them to a campaign via CampaignAsset."""
5528
- asset_service = client.get_service("AssetService")
5529
- googleads_service = client.get_service("GoogleAdsService")
5530
- operations = []
5531
-
5532
- for i, payload in enumerate(assets):
5533
- op = client.get_type("MutateOperation")
5534
- asset = op.asset_operation.create
5535
- asset.resource_name = asset_service.asset_path(cid, str(-(i + 1)))
5536
- populate_asset(asset, payload)
5537
- operations.append(op)
5538
-
5539
- for i in range(len(assets)):
5540
- op = client.get_type("MutateOperation")
5541
- ca = op.campaign_asset_operation.create
5542
- ca.asset = asset_service.asset_path(cid, str(-(i + 1)))
5543
- ca.campaign = googleads_service.campaign_path(cid, campaign_id)
5544
- ca.field_type = field_type
5545
- operations.append(op)
5546
-
5547
- response = googleads_service.mutate(
5548
- customer_id=cid, mutate_operations=operations
5549
- )
5550
-
5551
- results = {"assets": [], "campaign_assets": []}
5552
- num_assets = len(assets)
5553
- for i, resp in enumerate(response.mutate_operation_responses):
5554
- resource = None
5555
- if resp.asset_result.resource_name:
5556
- resource = resp.asset_result.resource_name
5557
- elif resp.campaign_asset_result.resource_name:
5558
- resource = resp.campaign_asset_result.resource_name
5559
-
5560
- if resource:
5561
- if i < num_assets:
5562
- results["assets"].append(resource)
5563
- else:
5564
- results["campaign_assets"].append(resource)
5565
-
5566
- return results
5567
-
5568
-
5569
5587
  def load_image_bytes(payload: dict) -> tuple[bytes, PurePath]:
5570
5588
  """The approved bytes of a drafted image (URL, upload or local path) and a name source.
5571
5589
 
@@ -5607,27 +5625,26 @@ def populate_image_asset(client: object, asset: object, payload: dict) -> None:
5607
5625
 
5608
5626
 
5609
5627
  def _apply_create_image_assets(client: object, cid: str, changes: dict) -> dict:
5610
- """Create image assets from local files or URLs and link them to a campaign.
5628
+ """Create image assets from local files or URLs and link them at the plan's scope.
5611
5629
 
5612
5630
  URL images are re-fetched through the same safe fetcher and must match
5613
5631
  the sha256 approved in the preview.
5614
5632
  """
5633
+ from adloop.ads.assets import _create_and_link
5615
5634
 
5616
5635
  def populate(asset: object, payload: dict) -> None:
5617
5636
  populate_image_asset(client, asset, payload)
5618
5637
 
5619
- return _apply_campaign_assets(
5620
- client,
5621
- cid,
5622
- changes["campaign_id"],
5623
- changes["images"],
5624
- client.enums.AssetFieldTypeEnum.AD_IMAGE,
5625
- populate,
5626
- )
5638
+ def field_type(payload: dict) -> object:
5639
+ # Plans drafted before field_types existed link as AD_IMAGE.
5640
+ return getattr(client.enums.AssetFieldTypeEnum, payload.get("field_type") or "AD_IMAGE")
5641
+
5642
+ return _create_and_link(client, cid, changes["images"], field_type, populate, changes)
5627
5643
 
5628
5644
 
5629
5645
  def _apply_create_sitelinks(client: object, cid: str, changes: dict) -> dict:
5630
- """Create sitelink assets and link them to a campaign."""
5646
+ """Create sitelink assets and link them at the plan's scope."""
5647
+ from adloop.ads.assets import _create_and_link
5631
5648
 
5632
5649
  def populate(asset: object, payload: dict) -> None:
5633
5650
  asset.sitelink_asset.link_text = payload["link_text"]
@@ -5637,13 +5654,8 @@ def _apply_create_sitelinks(client: object, cid: str, changes: dict) -> dict:
5637
5654
  if payload.get("description2"):
5638
5655
  asset.sitelink_asset.description2 = payload["description2"]
5639
5656
 
5640
- return _apply_campaign_assets(
5641
- client,
5642
- cid,
5643
- changes["campaign_id"],
5644
- changes["sitelinks"],
5645
- client.enums.AssetFieldTypeEnum.SITELINK,
5646
- populate,
5657
+ return _create_and_link(
5658
+ client, cid, changes["sitelinks"], client.enums.AssetFieldTypeEnum.SITELINK, populate, changes
5647
5659
  )
5648
5660
 
5649
5661
 
@@ -299,8 +299,8 @@ Conversions that happen offline (a sales call, a lead that turned into a deal) g
299
299
  | `draft_promotion` | Create a promotion asset ("20% off winter tyres") for an ad group, a campaign or the account | `promotion_target` (≤20), `final_url`, `language_code` (REQUIRED), `money_off` or `percent_off`; optional `promotion_code` (≤15) or `orders_over_amount`, `occasion`, `discount_modifier` UP_TO, dates, `ad_schedule` (hours it shows); amounts in the account currency unless `currency_code` |
300
300
  | `update_promotion` | Edit a promotion IN PLACE; fields not passed stay | `asset_id` plus the fields to change; `money_off`/`percent_off` and `promotion_code`/`orders_over_amount` replace each other; `ad_schedule` replaces its schedule; `clear_fields` removes optional ones (incl. `ad_schedule`) |
301
301
  | `draft_price_asset` | Create a price asset (3-8 offerings) for an ad group, a campaign or the account | `offerings` [{header ≤25, description ≤25, price, final_url, unit}], `price_type`, `language_code` (both REQUIRED); `price_qualifier` FROM/UP_TO/AVERAGE optional; account currency unless `currency_code` |
302
- | `draft_image_assets` | Create image assets for a campaign from local files, public image URLs or uploads (does NOT publish) | `campaign_id`, `image_paths` (local PNG/JPEG/GIF files; not on a hosted server), `image_urls` (public http(s) image links, ≤5120 KB; re-checked at apply — if the image changed since the preview, draft again) and/or `upload_ids` (`up_...` from `upload_images` / `list_uploads`) |
303
- | `draft_sitelinks` | Create sitelink extensions for a campaign (does NOT publish) | `campaign_id`, `sitelinks` list of {link_text ≤25 chars, final_url, description1 ≤35 chars, description2 ≤35 chars} |
302
+ | `draft_image_assets` | Create image assets for a campaign from local files, public image URLs or uploads (does NOT publish); a business logo can also go on the account | `campaign_id` or `scope="account"`, `field_types` (one per image: AD_IMAGE, the campaign default, or BUSINESS_LOGO; account level takes BUSINESS_LOGO only, one per account: to replace it, remove the current link with `remove_entity` first; the draft names it), `image_paths` (local PNG/JPEG/GIF files; not on a hosted server), `image_urls` (public http(s) image links, ≤5120 KB; re-checked at apply — if the image changed since the preview, draft again) and/or `upload_ids` (`up_...` from `upload_images` / `list_uploads`) |
303
+ | `draft_sitelinks` | Create sitelink extensions for a campaign or the account (does NOT publish) | `campaign_id` or `scope="account"`, `sitelinks` list of {link_text ≤25 chars, final_url, description1 ≤35 chars, description2 ≤35 chars} |
304
304
  | `draft_keywords` | Propose keyword additions (does NOT add) | Each keyword needs `text` and `match_type` (EXACT/PHRASE/BROAD) |
305
305
  | `add_negative_keywords` | Propose negative keywords directly on a campaign (does NOT add) | `campaign_id`, keyword list, `match_type` |
306
306
  | `add_negative_locations` | Propose negative geo exclusions on a campaign (does NOT add) — exclude cities/regions while keeping broader positive targets | `campaign_id`, `geo_target_ids` (numeric geo target constant IDs) |
@@ -5022,13 +5022,15 @@ def update_structured_snippet(
5022
5022
  @_tool(title="Draft image assets", annotations=_WRITE, tags={"ads"})
5023
5023
  @_safe
5024
5024
  def draft_image_assets(
5025
- campaign_id: str,
5025
+ campaign_id: str = "",
5026
5026
  image_paths: _StrList = [], # noqa: B006
5027
5027
  image_urls: _StrList = [], # noqa: B006
5028
5028
  customer_id: str = "",
5029
5029
  upload_ids: _StrList = [], # noqa: B006
5030
+ scope: str = "",
5031
+ field_types: _StrListOpt = None,
5030
5032
  ) -> dict:
5031
- """Draft campaign image assets from local files, public image URLs or uploads — returns a PREVIEW.
5033
+ """Draft image assets from local files, public image URLs or uploads — returns a PREVIEW.
5032
5034
 
5033
5035
  At least one image in total is required across image_paths, image_urls
5034
5036
  and upload_ids.
@@ -5039,7 +5041,8 @@ def draft_image_assets(
5039
5041
  applies it.
5040
5042
 
5041
5043
  Args:
5042
- campaign_id: Numeric ID of the campaign to attach the images to.
5044
+ campaign_id: Numeric ID of the campaign to attach the images to. Leave
5045
+ empty with scope="account".
5043
5046
  image_paths: Local PNG/JPEG/GIF file paths on the machine running
5044
5047
  AdLoop. Not available on a hosted server, where image_urls
5045
5048
  applies instead.
@@ -5050,6 +5053,14 @@ def draft_image_assets(
5050
5053
  upload_ids: Ids of images the user uploaded (up_..., from
5051
5054
  upload_images or list_uploads). The way to use an image that has
5052
5055
  no public URL.
5056
+ scope: Empty follows campaign_id. "account" links the images
5057
+ account-wide, which Google allows for BUSINESS_LOGO only and which
5058
+ is never inferred from an empty campaign_id. An account takes one
5059
+ business logo: while one is linked, the draft is refused and
5060
+ names the link to remove first.
5061
+ field_types: One per image, in the order upload_ids, image_paths,
5062
+ image_urls: AD_IMAGE (campaign links; the default) or BUSINESS_LOGO
5063
+ (campaign or account links). Required with scope="account".
5053
5064
  """
5054
5065
  from adloop.ads.write import draft_image_assets as _impl
5055
5066
 
@@ -5060,6 +5071,8 @@ def draft_image_assets(
5060
5071
  image_paths=image_paths,
5061
5072
  image_urls=image_urls,
5062
5073
  upload_ids=upload_ids,
5074
+ scope=scope,
5075
+ field_types=field_types,
5063
5076
  )
5064
5077
 
5065
5078
 
@@ -5173,11 +5186,12 @@ def remove_entity(
5173
5186
  @_tool(title="Draft sitelinks", annotations=_WRITE, tags={"ads"})
5174
5187
  @_safe
5175
5188
  def draft_sitelinks(
5176
- campaign_id: str,
5177
5189
  sitelinks: _DictList,
5190
+ campaign_id: str = "",
5178
5191
  customer_id: str = "",
5192
+ scope: str = "",
5179
5193
  ) -> dict:
5180
- """Draft sitelink extensions for a campaign — returns a PREVIEW.
5194
+ """Draft sitelink extensions for a campaign or the account — returns a PREVIEW.
5181
5195
 
5182
5196
  Sitelinks appear as additional links below your ad, increasing click area
5183
5197
  and directing users to specific pages. Every final_url is fetched and an
@@ -5187,14 +5201,18 @@ def draft_sitelinks(
5187
5201
  it.
5188
5202
 
5189
5203
  Args:
5190
- campaign_id: Numeric ID of the campaign to attach sitelinks to.
5191
5204
  sitelinks: List of dicts (at least one), each with link_text (str,
5192
5205
  required, max 25 chars) — the clickable text shown; final_url (str,
5193
5206
  required) — destination URL for this sitelink; description1 (str,
5194
5207
  optional, max 35 chars) — first description line; description2
5195
5208
  (str, optional, max 35 chars) — second description line.
5209
+ campaign_id: Numeric ID of the campaign to attach sitelinks to. Leave
5210
+ empty with scope="account".
5196
5211
  customer_id: Google Ads customer ID (digits, dashes optional). Defaults to
5197
5212
  the configured account.
5213
+ scope: Empty follows campaign_id. "account" links the sitelinks
5214
+ account-wide; they serve on every eligible campaign without sitelinks
5215
+ of its own. It is never inferred from an empty campaign_id.
5198
5216
  """
5199
5217
  from adloop.ads.write import draft_sitelinks as _impl
5200
5218
 
@@ -5203,6 +5221,7 @@ def draft_sitelinks(
5203
5221
  customer_id=customer_id or current_config().ads.customer_id,
5204
5222
  campaign_id=campaign_id,
5205
5223
  sitelinks=sitelinks,
5224
+ scope=scope,
5206
5225
  )
5207
5226
 
5208
5227
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes