tubesentry 0.1.2__tar.gz → 0.2.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.
Files changed (65) hide show
  1. {tubesentry-0.1.2 → tubesentry-0.2.0}/PKG-INFO +10 -2
  2. {tubesentry-0.1.2 → tubesentry-0.2.0}/README.md +9 -1
  3. {tubesentry-0.1.2 → tubesentry-0.2.0}/docs/guide/cli.md +25 -4
  4. {tubesentry-0.1.2 → tubesentry-0.2.0}/docs/guide/google-ads-scripts.md +23 -0
  5. tubesentry-0.2.0/docs/guide/pro.md +42 -0
  6. {tubesentry-0.1.2 → tubesentry-0.2.0}/pyproject.toml +1 -1
  7. tubesentry-0.2.0/tests/test_delivery_quality_suite.py +102 -0
  8. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/__init__.py +16 -2
  9. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/cli.py +59 -1
  10. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/contracts/schemas.py +29 -0
  11. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/contracts/taxonomy.py +2 -0
  12. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/core/auditor.py +114 -0
  13. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/core/heuristics.py +35 -0
  14. tubesentry-0.2.0/tubesentry/integrations/__init__.py +15 -0
  15. tubesentry-0.2.0/tubesentry/integrations/adh.py +123 -0
  16. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/integrations/google_ads_script.py +135 -0
  17. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/io/ingestor.py +46 -16
  18. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/pro/bridge.py +4 -0
  19. tubesentry-0.1.2/docs/guide/pro.md +0 -38
  20. tubesentry-0.1.2/tubesentry/integrations/__init__.py +0 -9
  21. {tubesentry-0.1.2 → tubesentry-0.2.0}/.agents/skills/youtube-placement-audit/SKILL.md +0 -0
  22. {tubesentry-0.1.2 → tubesentry-0.2.0}/.github/workflows/ci_tests.yml +0 -0
  23. {tubesentry-0.1.2 → tubesentry-0.2.0}/.github/workflows/deploy_docs.yml +0 -0
  24. {tubesentry-0.1.2 → tubesentry-0.2.0}/.github/workflows/publish_pypi.yml +0 -0
  25. {tubesentry-0.1.2 → tubesentry-0.2.0}/.gitignore +0 -0
  26. {tubesentry-0.1.2 → tubesentry-0.2.0}/LICENSE +0 -0
  27. {tubesentry-0.1.2 → tubesentry-0.2.0}/docs/.vitepress/config.mjs +0 -0
  28. {tubesentry-0.1.2 → tubesentry-0.2.0}/docs/audit.md +0 -0
  29. {tubesentry-0.1.2 → tubesentry-0.2.0}/docs/guide/agent-skill.md +0 -0
  30. {tubesentry-0.1.2 → tubesentry-0.2.0}/docs/guide/bigquery.md +0 -0
  31. {tubesentry-0.1.2 → tubesentry-0.2.0}/docs/guide/creative-profiler.md +0 -0
  32. {tubesentry-0.1.2 → tubesentry-0.2.0}/docs/guide/mcp-server.md +0 -0
  33. {tubesentry-0.1.2 → tubesentry-0.2.0}/docs/guide/python-sdk.md +0 -0
  34. {tubesentry-0.1.2 → tubesentry-0.2.0}/docs/guide/quickstart.md +0 -0
  35. {tubesentry-0.1.2 → tubesentry-0.2.0}/docs/guide/waste-categories.md +0 -0
  36. {tubesentry-0.1.2 → tubesentry-0.2.0}/docs/index.md +0 -0
  37. {tubesentry-0.1.2 → tubesentry-0.2.0}/docs/public/llms-full.txt +0 -0
  38. {tubesentry-0.1.2 → tubesentry-0.2.0}/docs/public/llms.txt +0 -0
  39. {tubesentry-0.1.2 → tubesentry-0.2.0}/package-lock.json +0 -0
  40. {tubesentry-0.1.2 → tubesentry-0.2.0}/package.json +0 -0
  41. {tubesentry-0.1.2 → tubesentry-0.2.0}/skills/youtube-placement-audit/SKILL.md +0 -0
  42. {tubesentry-0.1.2 → tubesentry-0.2.0}/tests/test_cli.py +0 -0
  43. {tubesentry-0.1.2 → tubesentry-0.2.0}/tests/test_core_coverage_boost.py +0 -0
  44. {tubesentry-0.1.2 → tubesentry-0.2.0}/tests/test_epro_adapted_features.py +0 -0
  45. {tubesentry-0.1.2 → tubesentry-0.2.0}/tests/test_fixtures.py +0 -0
  46. {tubesentry-0.1.2 → tubesentry-0.2.0}/tests/test_free_auditor.py +0 -0
  47. {tubesentry-0.1.2 → tubesentry-0.2.0}/tests/test_id_extractor.py +0 -0
  48. {tubesentry-0.1.2 → tubesentry-0.2.0}/tests/test_ingestor_multilang.py +0 -0
  49. {tubesentry-0.1.2 → tubesentry-0.2.0}/tests/test_integrations.py +0 -0
  50. {tubesentry-0.1.2 → tubesentry-0.2.0}/tests/test_mcp_server.py +0 -0
  51. {tubesentry-0.1.2 → tubesentry-0.2.0}/tests/test_skills.py +0 -0
  52. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/contracts/__init__.py +0 -0
  53. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/contracts/exceptions.py +0 -0
  54. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/core/__init__.py +0 -0
  55. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/core/seed_db.py +0 -0
  56. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/integrations/bigquery.py +0 -0
  57. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/io/__init__.py +0 -0
  58. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/io/fixtures.py +0 -0
  59. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/mcp_server.py +0 -0
  60. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/pro/__init__.py +0 -0
  61. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/pro/installer.py +0 -0
  62. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/py.typed +0 -0
  63. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/skills/__init__.py +0 -0
  64. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/skills/youtube_placement_audit/SKILL.md +0 -0
  65. {tubesentry-0.1.2 → tubesentry-0.2.0}/tubesentry/skills/youtube_placement_audit/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: tubesentry
