adloop 0.38.1__tar.gz → 0.38.2__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.38.1 → adloop-0.38.2}/PKG-INFO +1 -1
  2. {adloop-0.38.1 → adloop-0.38.2}/pyproject.toml +1 -1
  3. {adloop-0.38.1 → adloop-0.38.2}/pyproject.toml.orig +1 -1
  4. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/assets.py +16 -2
  5. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/pmax.py +4 -3
  6. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/read.py +39 -18
  7. {adloop-0.38.1 → adloop-0.38.2}/README.md +0 -0
  8. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/__init__.py +0 -0
  9. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/__main__.py +0 -0
  10. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/_mcp_patches.py +0 -0
  11. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/__init__.py +0 -0
  12. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/ai_max.py +0 -0
  13. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/audiences.py +0 -0
  14. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/brands.py +0 -0
  15. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/campaign_settings.py +0 -0
  16. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/client.py +0 -0
  17. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/conversion_actions.py +0 -0
  18. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/currency.py +0 -0
  19. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/custom_conversion_goals.py +0 -0
  20. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/enums.py +0 -0
  21. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/forecast.py +0 -0
  22. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/gaql.py +0 -0
  23. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/image_fetch.py +0 -0
  24. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/recommendation_subscriptions.py +0 -0
  25. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/recommendations.py +0 -0
  26. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/shopping.py +0 -0
  27. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/snippet_headers.py +0 -0
  28. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/validate_only.py +0 -0
  29. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ads/write.py +0 -0
  30. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/auth.py +0 -0
  31. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/cli.py +0 -0
  32. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/config.py +0 -0
  33. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/crossref.py +0 -0
  34. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/diagnostics.py +0 -0
  35. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ga4/__init__.py +0 -0
  36. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ga4/client.py +0 -0
  37. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ga4/reports.py +0 -0
  38. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ga4/tracking.py +0 -0
  39. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/ga4/write.py +0 -0
  40. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/gsc/__init__.py +0 -0
  41. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/gsc/client.py +0 -0
  42. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/gsc/reports.py +0 -0
  43. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/gtm/__init__.py +0 -0
  44. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/gtm/client.py +0 -0
  45. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/gtm/entities.py +0 -0
  46. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/gtm/read.py +0 -0
  47. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/gtm/write.py +0 -0
  48. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/merchant/__init__.py +0 -0
  49. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/merchant/client.py +0 -0
  50. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/merchant/read.py +0 -0
  51. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/pagespeed.py +0 -0
  52. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/reddit/__init__.py +0 -0
  53. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/reddit/auth.py +0 -0
  54. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/reddit/client.py +0 -0
  55. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/reddit/read.py +0 -0
  56. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/reddit/schedule.py +0 -0
  57. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/reddit/write.py +0 -0
  58. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/rules/__init__.py +0 -0
  59. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/rules/adloop.md +0 -0
  60. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/rules/commands/analyze-performance.md +0 -0
  61. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/rules/commands/budget-plan.md +0 -0
  62. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/rules/commands/create-ad.md +0 -0
  63. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/rules/commands/create-campaign.md +0 -0
  64. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/rules/commands/diagnose-tracking.md +0 -0
  65. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/rules/commands/optimize-campaign.md +0 -0
  66. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/rules_install.py +0 -0
  67. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/runtime.py +0 -0
  68. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/safety/__init__.py +0 -0
  69. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/safety/approval.py +0 -0
  70. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/safety/approval_card.html +0 -0
  71. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/safety/audit.py +0 -0
  72. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/safety/guards.py +0 -0
  73. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/safety/preview.py +0 -0
  74. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/server.py +0 -0
  75. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/tracking.py +0 -0
  76. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/upload_card.html +0 -0
  77. {adloop-0.38.1 → adloop-0.38.2}/src/adloop/uploads.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: adloop
