# Link & UTM Checker
Crawl campaign URLs to detect broken links and malformed UTM (Urchin Tracking Module — the query parameters used to track marketing campaign performance) parameters, then alert a human when problems are found.

## When to use
- Before a campaign email or ad set goes live, to confirm every linked URL resolves and is tagged correctly.
- On a recurring monitoring cadence to catch links that broke after launch (redirects removed, pages taken down).
- When a teammate reports a click that landed on a 404 or an analytics dashboard showing missing campaign attribution.

## Tools
- `browser-navigate` — load each campaign URL to confirm it resolves and to follow any redirect chain.
- `browser-extract` — pull the rendered page state (title, status indicators, final URL) and the outbound link list from a landing page.
- `shell-execute` — parse the collected URL list, validate UTM parameter structure (utm_source, utm_medium, utm_campaign present and non-empty), and diff against the expected campaign spec.
- `send-message` — alert a human or another agent in-session when broken links or malformed UTMs are found.
- `schedule-task`: register this watch on a recurring cron cadence so it reruns automatically without a human re-enqueuing it.

## Cadence

Monitoring must repeat, not run once. On first setup, use `schedule-task` to register a recurring run of this check on an appropriate cron cadence (for example `0 * * * *` hourly or `0 9 * * *` daily), passing the same monitoring instruction as the schedule prompt. The platform then reruns it automatically at each due time — you never depend on a human to re-enqueue it. Create the schedule only once; if this check is already scheduled, skip re-creating it.

## Playbook
1. Read the campaign brief or task payload to get the list of URLs and the expected UTM parameter values (source, medium, campaign name).
2. Use `shell-execute` to normalize the URL list into a working file (dedupe, strip whitespace).
3. For each URL, call `browser-navigate` to load it and follow any redirects.
4. Call `browser-extract` after navigation to capture the final resolved URL, page title, and any visible error state (404, "page not found", blank page).
5. Use `shell-execute` to compare the final URL's query string against the expected UTM schema: confirm utm_source, utm_medium, and utm_campaign are present, non-empty, and match the approved values for this campaign.
6. Use `shell-execute` to flag any URL that returned a non-200-looking state (based on extracted page signals) or redirected somewhere unexpected.
7. Use `shell-execute` to compile a results table: URL, status (ok/broken/malformed-utm), and details for each failure.
8. If any URL is broken or has malformed UTMs, use `send-message` to alert a human, listing the specific URLs and the exact problem for each.
9. If everything passes, use `send-message` to confirm the campaign's links and UTMs are clean, citing the count of URLs checked.

## Failure modes
- Navigation blocked or page requires login unexpectedly -> note the URL as unverifiable and flag it via `send-message` rather than guessing its status.
- Empty or missing URL list in the task payload -> stop and verify the expected input source with a human before proceeding.
- Rate limited or throttled while crawling many URLs -> back off between requests and note the slowdown for future runs.
- Landing page structure changed so extraction returns nothing useful -> fall back to browser-search to confirm the domain is still live, then report degraded confidence in the result.

## Done when
- Every URL in the campaign list has been navigated to and checked against its expected UTM schema.
- A results table exists distinguishing ok, broken, and malformed-utm URLs.
- A human has been alerted via `send-message` with specifics if any failures were found, or a clean confirmation was sent if none were.