3
- Version: 0.1.2
3
+ Version: 0.2.0
4
4
  Summary: Local-First YouTube & Performance Max Placement Waste Auditor & MCP Server
5
5
  Project-URL: Homepage, https://flovv.github.io/tubesentry
6
6
  Project-URL: Documentation, https://flovv.github.io/tubesentry/guide/quickstart
@@ -71,7 +71,15 @@ When running YouTube or Performance Max campaigns, broad placement algorithms fr
71
71
  * **Foreign Script Delivery:** Placements running on non-target language scripts (Cyrillic, Devanagari, Arabic, Thai) within domestic campaigns.
72
72
  * **Low-Quality Content Farms:** Automated short-form compilations designed for view arbitrage with high bounce rates.
73
73
  * **Performance Sinkholes:** Placements that exceed 3x target CPA without registering conversions.
74
- * **Creative Alignment Gap:** Optional analysis comparing your creative's intended target audience with the actual channels where impressions ran.
74
+ * **GVP & Mobile App Leakage:** Third-party Google Video Partners (GVP) websites and `mobileapp::` placements outside YouTube Owned & Operated inventory where muted out-stream slots drain budgets.
75
+ * **Creative Alignment & Sampled Video Verification:** Compares your ad creative's target audience against Top-N enriched channels and sampled video titles/descriptions to separate **On-Target ICP**, **Off-Topic / Generic**, and **Outright Waste**.
76
+ * **Quality-Adjusted CPM (`qCPM`) & Vendor Break-Even Math:** Reveals your true cost per qualified impression (`Nominal CPM / Qualified Delivery Rate`) and calculates the exact maximum fee premium a curated inclusion vendor can charge before losing money.
77
+ * **Attribution Inflation & 2026 Breakpoints:** Flags reports where ≥70% of conversions come from View-Through / Engaged-View attribution and annotates Google's 2026 reporting breakpoints (June 2 Total Co-view Reach, August Multi-Format Reach auto-upgrades, August 24 Public View Count overhaul).
78
+
79
+ ### Enterprise & Hygiene Exporters
80
+ * **Demand Gen (Dec 1, 2026) Hygiene Script (`tubesentry export demand-gen-audit`):** Audits accounts ahead of Google's removal of campaign-level Display opt-outs (`target_content_network = false`), flags auto-generated/enhanced PMax videos, and checks Mobile App/GVP spend.
81
+ * **Ads Data Hub (ADH) 3-Table SQL (`tubesentry export adh`):** Generates the exact `UNION ALL` query across `adh.google_ads_impressions`, `adh.google_ads_active_views`, and `adh.google_ads_creative_conversions` for GroupM viewability, Audible & Fully Visible Watchtime, and custom AVOC.
82
+ * **Positive Inclusion Whitelists (`--out-inclusions`) & Smart Chunking (`--exclusion-mode standalone|mcc`):** Export verified On-Target channels as a positive whitelist (avoiding 10%–15% curation taxes) and auto-split reactive exclusions into 20,000-row pasteable Google Ads UI chunks (or 250k MCC shared lists).
75
83
 
76
84
  ---
77
85
 
@@ -33,7 +33,15 @@ When running YouTube or Performance Max campaigns, broad placement algorithms fr
33
33
  * **Foreign Script Delivery:** Placements running on non-target language scripts (Cyrillic, Devanagari, Arabic, Thai) within domestic campaigns.
34
34
  * **Low-Quality Content Farms:** Automated short-form compilations designed for view arbitrage with high bounce rates.
35
35
  * **Performance Sinkholes:** Placements that exceed 3x target CPA without registering conversions.
36
- * **Creative Alignment Gap:** Optional analysis comparing your creative's intended target audience with the actual channels where impressions ran.
36
+ * **GVP & Mobile App Leakage:** Third-party Google Video Partners (GVP) websites and `mobileapp::` placements outside YouTube Owned & Operated inventory where muted out-stream slots drain budgets.
37
+ * **Creative Alignment & Sampled Video Verification:** Compares your ad creative's target audience against Top-N enriched channels and sampled video titles/descriptions to separate **On-Target ICP**, **Off-Topic / Generic**, and **Outright Waste**.
38
+ * **Quality-Adjusted CPM (`qCPM`) & Vendor Break-Even Math:** Reveals your true cost per qualified impression (`Nominal CPM / Qualified Delivery Rate`) and calculates the exact maximum fee premium a curated inclusion vendor can charge before losing money.
39
+ * **Attribution Inflation & 2026 Breakpoints:** Flags reports where ≥70% of conversions come from View-Through / Engaged-View attribution and annotates Google's 2026 reporting breakpoints (June 2 Total Co-view Reach, August Multi-Format Reach auto-upgrades, August 24 Public View Count overhaul).
40
+
41
+ ### Enterprise & Hygiene Exporters
42
+ * **Demand Gen (Dec 1, 2026) Hygiene Script (`tubesentry export demand-gen-audit`):** Audits accounts ahead of Google's removal of campaign-level Display opt-outs (`target_content_network = false`), flags auto-generated/enhanced PMax videos, and checks Mobile App/GVP spend.
43
+ * **Ads Data Hub (ADH) 3-Table SQL (`tubesentry export adh`):** Generates the exact `UNION ALL` query across `adh.google_ads_impressions`, `adh.google_ads_active_views`, and `adh.google_ads_creative_conversions` for GroupM viewability, Audible & Fully Visible Watchtime, and custom AVOC.
44
+ * **Positive Inclusion Whitelists (`--out-inclusions`) & Smart Chunking (`--exclusion-mode standalone|mcc`):** Export verified On-Target channels as a positive whitelist (avoiding 10%–15% curation taxes) and auto-split reactive exclusions into 20,000-row pasteable Google Ads UI chunks (or 250k MCC shared lists).
37
45
 