3
- Version: 0.38.1
3
+ Version: 0.38.2
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "adloop"
3
- version = "0.38.1"
3
+ version = "0.38.2"
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.38.1"
3
+ version = "0.38.2"
4
4
  description = "The AI command center for Google Ads, Reddit Ads, GA4, and tracking code."
5
5
  readme = "README.md"
6
6
  authors = [
@@ -1671,22 +1671,36 @@ def _apply_update_promotion(client, cid: str, changes: dict) -> dict:
1671
1671
  if "final_url" in changed:
1672
1672
  asset.final_urls.append(promo["final_url"])
1673
1673
  paths.append("final_urls")
1674
+ # Google refuses a mask that names a message field it is given a value
1675
+ # for (FIELD_HAS_SUBFIELDS): a Money that is set is masked by its
1676
+ # leaves. An unset field may still be masked whole, which clears it,
1677
+ # and the replaced member of a oneof (discount, trigger) has to be
1678
+ # cleared that way: Google does not drop it on its own
1679
+ # (PROMOTION_CANNOT_SET_PERCENT_OFF_AND_MONEY_AMOUNT_OFF).
1674
1680
  if changed.keys() & {"money_off", "percent_off", "currency_code"}:
1675
1681
  if promo["percent_off"]:
1676
1682
  p.percent_off = round(float(promo["percent_off"]) * 10_000)
1677
1683
  paths.append("promotion_asset.percent_off")
1684
+ if before.get("money_off"):
1685
+ paths.append("promotion_asset.money_amount_off")
1678
1686
  else:
1679
1687
  p.money_amount_off.amount_micros = _micros(promo["money_off"])
1680
1688
  p.money_amount_off.currency_code = promo["currency_code"]
1681
- paths.append("promotion_asset.money_amount_off")
1689
+ paths += [f"promotion_asset.money_amount_off.{f}" for f in ("amount_micros", "currency_code")]
1690
+ if before.get("percent_off"):
1691
+ paths.append("promotion_asset.percent_off")
1682
1692
  if changed.keys() & {"promotion_code", "orders_over_amount", "currency_code"}:
1683
1693
  if promo["promotion_code"]:
1684
1694
  p.promotion_code = promo["promotion_code"]
1685
1695
  paths.append("promotion_asset.promotion_code")
1696
+ if before.get("orders_over_amount"):
1697
+ paths.append("promotion_asset.orders_over_amount")
1686
1698
  elif promo["orders_over_amount"]:
1687
1699
  p.orders_over_amount.amount_micros = _micros(promo["orders_over_amount"])
1688
1700
  p.orders_over_amount.currency_code = promo["currency_code"]
1689
- paths.append("promotion_asset.orders_over_amount")
1701
+ paths += [f"promotion_asset.orders_over_amount.{f}" for f in ("amount_micros", "currency_code")]
1702
+ if before.get("promotion_code"):
1703
+ paths.append("promotion_asset.promotion_code")
1690
1704
  else: # cleared: the masked, unset field is removed
1691
1705
  paths += [f"promotion_asset.{f}" for f in ("promotion_code", "orders_over_amount") if before.get(f)]
1692
1706
  for field, enum in (("occasion", "PromotionExtensionOccasionEnum"),
@@ -17,7 +17,7 @@ from __future__ import annotations
17
17
  from typing import TYPE_CHECKING, Any
18
18
 
19
19
  from adloop.ads.currency import get_currency_code
20
- from adloop.ads.read import _date_clause, _enrich_cost_fields
20
+ from adloop.ads.read import _date_clause, _drop_idle_removed, _enrich_cost_fields
21
21
 
22
22
  if TYPE_CHECKING:
23
23
  from adloop.config import AdLoopConfig
@@ -750,12 +750,13 @@ def get_pmax_performance(
750
750
  segments.ad_network_type
751
751
  FROM campaign
752
752
  WHERE campaign.advertising_channel_type = 'PERFORMANCE_MAX'
753
- AND campaign.status != 'REMOVED'
754
753
  {date_clause}
755
754
  ORDER BY metrics.cost_micros DESC
756
755
  """
757
756
 
758
- campaigns = execute_query(config, customer_id, campaign_query)
757
+ campaigns = _drop_idle_removed(
758
+ execute_query(config, customer_id, campaign_query), "campaign.status"
759
+ )
759
760
  currency_code = get_currency_code(config, customer_id)
760
761
  _enrich_cost_fields(campaigns, currency_code)
761
762
 
@@ -71,6 +71,7 @@ def get_campaign_performance(
71
71
  from adloop.ads.gaql import execute_query
72
72
 
73
73
  date_clause = _date_clause(date_range_start, date_range_end)
74
+ where = date_clause.removeprefix("AND ")
74
75
 
75
76
  query = f"""
76
77
  SELECT campaign.id, campaign.name, campaign.status,
@@ -79,12 +80,13 @@ def get_campaign_performance(
79
80
  metrics.conversions, metrics.conversions_value,
80
81
  metrics.ctr, metrics.average_cpc
81
82
  FROM campaign
82
- WHERE campaign.status != 'REMOVED'
83
- {date_clause}
83
+ WHERE {where}
84
84
  ORDER BY metrics.cost_micros DESC
85
85
  """
86
86
 
87
- rows = execute_query(config, customer_id, query)
87
+ rows = _drop_idle_removed(
88
+ execute_query(config, customer_id, query), "campaign.status"
89
+ )
88
90
  currency_code = get_currency_code(config, customer_id)
89
91
  _enrich_cost_fields(rows, currency_code)
90
92
  share_error = _attach_impression_share(config, customer_id, rows, date_clause)
@@ -199,8 +201,7 @@ def _attach_impression_share(
199
201
  SELECT campaign.id, metrics.impressions,
200
202
  {", ".join(_IMPRESSION_SHARE_FIELDS)}
201
203
  FROM campaign
202
- WHERE campaign.status != 'REMOVED'
203
- AND campaign.advertising_channel_type IN ({channels})
204
+ WHERE campaign.advertising_channel_type IN ({channels})
204
205
  {date_clause}
205
206
  """
206
207
 
@@ -273,7 +274,7 @@ def get_ad_performance(
273
274
  """Get ad-level performance data including headlines, descriptions, and metrics."""
274
275
  from adloop.ads.gaql import execute_query
275
276
 
276
- date_clause = _date_clause(date_range_start, date_range_end)
277
+ where = _date_clause(date_range_start, date_range_end).removeprefix("AND ")
277
278
 
278
279
  query = f"""
279
280
  SELECT campaign.name, campaign.id, ad_group.name, ad_group.id,
@@ -288,12 +289,13 @@ def get_ad_performance(
288
289
  metrics.impressions, metrics.clicks, metrics.ctr,
289
290
  metrics.conversions, metrics.cost_micros
290
291
  FROM ad_group_ad
291
- WHERE ad_group_ad.status != 'REMOVED'
292
- {date_clause}
292
+ WHERE {where}
293
293
  ORDER BY metrics.cost_micros DESC
294
294
  """
295
295
 
296
- rows = execute_query(config, customer_id, query)
296
+ rows = _drop_idle_removed(
297
+ execute_query(config, customer_id, query), "ad_group_ad.status"
298
+ )
297
299
  currency_code = get_currency_code(config, customer_id)
298
300
  _enrich_cost_fields(rows, currency_code)
299
301
  for r in rows:
@@ -467,10 +469,11 @@ def get_keyword_performance(
467
469
  """Get keyword metrics including quality scores and competitive data."""
468
470
  from adloop.ads.gaql import execute_query
469
471
 
470
- date_clause = _date_clause(date_range_start, date_range_end)
472
+ where = _date_clause(date_range_start, date_range_end).removeprefix("AND ")
471
473
 
472
474
  query = f"""
473
475
  SELECT campaign.name, ad_group.name,
476
+ ad_group_criterion.status,
474
477
  ad_group_criterion.keyword.text,
475
478
  ad_group_criterion.keyword.match_type,
476
479
  ad_group_criterion.quality_info.quality_score,
@@ -478,12 +481,13 @@ def get_keyword_performance(
478
481
  metrics.average_cpc, metrics.cost_micros,
479
482
  metrics.conversions
480
483
  FROM keyword_view
481
- WHERE ad_group_criterion.status != 'REMOVED'
482
- {date_clause}
484
+ WHERE {where}
483
485
  ORDER BY metrics.cost_micros DESC
484
486
  """
485
487
 
486
- rows = execute_query(config, customer_id, query)
488
+ rows = _drop_idle_removed(
489
+ execute_query(config, customer_id, query), "ad_group_criterion.status"
490
+ )
487
491
  currency_code = get_currency_code(config, customer_id)
488
492
  _enrich_cost_fields(rows, currency_code)
489
493
 
@@ -940,14 +944,14 @@ def get_audience_performance(
940
944
  """Get audience segment performance metrics (remarketing, in-market, affinity, demographics)."""
941
945
  from adloop.ads.gaql import execute_query
942
946
 
943
- date_clause = _date_clause(date_range_start, date_range_end)
947
+ where = _date_clause(date_range_start, date_range_end).removeprefix("AND ")
944
948
 
945
949
  campaign_filter = ""
946
950
  if campaign_id:
947
951
  campaign_filter = f"AND campaign.id = {campaign_id}"
948
952
 
949
953
  query = f"""
950
- SELECT campaign.id, campaign.name,
954
+ SELECT campaign.id, campaign.name, campaign.status,
951
955
  campaign.advertising_channel_type,
952
956
  ad_group.id, ad_group.name,
953
957
  ad_group_criterion.display_name,
@@ -955,14 +959,15 @@ def get_audience_performance(
955
959
  metrics.impressions, metrics.clicks, metrics.cost_micros,
956
960
  metrics.conversions, metrics.ctr, metrics.average_cpc
957
961
  FROM ad_group_audience_view
958
- WHERE campaign.status != 'REMOVED'
959
- {date_clause}
962
+ WHERE {where}
960
963
  {campaign_filter}
961
964
  ORDER BY metrics.cost_micros DESC
962
965
  LIMIT 200
963
966
  """
964
967
 
965
- rows = execute_query(config, customer_id, query)
968
+ rows = _drop_idle_removed(
969
+ execute_query(config, customer_id, query), "campaign.status"
970
+ )
966
971
  currency_code = get_currency_code(config, customer_id)
967
972
  _enrich_cost_fields(rows, currency_code)
968
973
 
@@ -1360,6 +1365,22 @@ def _improvement(base: float, potential: float) -> float | None:
1360
1365
  return round(potential - base, 4)
1361
1366
 
1362
1367
 
1368
+ def _drop_idle_removed(rows: list[dict], status_field: str) -> list[dict]:
1369
+ """Drop REMOVED rows that had no impressions in the period.
1370
+
1371
+ Date-ranged reports cannot filter on status in GAQL: status is today's,
1372
+ metrics are the period's, so a status predicate hides spend from anything
1373
+ removed since. GAQL has no OR, and ``metrics.impressions > 0`` alone would
1374
+ also hide enabled entities with no impressions, which people look for.
1375
+ Rows without a status field are kept.
1376
+ """
1377
+ return [
1378
+ r for r in rows
1379
+ if str(r.get(status_field)) != "REMOVED"
1380
+ or (r.get("metrics.impressions") or 0) > 0
1381
+ ]
1382
+
1383
+
1363
1384
  def _date_clause(start: str, end: str) -> str:
1364
1385
  """Build a GAQL date WHERE fragment."""
1365
1386
  if start and end:
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