adloop 0.37.1__tar.gz → 0.38.0__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.
- {adloop-0.37.1 → adloop-0.38.0}/PKG-INFO +2 -2
- {adloop-0.37.1 → adloop-0.38.0}/README.md +1 -1
- {adloop-0.37.1 → adloop-0.38.0}/pyproject.toml +1 -1
- {adloop-0.37.1 → adloop-0.38.0}/pyproject.toml.orig +1 -1
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/assets.py +5 -3
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/write.py +84 -83
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/rules/adloop.md +2 -2
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/server.py +23 -6
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/__init__.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/__main__.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/_mcp_patches.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/__init__.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/ai_max.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/audiences.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/brands.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/campaign_settings.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/client.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/conversion_actions.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/currency.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/custom_conversion_goals.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/enums.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/forecast.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/gaql.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/image_fetch.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/pmax.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/read.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/recommendation_subscriptions.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/recommendations.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/shopping.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/snippet_headers.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ads/validate_only.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/auth.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/cli.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/config.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/crossref.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/diagnostics.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ga4/__init__.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ga4/client.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ga4/reports.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ga4/tracking.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/ga4/write.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/gsc/__init__.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/gsc/client.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/gsc/reports.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/gtm/__init__.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/gtm/client.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/gtm/entities.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/gtm/read.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/gtm/write.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/merchant/__init__.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/merchant/client.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/merchant/read.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/pagespeed.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/reddit/__init__.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/reddit/auth.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/reddit/client.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/reddit/read.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/reddit/schedule.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/reddit/write.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/rules/__init__.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/rules/commands/analyze-performance.md +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/rules/commands/budget-plan.md +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/rules/commands/create-ad.md +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/rules/commands/create-campaign.md +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/rules/commands/diagnose-tracking.md +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/rules/commands/optimize-campaign.md +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/rules_install.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/runtime.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/safety/__init__.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/safety/approval.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/safety/approval_card.html +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/safety/audit.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/safety/guards.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/safety/preview.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/tracking.py +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/upload_card.html +0 -0
- {adloop-0.37.1 → adloop-0.38.0}/src/adloop/uploads.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: adloop
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.38.0
|
|
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 |
|
|
@@ -609,7 +609,8 @@ def _create_and_link(client, cid: str, assets: list[dict], field_type, populate,
|
|
|
609
609
|
"""Create assets and link them at the plan's scope in one Mutate.
|
|
610
610
|
|
|
611
611
|
Plans from before scopes existed have no ``scope`` and link to their
|
|
612
|
-
campaign, as they always did.
|
|
612
|
+
campaign, as they always did. ``field_type`` is one enum value for all
|
|
613
|
+
assets, or a function of the asset's payload.
|
|
613
614
|
"""
|
|
614
615
|
scope = changes.get("scope") or "campaign"
|
|
615
616
|
asset_service = client.get_service("AssetService")
|
|
@@ -621,9 +622,10 @@ def _create_and_link(client, cid: str, assets: list[dict], field_type, populate,
|
|
|
621
622
|
asset.resource_name = asset_service.asset_path(cid, str(-(i + 1)))
|
|
622
623
|
populate(asset, payload)
|
|
623
624
|
operations.append(op)
|
|
624
|
-
for i in
|
|
625
|
+
for i, payload in enumerate(assets):
|
|
625
626
|
operations.append(_link_operation(
|
|
626
|
-
client, cid, asset_service.asset_path(cid, str(-(i + 1))),
|
|
627
|
+
client, cid, asset_service.asset_path(cid, str(-(i + 1))),
|
|
628
|
+
field_type(payload) if callable(field_type) else field_type, scope,
|
|
627
629
|
changes.get("campaign_id", ""), changes.get("ad_group_id", ""),
|
|
628
630
|
))
|
|
629
631
|
response = googleads_service.mutate(customer_id=cid, mutate_operations=operations)
|
|
@@ -2590,14 +2590,22 @@ 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
|
|
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 _account_scope_warning, resolve_scope, scope_entity
|
|
2601
2609
|
from adloop.runtime import deployment_mode
|
|
2602
2610
|
from adloop.safety.guards import SafetyViolation, check_blocked_operation
|
|
2603
2611
|
from adloop.safety.preview import ChangePlan, store_plan
|
|
@@ -2619,25 +2627,35 @@ def draft_image_assets(
|
|
|
2619
2627
|
except SafetyViolation as e:
|
|
2620
2628
|
return {"error": str(e)}
|
|
2621
2629
|
|
|
2622
|
-
|
|
2623
|
-
|
|
2630
|
+
scope, campaign_id, _, errors = resolve_scope(scope, campaign_id, "", allowed=("campaign", "account"))
|
|
2631
|
+
validated_images, image_errors = _validate_image_assets(
|
|
2632
|
+
image_paths, image_urls, list(upload_ids or [])
|
|
2624
2633
|
)
|
|
2634
|
+
errors.extend(image_errors)
|
|
2635
|
+
if not errors:
|
|
2636
|
+
errors.extend(_assign_image_field_types(validated_images, scope, field_types))
|
|
2625
2637
|
if errors:
|
|
2626
2638
|
return {"error": "Validation failed", "details": errors}
|
|
2627
2639
|
|
|
2640
|
+
entity_type, entity_id = scope_entity(scope, customer_id, campaign_id, "")
|
|
2628
2641
|
plan = ChangePlan(
|
|
2629
2642
|
operation="create_image_assets",
|
|
2630
|
-
entity_type=
|
|
2631
|
-
entity_id=
|
|
2643
|
+
entity_type=entity_type,
|
|
2644
|
+
entity_id=entity_id,
|
|
2632
2645
|
customer_id=customer_id,
|
|
2633
2646
|
changes={
|
|
2647
|
+
"scope": scope,
|
|
2634
2648
|
"campaign_id": campaign_id,
|
|
2635
2649
|
"images": validated_images,
|
|
2636
2650
|
"summary": [_describe_image(image) for image in validated_images],
|
|
2651
|
+
"field_types": [image["field_type"] for image in validated_images],
|
|
2637
2652
|
},
|
|
2638
2653
|
)
|
|
2639
2654
|
store_plan(plan)
|
|
2640
|
-
|
|
2655
|
+
preview = plan.to_preview()
|
|
2656
|
+
if scope == "account":
|
|
2657
|
+
preview["warnings"] = [_account_scope_warning("business logos")]
|
|
2658
|
+
return preview
|
|
2641
2659
|
|
|
2642
2660
|
|
|
2643
2661
|
def draft_sitelinks(
|
|
@@ -2646,8 +2664,12 @@ def draft_sitelinks(
|
|
|
2646
2664
|
customer_id: str = "",
|
|
2647
2665
|
campaign_id: str = "",
|
|
2648
2666
|
sitelinks: list[dict] | None = None,
|
|
2667
|
+
scope: str = "",
|
|
2649
2668
|
) -> dict:
|
|
2650
|
-
"""Draft sitelink extensions for a campaign — returns preview, does NOT execute.
|
|
2669
|
+
"""Draft sitelink extensions for a campaign or the account — returns preview, does NOT execute.
|
|
2670
|
+
|
|
2671
|
+
The scope follows campaign_id; account level has to be explicit
|
|
2672
|
+
(``scope="account"``), it is never inferred from an empty campaign_id.
|
|
2651
2673
|
|
|
2652
2674
|
sitelinks: list of dicts, each with:
|
|
2653
2675
|
- link_text (str, required, max 25 chars) — the clickable text
|
|
@@ -2656,6 +2678,7 @@ def draft_sitelinks(
|
|
|
2656
2678
|
- description2 (str, optional, max 35 chars) — second description line
|
|
2657
2679
|
campaign_id: the campaign to attach sitelinks to
|
|
2658
2680
|
"""
|
|
2681
|
+
from adloop.ads.assets import _account_scope_warning, resolve_scope, scope_entity
|
|
2659
2682
|
from adloop.safety.guards import SafetyViolation, check_blocked_operation
|
|
2660
2683
|
from adloop.safety.preview import ChangePlan, store_plan
|
|
2661
2684
|
|
|
@@ -2664,12 +2687,12 @@ def draft_sitelinks(
|
|
|
2664
2687
|
except SafetyViolation as e:
|
|
2665
2688
|
return {"error": str(e)}
|
|
2666
2689
|
|
|
2667
|
-
|
|
2668
|
-
|
|
2690
|
+
scope, campaign_id, _, errors = resolve_scope(scope, campaign_id, "", allowed=("campaign", "account"))
|
|
2691
|
+
if errors:
|
|
2692
|
+
return {"error": "Validation failed", "details": errors}
|
|
2669
2693
|
if not sitelinks:
|
|
2670
2694
|
return {"error": "At least one sitelink is required"}
|
|
2671
2695
|
|
|
2672
|
-
errors = []
|
|
2673
2696
|
warnings = []
|
|
2674
2697
|
validated = []
|
|
2675
2698
|
|
|
@@ -2733,12 +2756,16 @@ def draft_sitelinks(
|
|
|
2733
2756
|
f"maximum ad real estate."
|
|
2734
2757
|
)
|
|
2735
2758
|
|
|
2759
|
+
if scope == "account":
|
|
2760
|
+
warnings.append(_account_scope_warning("sitelinks"))
|
|
2761
|
+
|
|
2762
|
+
entity_type, entity_id = scope_entity(scope, customer_id, campaign_id, "")
|
|
2736
2763
|
plan = ChangePlan(
|
|
2737
2764
|
operation="create_sitelinks",
|
|
2738
|
-
entity_type=
|
|
2739
|
-
entity_id=
|
|
2765
|
+
entity_type=entity_type,
|
|
2766
|
+
entity_id=entity_id,
|
|
2740
2767
|
customer_id=customer_id,
|
|
2741
|
-
changes={"campaign_id": campaign_id, "sitelinks": validated},
|
|
2768
|
+
changes={"scope": scope, "campaign_id": campaign_id, "sitelinks": validated},
|
|
2742
2769
|
)
|
|
2743
2770
|
store_plan(plan)
|
|
2744
2771
|
preview = plan.to_preview()
|
|
@@ -3514,15 +3541,45 @@ def image_payloads(
|
|
|
3514
3541
|
return validated, errors
|
|
3515
3542
|
|
|
3516
3543
|
|
|
3544
|
+
# Where Google links each image field type ("Asset types linked to customers,
|
|
3545
|
+
# campaigns, and ad groups" in the Google Ads API assets overview).
|
|
3546
|
+
_IMAGE_FIELD_TYPE_SCOPES = {
|
|
3547
|
+
"AD_IMAGE": ("campaign",),
|
|
3548
|
+
"BUSINESS_LOGO": ("campaign", "account"),
|
|
3549
|
+
}
|
|
3550
|
+
|
|
3551
|
+
|
|
3552
|
+
def _assign_image_field_types(
|
|
3553
|
+
images: list[dict[str, object]], scope: str, field_types: list[str] | None
|
|
3554
|
+
) -> list[str]:
|
|
3555
|
+
"""Set each image's ``field_type``; returns what was wrong with the request."""
|
|
3556
|
+
if field_types is None:
|
|
3557
|
+
if scope == "account":
|
|
3558
|
+
return ['scope="account" needs field_types: only BUSINESS_LOGO links at account level']
|
|
3559
|
+
field_types = ["AD_IMAGE"] * len(images)
|
|
3560
|
+
if len(field_types) != len(images):
|
|
3561
|
+
return [f"field_types has {len(field_types)} entries for {len(images)} images; pass one per image"]
|
|
3562
|
+
errors = []
|
|
3563
|
+
for index, (image, raw) in enumerate(zip(images, field_types), start=1):
|
|
3564
|
+
field_type = str(raw).strip().upper()
|
|
3565
|
+
scopes = _IMAGE_FIELD_TYPE_SCOPES.get(field_type)
|
|
3566
|
+
if scopes is None:
|
|
3567
|
+
errors.append(
|
|
3568
|
+
f"Image {index}: field type '{field_type}' is not supported; "
|
|
3569
|
+
f"allowed: {sorted(_IMAGE_FIELD_TYPE_SCOPES)}"
|
|
3570
|
+
)
|
|
3571
|
+
elif scope not in scopes:
|
|
3572
|
+
errors.append(f"Image {index}: {field_type} cannot be linked at {scope} level")
|
|
3573
|
+
image["field_type"] = field_type
|
|
3574
|
+
return errors
|
|
3575
|
+
|
|
3576
|
+
|
|
3517
3577
|
def _validate_image_assets(
|
|
3518
|
-
campaign_id: str,
|
|
3519
3578
|
image_paths: list[str],
|
|
3520
3579
|
image_urls: list[str] | None = None,
|
|
3521
3580
|
upload_ids: list[str] | None = None,
|
|
3522
3581
|
) -> tuple[list[dict[str, object]], list[str]]:
|
|
3523
3582
|
errors = []
|
|
3524
|
-
if not campaign_id:
|
|
3525
|
-
errors.append("campaign_id is required")
|
|
3526
3583
|
if not image_paths and not image_urls and not upload_ids:
|
|
3527
3584
|
errors.append("At least one image (image_paths, image_urls or upload_ids) is required")
|
|
3528
3585
|
validated, image_errors = image_payloads(image_paths, image_urls, upload_ids)
|
|
@@ -5516,56 +5573,6 @@ def _apply_status_change(
|
|
|
5516
5573
|
return {"resource_name": response.results[0].resource_name}
|
|
5517
5574
|
|
|
5518
5575
|
|
|
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
5576
|
def load_image_bytes(payload: dict) -> tuple[bytes, PurePath]:
|
|
5570
5577
|
"""The approved bytes of a drafted image (URL, upload or local path) and a name source.
|
|
5571
5578
|
|
|
@@ -5607,27 +5614,26 @@ def populate_image_asset(client: object, asset: object, payload: dict) -> None:
|
|
|
5607
5614
|
|
|
5608
5615
|
|
|
5609
5616
|
def _apply_create_image_assets(client: object, cid: str, changes: dict) -> dict:
|
|
5610
|
-
"""Create image assets from local files or URLs and link them
|
|
5617
|
+
"""Create image assets from local files or URLs and link them at the plan's scope.
|
|
5611
5618
|
|
|
5612
5619
|
URL images are re-fetched through the same safe fetcher and must match
|
|
5613
5620
|
the sha256 approved in the preview.
|
|
5614
5621
|
"""
|
|
5622
|
+
from adloop.ads.assets import _create_and_link
|
|
5615
5623
|
|
|
5616
5624
|
def populate(asset: object, payload: dict) -> None:
|
|
5617
5625
|
populate_image_asset(client, asset, payload)
|
|
5618
5626
|
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
client.enums.AssetFieldTypeEnum.AD_IMAGE,
|
|
5625
|
-
populate,
|
|
5626
|
-
)
|
|
5627
|
+
def field_type(payload: dict) -> object:
|
|
5628
|
+
# Plans drafted before field_types existed link as AD_IMAGE.
|
|
5629
|
+
return getattr(client.enums.AssetFieldTypeEnum, payload.get("field_type") or "AD_IMAGE")
|
|
5630
|
+
|
|
5631
|
+
return _create_and_link(client, cid, changes["images"], field_type, populate, changes)
|
|
5627
5632
|
|
|
5628
5633
|
|
|
5629
5634
|
def _apply_create_sitelinks(client: object, cid: str, changes: dict) -> dict:
|
|
5630
|
-
"""Create sitelink assets and link them
|
|
5635
|
+
"""Create sitelink assets and link them at the plan's scope."""
|
|
5636
|
+
from adloop.ads.assets import _create_and_link
|
|
5631
5637
|
|
|
5632
5638
|
def populate(asset: object, payload: dict) -> None:
|
|
5633
5639
|
asset.sitelink_asset.link_text = payload["link_text"]
|
|
@@ -5637,13 +5643,8 @@ def _apply_create_sitelinks(client: object, cid: str, changes: dict) -> dict:
|
|
|
5637
5643
|
if payload.get("description2"):
|
|
5638
5644
|
asset.sitelink_asset.description2 = payload["description2"]
|
|
5639
5645
|
|
|
5640
|
-
return
|
|
5641
|
-
client,
|
|
5642
|
-
cid,
|
|
5643
|
-
changes["campaign_id"],
|
|
5644
|
-
changes["sitelinks"],
|
|
5645
|
-
client.enums.AssetFieldTypeEnum.SITELINK,
|
|
5646
|
-
populate,
|
|
5646
|
+
return _create_and_link(
|
|
5647
|
+
client, cid, changes["sitelinks"], client.enums.AssetFieldTypeEnum.SITELINK, populate, changes
|
|
5647
5648
|
)
|
|
5648
5649
|
|
|
5649
5650
|
|
|
@@ -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), `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
|
|
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,12 @@ 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.
|
|
5059
|
+
field_types: One per image, in the order upload_ids, image_paths,
|
|
5060
|
+
image_urls: AD_IMAGE (campaign links; the default) or BUSINESS_LOGO
|
|
5061
|
+
(campaign or account links). Required with scope="account".
|
|
5053
5062
|
"""
|
|
5054
5063
|
from adloop.ads.write import draft_image_assets as _impl
|
|
5055
5064
|
|
|
@@ -5060,6 +5069,8 @@ def draft_image_assets(
|
|
|
5060
5069
|
image_paths=image_paths,
|
|
5061
5070
|
image_urls=image_urls,
|
|
5062
5071
|
upload_ids=upload_ids,
|
|
5072
|
+
scope=scope,
|
|
5073
|
+
field_types=field_types,
|
|
5063
5074
|
)
|
|
5064
5075
|
|
|
5065
5076
|
|
|
@@ -5173,11 +5184,12 @@ def remove_entity(
|
|
|
5173
5184
|
@_tool(title="Draft sitelinks", annotations=_WRITE, tags={"ads"})
|
|
5174
5185
|
@_safe
|
|
5175
5186
|
def draft_sitelinks(
|
|
5176
|
-
campaign_id: str,
|
|
5177
5187
|
sitelinks: _DictList,
|
|
5188
|
+
campaign_id: str = "",
|
|
5178
5189
|
customer_id: str = "",
|
|
5190
|
+
scope: str = "",
|
|
5179
5191
|
) -> dict:
|
|
5180
|
-
"""Draft sitelink extensions for a campaign — returns a PREVIEW.
|
|
5192
|
+
"""Draft sitelink extensions for a campaign or the account — returns a PREVIEW.
|
|
5181
5193
|
|
|
5182
5194
|
Sitelinks appear as additional links below your ad, increasing click area
|
|
5183
5195
|
and directing users to specific pages. Every final_url is fetched and an
|
|
@@ -5187,14 +5199,18 @@ def draft_sitelinks(
|
|
|
5187
5199
|
it.
|
|
5188
5200
|
|
|
5189
5201
|
Args:
|
|
5190
|
-
campaign_id: Numeric ID of the campaign to attach sitelinks to.
|
|
5191
5202
|
sitelinks: List of dicts (at least one), each with link_text (str,
|
|
5192
5203
|
required, max 25 chars) — the clickable text shown; final_url (str,
|
|
5193
5204
|
required) — destination URL for this sitelink; description1 (str,
|
|
5194
5205
|
optional, max 35 chars) — first description line; description2
|
|
5195
5206
|
(str, optional, max 35 chars) — second description line.
|
|
5207
|
+
campaign_id: Numeric ID of the campaign to attach sitelinks to. Leave
|
|
5208
|
+
empty with scope="account".
|
|
5196
5209
|
customer_id: Google Ads customer ID (digits, dashes optional). Defaults to
|
|
5197
5210
|
the configured account.
|
|
5211
|
+
scope: Empty follows campaign_id. "account" links the sitelinks
|
|
5212
|
+
account-wide; they serve on every eligible campaign without sitelinks
|
|
5213
|
+
of its own. It is never inferred from an empty campaign_id.
|
|
5198
5214
|
"""
|
|
5199
5215
|
from adloop.ads.write import draft_sitelinks as _impl
|
|
5200
5216
|
|
|
@@ -5203,6 +5219,7 @@ def draft_sitelinks(
|
|
|
5203
5219
|
customer_id=customer_id or current_config().ads.customer_id,
|
|
5204
5220
|
campaign_id=campaign_id,
|
|
5205
5221
|
sitelinks=sitelinks,
|
|
5222
|
+
scope=scope,
|
|
5206
5223
|
)
|
|
5207
5224
|
|
|
5208
5225
|
|
|
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
|
|
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
|
|
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
|
|
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
|
|
File without changes
|