38
46
  ---
39
47
 
@@ -34,13 +34,34 @@ tubesentry audit <report_csv> [OPTIONS]
34
34
  | `--cpa` | `None` | Target CPA to flag performance sinkholes |
35
35
  | `--key`, `-k` | `None` | TubeSentry Pro license key (or set `TUBESENTRY_API_KEY`) |
36
36
  | `--out-exclusions` | `None` | Path to export reactive Google Ads Editor exclusions CSV (Pro) |
37
- | `--out-65k` | `None` | Path to export full 65,000-channel shield CSV (Pro) |
37
+ | `--out-65k` | `None` | Path to export full 65,000-channel (or 250k MCC) shield CSV (Pro) |
38
+ | `--out-inclusions` | `None` | Path to export verified On-Target positive inclusion whitelist CSV (Pro) |
39
+ | `--exclusion-mode` | `standalone` | `standalone` (20k pasteable chunks, 65k cap) or `mcc` (250k shared cap) |
38
40
  | `--html` | `None` | Path to export interactive white-label HTML audit deck (Pro) |
39
- | `--ad-url` | `None` | YouTube ad video URL to profile targeting fit |
41
+ | `--ad-url` | `None` | YouTube ad video URL to profile targeting fit & score sampled videos |
40
42
  | `--ad-text` | `None` | Ad creative brief or copy to profile ICP intent |
41
43
 
42
44
  ---
43
45
 
46
+ ### `tubesentry export`
47
+ Exports ready-to-run automation scripts and warehouse SQL templates:
48
+
49
+ ```bash
50
+ # Export copy-paste Google Ads placement exclusion script
51
+ tubesentry export script --report where_ads_showed.csv --out cleanup.js
52
+
53
+ # Export Dec 1, 2026 Demand Gen Display opt-out & Video Enhancements audit script
54
+ tubesentry export demand-gen-audit --out demand_gen_dec2026_audit.js
55
+
56
+ # Export Ads Data Hub (ADH) 3-table UNION ALL SQL for GroupM viewability, AVOC & audible watchtime
57
+ tubesentry export adh --out tubesentry_adh_quality.sql --days 30
58
+
59
+ # Export BigQuery Data Transfer Service (DTS) SQL model
60
+ tubesentry export bigquery --dataset google_ads_export --out tubesentry_bq.sql
61
+ ```
62
+
63
+ ---
64
+
44
65
  ### `tubesentry mcp`
45
66
  Launches the FastMCP stdio server.
46
67
 
@@ -51,8 +72,8 @@ tubesentry mcp
51
72
  ---
52
73
 
53
74
  ### `tubesentry auth`
54
- Activates TubeSentry Pro using a Polar.sh license key.
75
+ Activates TubeSentry Pro using a Polar.sh license key and downloaded platform wheel.
55
76
 
56
77
  ```bash
57
- tubesentry auth --key TS_PRO_YOUR_KEY
78
+ tubesentry auth --key tube_-XXXX-XXXX-XXXX --wheel path/to/tubesentry_pro-*.whl
58
79
  ```
@@ -76,3 +76,26 @@ function main() {
76
76
 
77
77
  * **`SHARED_LIST` Mode (Recommended):** Creates or appends to an account-level **Excluded Placement List** in the Shared Library. Applying this list to all campaigns blocks flagged channels across Video, Performance Max, and Demand Gen without hitting individual campaign limits.
78
78
  * **`CAMPAIGNS` Mode:** Targets specific campaigns matching `--campaign-name-contains`.
79
+
80
+
81
+ ---
82
+
83
+ ## 5. Demand Gen (Dec 1, 2026) & Creative Governance Audit Script
84
+
85
+ Starting the week of **December 1, 2026**, Google removes campaign-level Display opt-outs (`target_content_network = false`) in Demand Gen — causing legacy scripts and bulk uploads to fail with `OPERATION_NOT_PERMITTED_FOR_CONTEXT` unless Display opt-outs are enforced at the ad-group level (`ALL_OWNED_AND_OPERATED_CHANNELS`).
86
+
87
+ Generate a ready-to-paste audit script to inspect your account for breaking Demand Gen configs, default-on auto-generated/enhanced PMax videos (`GENERATE_ENHANCED_YOUTUBE_VIDEOS`), and Mobile App / GVP spend leakage:
88
+
89
+ ```bash
90
+ tubesentry export demand-gen-audit --out demand_gen_dec2026_audit.js
91
+ ```
92
+
93
+ ---
94
+
95
+ ## 6. Enterprise Ads Data Hub (ADH) 3-Table SQL
96
+
97
+ For enterprise teams auditing delivery inside Google's **Ads Data Hub** clean room, TubeSentry generates the exact 3-table `UNION ALL` query (`adh.google_ads_impressions`, `adh.google_ads_active_views`, and `adh.google_ads_creative_conversions` joined on `impression_id`) to measure **GroupM Viewability**, **Audible & Fully Visible Watchtime**, and custom **AVOC** from Q4 quartile telemetry:
98
+
99
+ ```bash
100
+ tubesentry export adh --out tubesentry_adh_quality.sql --days 30
101
+ ```
@@ -0,0 +1,42 @@
1
+ # TubeSentry Pro Commercial Edition
2
+
3
+ **TubeSentry Pro** provides deep intelligence for performance marketing agencies, CMOs, and enterprise brand safety teams.
4
+
5
+ ---
6
+
7
+ ## Pro Features Overview
8
+
9
+ ### 1. Top-N Spend Enrichment & Sampled Video Content Verification
10
+ In typical Google Ads placement reports, the top 300–500 channels account for 70%–85% of total spend. Pro prioritizes the **Top 500 spend channels** via 50-ID YouTube Data API v3 batch calls (only ~10 API calls) with a persistent SQLite cache, and samples recent videos via each channel's `UU...` uploads playlist (1 quota unit/channel) to score actual video titles and descriptions against your target audience.
11
+ * **Why it matters:** Moves beyond binary blocklists to verify whether Google's algorithm actually reached your ICP (**On-Target** vs. **Off-Topic / Generic** vs. **Outright Waste**).
12
+
13
+ ### 2. Quality-Adjusted CPM (`qCPM`) & Curated Vendor Break-Even Math
14
+ Computes **Nominal CPM**, **Effective `qCPM`**, **On-Target `qCPM`**, and your exact **Curated Vendor Break-Even Ceiling** (the maximum all-in CPM + curation fee premium before a third-party inclusion vendor loses money on pure waste reduction), alongside **VTC/EVC Attribution Inflation** and **2026 Platform Breakpoint** checks.
15
+ * **Why it matters:** Gives CMOs objective unit-economics math to decide between reactive exclusions vs. paying 10%–15% curation vendor taxes.
16
+
17
+ ### 3. Positive On-Target Inclusion Whitelists & Smart Exclusion Modes (`standalone` vs. `mcc`)
18
+ * **Positive Whitelists (`--out-inclusions`):** Exports verified `ON_TARGET` channels into a clean Google Ads Editor inclusion CSV for high-precision campaigns without vendor media taxes.
19
+ * **Standalone Mode (`--exclusion-mode standalone`):** Exports reactive-only exclusions split into **20,000-row pasteable chunks** (matching Google Ads' paste cap and protecting standalone 65,000-exclusion limits).
20
+ * **MCC Mode (`--exclusion-mode mcc`):** Supports unified shared MCC exclusion lists up to Google's **250,000-placement** limit.
21
+
22
+ ### 4. Interactive CFO / Client HTML Pitch Deck
23
+ Compiles a standalone, single-file interactive presentation deck containing:
24
+ * Executive KPI cards (Quality index, COPPA toddler exposure, 12-month run-rate recovery).
25
+ * Quality-Adjusted CPM (`qCPM`) & Curated Vendor Break-Even Economics card.
26
+ * 3-Bucket Targeting Quality bar (On-Target ICP / Off-Topic Generic / Outright Waste) + Sampled Video Content Verification table.
27
+ * Chart.js visualizations and "Wall of Shame" visual thumbnail spotlights.
28
+
29
+ ---
30
+
31
+ ## Licensing & Activation
32
+
33
+ Obtain an instant license key directly via [Polar Checkout](https://buy.polar.sh/polar_cl_lRuifr3uJS0LR0k6frhg3JEKBRZNQq75hv7cS2am9cX):
34
+ * **TubeSentry Pro (Monthly):** $199/mo (unlimited unmasked audits, 50-ID batch YouTube API v3 enrichment, Google Ads Editor exclusion exports, and interactive HTML pitch decks).
35
+
36
+ [![Buy TubeSentry Pro on Polar](https://img.shields.io/badge/Polar.sh-Buy%20TubeSentry%20Pro-0062FF?style=for-the-badge&logo=polar&logoColor=white)](https://buy.polar.sh/polar_cl_lRuifr3uJS0LR0k6frhg3JEKBRZNQq75hv7cS2am9cX)
37
+
38
+ ```bash
39
+ # Download your platform wheel (.whl) from the Polar Customer Portal:
40
+ # https://polar.sh/spotlift/portal
41
+ tubesentry auth --key tube_-XXXX-XXXX-XXXX --wheel path/to/tubesentry_pro-*.whl
42
+ ```
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "tubesentry"
7
- version = "0.1.2"
7
+ version = "0.2.0"
8
8
  description = "Local-First YouTube & Performance Max Placement Waste Auditor & MCP Server"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -0,0 +1,102 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+
5
+ from typer.testing import CliRunner
6
+
7
+ import tubesentry
8
+ from tubesentry.cli import app
9
+ from tubesentry.core.auditor import (
10
+ analyze_attribution_and_breakpoints,
11
+ compute_quality_economics,
12
+ )
13
+ from tubesentry.core.heuristics import is_gvp_or_mobile_app
14
+ from tubesentry.integrations import (
15
+ generate_adh_quality_sql,
16
+ generate_demand_gen_hygiene_script,
17
+ )
18
+
19
+ runner = CliRunner()
20
+
21
+
22
+ def test_qcpm_and_vendor_breakeven_math() -> None:
23
+ # 30% waste on $9.29 nominal CPM ($929 spend / 100k impressions) -> $13.27 qCPM, ~1.36x (+35.7%) break-even
24
+ econ = compute_quality_economics(
25
+ total_spend=929.0,
26
+ total_impressions=100_000,
27
+ total_wasted_spend=278.7,
28
+ gvp_app_spend=92.9,
29
+ on_target_spend=464.5,
30
+ )
31
+ assert econ.nominal_cpm == 9.29
32
+ assert econ.qualified_delivery_rate == 0.7
33
+ assert econ.qualified_cpm == 13.27
34
+ assert econ.on_target_cpm == 18.58
35
+ assert econ.vendor_breakeven_multiplier == 1.36
36
+ assert econ.vendor_breakeven_premium_pct == 36.0
37
+ assert econ.gvp_mobile_app_spend == 92.9
38
+ assert econ.gvp_mobile_app_percentage == 10.0
39
+
40
+
41
+ def test_gvp_and_mobile_app_detection(tmp_path: Path) -> None:
42
+ assert is_gvp_or_mobile_app("mobileapp::1-com.candycrush.saga") == (True, "MOBILE_APP_PLACEMENT")
43
+ assert is_gvp_or_mobile_app("random-blog-news.com") == (True, "GVP_THIRD_PARTY_SITE")
44
+ assert is_gvp_or_mobile_app("anonymous.google") == (True, "GVP_ANONYMOUS_PARTNER")
45
+ assert is_gvp_or_mobile_app("youtube.com/channel/UCBJycsmduvYEL83R_U4JriQ") == (False, "")
46
+
47
+ csv_file = tmp_path / "gvp_mix.csv"
48
+ csv_file.write_text(
49
+ """Placement,Placement name,Cost,Impr.,Views,Clicks,Conversions,View-through conv.,Day
50
+ mobileapp::1-com.kids.coloring,Coloring App,300.00,30000,0,50,0,0,2026-05-15
51
+ daily-clickbait-site.net,Clickbait Blog,200.00,20000,100,10,0,0,2026-07-10
52
+ youtube.com/channel/UCBJycsmduvYEL83R_U4JriQ,MKBHD Tech,500.00,50000,15000,200,10,9,2026-09-01
53
+ """,
54
+ encoding="utf-8",
55
+ )
56
+
57
+ report = tubesentry.audit_placements(report=csv_file, print_banner=False)
58
+ assert report.quality_economics is not None
59
+ assert report.quality_economics.gvp_mobile_app_spend == 500.0
60
+ assert report.quality_economics.gvp_mobile_app_percentage == 50.0
61
+ assert report.category_breakdowns["GVP_MOBILE_APP_LEAK"].channel_count == 2
62
+
63
+ assert report.attribution_health is not None
64
+ assert report.attribution_health.attribution_inflation_warning is True
65
+ assert report.attribution_health.vtc_evc_share_pct == 90.0
66
+ # Date range 2026-05-15 -> 2026-09-01 spans all 3 documented 2026 breakpoints
67
+ assert len(report.attribution_health.platform_breakpoints_detected) == 3
68
+
69
+
70
+ def test_adh_sql_and_demand_gen_script_generators(tmp_path: Path) -> None:
71
+ sql = generate_adh_quality_sql(lookback_days=45)
72
+ assert "adh.google_ads_impressions" in sql
73
+ assert "adh.google_ads_active_views" in sql
74
+ assert "adh.google_ads_creative_conversions" in sql
75
+ assert "UNION ALL" in sql
76
+ assert "groupm_viewable_impressions" in sql
77
+ assert "audible_and_fully_visible_watchtime_msec" in sql
78
+ assert "INTERVAL 45 DAY" in sql
79
+
80
+ script = generate_demand_gen_hygiene_script(dry_run=True)
81
+ assert "DEMAND_GEN" in script
82
+ assert "ALL_OWNED_AND_OPERATED_CHANNELS" in script
83
+ assert "GENERATE_ENHANCED_YOUTUBE_VIDEOS" in script
84
+ assert "MOBILE_APPLICATION" in script
85
+
86
+ adh_out = tmp_path / "adh.sql"
87
+ res1 = runner.invoke(app, ["export", "adh", "--out", str(adh_out), "--days", "14"])
88
+ assert res1.exit_code == 0
89
+ assert adh_out.exists()
90
+
91
+ dg_out = tmp_path / "dg.js"
92
+ res2 = runner.invoke(app, ["export", "demand-gen-audit", "--out", str(dg_out)])
93
+ assert res2.exit_code == 0
94
+ assert dg_out.exists()
95
+
96
+
97
+ def test_attribution_health_empty_df() -> None:
98
+ import pandas as pd
99
+
100
+ health = analyze_attribution_and_breakpoints(pd.DataFrame())
101
+ assert health.attribution_inflation_warning is False
102
+ assert health.platform_breakpoints_detected == []
@@ -8,14 +8,19 @@ import pandas as pd
8
8
 
9
9
  from tubesentry.contracts.schemas import AuditSummaryReport
10
10
  from tubesentry.core.auditor import run_free_audit
11
- from tubesentry.integrations import generate_bigquery_dts_sql, generate_google_ads_script
11
+ from tubesentry.integrations import (
12
+ generate_adh_quality_sql,
13
+ generate_bigquery_dts_sql,
14
+ generate_demand_gen_hygiene_script,
15
+ generate_google_ads_script,
16
+ )
12
17
  from tubesentry.io.ingestor import load_placement_report
13
18
  from tubesentry.pro import bridge
14
19
  from tubesentry.pro.bridge import dispatch_pro_audit, is_pro_available
15
20
  from tubesentry.pro.installer import install_pro
16
21
  from tubesentry.skills import get_bundled_skill_path, get_bundled_skill_text, install_skill
17
22
 
18
- __version__ = "0.1.2"
23
+ __version__ = "0.2.0"
19
24
 
20
25
 
21
26
  def audit_placements(
@@ -26,6 +31,8 @@ def audit_placements(
26
31
  youtube_api_key: str | None = None,
27
32
  export_exclusions_csv: str | None = None,
28
33
  export_65k_shield_csv: str | None = None,
34
+ export_inclusions_csv: str | None = None,
35
+ exclusion_mode: str = "standalone",
29
36
  export_html_deck: str | None = None,
30
37
  export_google_ads_script: str | None = None,
31
38
  white_label_config: dict[str, Any] | None = None,
@@ -57,6 +64,8 @@ def audit_placements(
57
64
  youtube_api_key=youtube_api_key,
58
65
  export_exclusions_csv=export_exclusions_csv,
59
66
  export_65k_shield_csv=export_65k_shield_csv,
67
+ export_inclusions_csv=export_inclusions_csv,
68
+ exclusion_mode=exclusion_mode,
60
69
  export_html_deck=export_html_deck,
61
70
  white_label_config=white_label_config,
62
71
  ad_url=ad_url,
@@ -67,6 +76,7 @@ def audit_placements(
67
76
  api_key
68
77
  or export_exclusions_csv
69
78
  or export_65k_shield_csv
79
+ or export_inclusions_csv
70
80
  or export_html_deck
71
81
  or ad_url
72
82
  or ad_text
@@ -81,6 +91,8 @@ def audit_placements(
81
91
  youtube_api_key=youtube_api_key,
82
92
  export_exclusions_csv=export_exclusions_csv,
83
93
  export_65k_shield_csv=export_65k_shield_csv,
94
+ export_inclusions_csv=export_inclusions_csv,
95
+ exclusion_mode=exclusion_mode,
84
96
  export_html_deck=export_html_deck,
85
97
  white_label_config=white_label_config,
86
98
  ad_url=ad_url,
@@ -113,7 +125,9 @@ __all__ = [
113
125
  "AuditSummaryReport",
114
126
  "__version__",
115
127
  "audit_placements",
128
+ "generate_adh_quality_sql",
116
129
  "generate_bigquery_dts_sql",
130
+ "generate_demand_gen_hygiene_script",
117
131
  "generate_google_ads_script",
118
132
  "get_bundled_skill_path",
119
133
  "get_bundled_skill_text",
@@ -97,7 +97,17 @@ def audit(
97
97
  out_65k: Path | None = typer.Option(
98
98
  None,
99
99
  "--out-65k",
100
- help="Path to export full 65,000-channel protection shield CSV (Pro feature).",
100
+ help="Path to export full 65,000-channel (or 250k MCC) protection shield CSV (Pro feature).",
101
+ ),
102
+ out_inclusions: Path | None = typer.Option(
103
+ None,
104
+ "--out-inclusions",
105
+ help="Path to export verified On-Target positive inclusion whitelist CSV (Pro feature).",
106
+ ),
107
+ exclusion_mode: str = typer.Option(
108
+ "standalone",
109
+ "--exclusion-mode",
110
+ help="Exclusion export mode: 'standalone' (20k chunks, 65k cap) or 'mcc' (250k shared cap).",
101
111
  ),
102
112
  html: Path | None = typer.Option(
103
113
  None,
@@ -132,6 +142,8 @@ def audit(
132
142
  api_key=key,
133
143
  export_exclusions_csv=str(out_exclusions) if out_exclusions else None,
134
144
  export_65k_shield_csv=str(out_65k) if out_65k else None,
145
+ export_inclusions_csv=str(out_inclusions) if out_inclusions else None,
146
+ exclusion_mode=exclusion_mode,
135
147
  export_html_deck=str(html) if html else None,
136
148
  export_google_ads_script=str(export_script) if export_script else None,
137
149
  print_banner=True,
@@ -367,3 +379,49 @@ def export_bigquery_cmd(
367
379
 
368
380
  if __name__ == "__main__":
369
381
  app()
382
+
383
+
384
+ @export_app.command(name="adh")
385
+ def export_adh_cmd(
386
+ out_file: Path = typer.Option(
387
+ Path("tubesentry_adh_quality.sql"),
388
+ "--out",
389
+ "-o",
390
+ help="Destination path for the Ads Data Hub SQL file.",
391
+ ),
392
+ lookback_days: int = typer.Option(
393
+ 30,
394
+ "--days",
395
+ help="Lookback window in days.",
396
+ ),
397
+ ) -> None:
398
+ """Exports an Ads Data Hub (ADH) 3-table UNION ALL SQL query for GroupM viewability, AVOC, and audible watchtime."""
399
+ from tubesentry.integrations import generate_adh_quality_sql
400
+
401
+ sql = generate_adh_quality_sql(lookback_days=lookback_days)
402
+ out_file.parent.mkdir(parents=True, exist_ok=True)
403
+ out_file.write_text(sql, encoding="utf-8")
404
+ console.print(f"[bold green][OK] Ads Data Hub SQL exported to:[/bold green] {out_file}")
405
+
406
+
407
+ @export_app.command(name="demand-gen-audit")
408
+ def export_demand_gen_audit_cmd(
409
+ out_file: Path = typer.Option(
410
+ Path("demand_gen_dec2026_audit.js"),
411
+ "--out",
412
+ "-o",
413
+ help="Destination path for the Demand Gen & Video Enhancements Google Ads Script.",
414
+ ),
415
+ dry_run: bool = typer.Option(
416
+ True,
417
+ "--dry-run/--live",
418
+ help="Whether the generated script defaults to dry-run preview mode.",
419
+ ),
420
+ ) -> None:
421
+ """Exports a Google Ads Script auditing Dec 1, 2026 Demand Gen Display opt-outs, auto-generated videos, and GVP leakage."""
422
+ from tubesentry.integrations import generate_demand_gen_hygiene_script
423
+
424
+ script_js = generate_demand_gen_hygiene_script(dry_run=dry_run)
425
+ out_file.parent.mkdir(parents=True, exist_ok=True)
426
+ out_file.write_text(script_js, encoding="utf-8")
427
+ console.print(f"[bold green][OK] Demand Gen Hygiene Script exported to:[/bold green] {out_file}")
@@ -12,6 +12,7 @@ WasteCategoryType = Literal[
12
12
  "FOREIGN_SCRIPT_LEAK",
13
13
  "AI_SLOP_CLICK_FARM",
14
14
  "PERFORMANCE_SINKHOLE",
15
+ "GVP_MOBILE_APP_LEAK",
15
16
  ]
16
17
 
17
18
 
@@ -131,6 +132,30 @@ class CreativeAlignmentSummary(BaseModel):
131
132
  strategic_recommendations: list[str] = Field(default_factory=list)
132
133
 
133
134
 
135
+ class QualityEconomicsSummary(BaseModel):
136
+ """Quality-Adjusted CPM (qCPM / TrueCPM) and curated vendor break-even economics."""
137
+ nominal_cpm: float = 0.0
138
+ qualified_delivery_rate: float = 1.0
139
+ qualified_cpm: float = 0.0
140
+ on_target_cpm: float | None = None
141
+ curated_target_quality: float = 0.95
142
+ vendor_breakeven_multiplier: float = 1.0
143
+ vendor_breakeven_premium_pct: float = 0.0
144
+ gvp_mobile_app_spend: float = 0.0
145
+ gvp_mobile_app_percentage: float = 0.0
146
+
147
+
148
+ class AttributionHealthSummary(BaseModel):
149
+ """View-Through / Engaged-View attribution inflation and 2026 platform breakpoint diagnostics."""
150
+ total_conversions: float = 0.0
151
+ view_through_conversions: float = 0.0
152
+ engaged_view_conversions: float = 0.0
153
+ vtc_evc_share_pct: float = 0.0
154
+ attribution_inflation_warning: bool = False
155
+ warning_message: str | None = None
156
+ platform_breakpoints_detected: list[str] = Field(default_factory=list)
157
+
158
+
134
159
  class AuditSummaryReport(BaseModel):
135
160
  """Comprehensive executive audit report generated from placement analysis."""
136
161
  total_placements_audited: int
@@ -152,6 +177,10 @@ class AuditSummaryReport(BaseModel):
152
177
  annualized_recoverable_runrate: float = 0.0
153
178
  exclusions_csv_path: str | None = None
154
179
  shield_65k_csv_path: str | None = None
180
+ inclusions_csv_path: str | None = None
181
+ exclusion_chunk_paths: list[str] = Field(default_factory=list)
155
182
  html_report_path: str | None = None
156
183
  upgrade_prompt: str | None = None
157
184
  creative_alignment: CreativeAlignmentSummary | None = None
185
+ quality_economics: QualityEconomicsSummary | None = None
186
+ attribution_health: AttributionHealthSummary | None = None
@@ -12,6 +12,7 @@ class WasteCategory(str, Enum):
12
12
  FOREIGN_SCRIPT_LEAK = "FOREIGN_SCRIPT_LEAK"
13
13
  AI_SLOP_CLICK_FARM = "AI_SLOP_CLICK_FARM"
14
14
  PERFORMANCE_SINKHOLE = "PERFORMANCE_SINKHOLE"
15
+ GVP_MOBILE_APP_LEAK = "GVP_MOBILE_APP_LEAK"
15
16
 
16
17
 
17
18
  # Freebase topic IDs and Wikipedia ontology mappings from YouTube Data API v3
@@ -63,4 +64,5 @@ CATEGORY_DESCRIPTIONS: dict[WasteCategory, str] = {
63
64
  WasteCategory.FOREIGN_SCRIPT_LEAK: "Foreign language and non-Latin script leakage mismatched with campaign geotargeting.",
64
65
  WasteCategory.AI_SLOP_CLICK_FARM: "High-frequency synthetic AI content farms, faceless TTS shorts, and click arbitrage.",
65
66
  WasteCategory.PERFORMANCE_SINKHOLE: "Empirical budget bleed placements exceeding 3x Target CPA with zero conversions.",
67
+ WasteCategory.GVP_MOBILE_APP_LEAK: "Third-party Google Video Partners (GVP) websites and mobile apps outside YouTube Owned & Operated inventory.",
66
68
  }
@@ -7,8 +7,10 @@ import pandas as pd
7
7
  from rich.console import Console
8
8
 
9
9
  from tubesentry.contracts.schemas import (
10
+ AttributionHealthSummary,
10
11
  AuditSummaryReport,
11
12
  ClassifiedChannelRecord,
13
+ QualityEconomicsSummary,
12
14
  WasteCategoryBreakdown,
13
15
  )
14
16
  from tubesentry.contracts.taxonomy import CATEGORY_DESCRIPTIONS, WasteCategory
@@ -27,6 +29,107 @@ def normalize_topic_category(topic_str: str) -> str:
27
29
  return topic_name.replace("_", " ").strip()
28
30
 
29
31
 
32
+ def compute_quality_economics(
33
+ total_spend: float,
34
+ total_impressions: int,
35
+ total_wasted_spend: float,
36
+ gvp_app_spend: float = 0.0,
37
+ on_target_spend: float | None = None,
38
+ curated_target_quality: float = 0.95,
39
+ ) -> QualityEconomicsSummary:
40
+ """Computes Nominal CPM, Quality-Adjusted CPM (qCPM), and curated vendor break-even math."""
41
+ nominal_cpm = (total_spend / total_impressions * 1000.0) if total_impressions > 0 else 0.0
42
+ qualified_rate = (
43
+ max(0.01, min(1.0, (total_spend - total_wasted_spend) / total_spend))
44
+ if total_spend > 0
45
+ else 1.0
46
+ )
47
+ qualified_cpm = (nominal_cpm / qualified_rate) if nominal_cpm > 0 else 0.0
48
+
49
+ on_target_cpm: float | None = None
50
+ if on_target_spend is not None and total_spend > 0 and on_target_spend > 0 and nominal_cpm > 0:
51
+ on_target_rate = max(0.01, min(1.0, on_target_spend / total_spend))
52
+ on_target_cpm = round(nominal_cpm / on_target_rate, 2)
53
+
54
+ breakeven_mult = round(curated_target_quality / qualified_rate, 2) if qualified_rate > 0 else 1.0
55
+ breakeven_premium_pct = round(max(0.0, (breakeven_mult - 1.0) * 100.0), 1)
56
+ gvp_pct = round((gvp_app_spend / total_spend * 100.0), 2) if total_spend > 0 else 0.0
57
+
58
+ return QualityEconomicsSummary(
59
+ nominal_cpm=round(nominal_cpm, 2),
60
+ qualified_delivery_rate=round(qualified_rate, 4),
61
+ qualified_cpm=round(qualified_cpm, 2),
62
+ on_target_cpm=on_target_cpm,
63
+ curated_target_quality=curated_target_quality,
64
+ vendor_breakeven_multiplier=breakeven_mult,
65
+ vendor_breakeven_premium_pct=breakeven_premium_pct,
66
+ gvp_mobile_app_spend=round(gvp_app_spend, 2),
67
+ gvp_mobile_app_percentage=gvp_pct,
68
+ )
69
+
70
+
71
+ _PLATFORM_BREAKPOINTS_2026 = [
72
+ (
73
+ "2026-06-02",
74
+ "2026-06-02 (Total Co-view Reach): Google Ads added modeled CTV co-viewers to 7 reach & frequency metrics — annotate dashboard trend breaks.",
75
+ ),
76
+ (
77
+ "2026-08-01",
78
+ "2026-08-01 (Multi-Format Reach Auto-Upgrade): Legacy in-stream Efficient Reach campaigns auto-upgraded to Shorts/In-Feed — blended CPM drops may mask lower attention.",
79
+ ),
80
+ (
81
+ "2026-08-24",
82
+ "2026-08-24 (Public View Count Overhaul): YouTube public views count from frame 1 — do not conflate with billable ad views (30s in-stream / 10s Shorts).",
83
+ ),
84
+ ]
85
+
86
+
87
+ def analyze_attribution_and_breakpoints(df: pd.DataFrame) -> AttributionHealthSummary:
88
+ """Detects VTC/EVC attribution inflation and 2026 YouTube platform measurement breakpoints."""
89
+ total_conv = float(df["conversions"].sum()) if (not df.empty and "conversions" in df.columns) else 0.0
90
+ vtc = (
91
+ float(df["view_through_conversions"].sum())
92
+ if (not df.empty and "view_through_conversions" in df.columns)
93
+ else 0.0
94
+ )
95
+ evc = (
96
+ float(df["engaged_view_conversions"].sum())
97
+ if (not df.empty and "engaged_view_conversions" in df.columns)
98
+ else 0.0
99
+ )
100
+
101
+ denom = max(total_conv, vtc + evc)
102
+ vtc_evc_share = round(((vtc + evc) / denom * 100.0), 1) if denom > 0 else 0.0
103
+ inflation_warn = bool(denom > 0 and vtc_evc_share >= 70.0)
104
+ warn_msg = (
105
+ f"Attribution inflation risk: {vtc_evc_share}% of conversions come from View-Through/Engaged-View "
106
+ f"({vtc + evc:.1f} VTC+EVC vs {total_conv:.1f} total). Validate with Search Lift or geo-holdouts."
107
+ if inflation_warn
108
+ else None
109
+ )
110
+
111
+ breakpoints: list[str] = []
112
+ if not df.empty and "date" in df.columns:
113
+ parsed_dates = pd.to_datetime(df["date"], errors="coerce").dropna()
114
+ if not parsed_dates.empty:
115
+ min_d = parsed_dates.min()
116
+ max_d = parsed_dates.max()
117
+ for bp_str, bp_desc in _PLATFORM_BREAKPOINTS_2026:
118
+ bp_ts = pd.Timestamp(bp_str)
119
+ if min_d <= bp_ts <= max_d:
120
+ breakpoints.append(bp_desc)
121
+
122
+ return AttributionHealthSummary(
123
+ total_conversions=round(total_conv, 2),
124
+ view_through_conversions=round(vtc, 2),
125
+ engaged_view_conversions=round(evc, 2),
126
+ vtc_evc_share_pct=vtc_evc_share,
127
+ attribution_inflation_warning=inflation_warn,
128
+ warning_message=warn_msg,
129
+ platform_breakpoints_detected=breakpoints,
130
+ )
131
+
132
+
30
133
  def run_free_audit(
31
134
  df: pd.DataFrame,
32
135
  target_languages: list[str] | None = None,
@@ -229,8 +332,17 @@ def run_free_audit(
229
332
  )
230
333
 
231
334
  coppa_kids_spend = category_stats["MADE_FOR_KIDS"]["wasted_spend"]
335
+ gvp_app_spend = category_stats["GVP_MOBILE_APP_LEAK"]["wasted_spend"]
232
336
  annual_runrate = total_wasted_spend * 12.0
233
337
 
338
+ quality_econ = compute_quality_economics(
339
+ total_spend=total_spend,
340
+ total_impressions=total_impressions,
341
+ total_wasted_spend=total_wasted_spend,
342
+ gvp_app_spend=gvp_app_spend,
343
+ )
344
+ attr_health = analyze_attribution_and_breakpoints(df)
345
+
234
346
  banner_text = _build_diagnostic_banner(
235
347
  total_placements=total_placements,
236
348
  total_spend=total_spend,
@@ -269,6 +381,8 @@ def run_free_audit(
269
381
  coppa_kids_risk_spend=round(coppa_kids_spend, 2),
270
382
  annualized_recoverable_runrate=round(annual_runrate, 2),
271
383
  upgrade_prompt=banner_text,
384
+ quality_economics=quality_econ,
385
+ attribution_health=attr_health,
272
386
  )
273
387
 
274
388