# X (Twitter) Ads Change Monitor (`immense_insulator/x-ads-daily-delta-monitor`) Actor

Monitor X (Twitter) Ads Repository advertisers on a schedule and emit only NEW, CHANGED, or ENDED ads. Stateful delta monitoring with a silent BASELINE first run; no login or user cookies.

- **URL**: https://apify.com/immense\_insulator/x-ads-daily-delta-monitor.md
- **Developed by:** [xinyao a](https://apify.com/immense_insulator) (community)
- **Categories:** Social media
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $5.00 / 1,000 ad changes

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## X Ads Daily Delta Monitor

Stateful monitoring for the **public X Ads Repository**. Give it advertiser screen names; the Actor stores a fingerprinted snapshot in an Apify named Key-value store and emits changes to the Dataset.

### Output semantics

- First run with `firstRunMode: "BASELINE"` (default): save the baseline without Dataset rows, avoiding an unexpected per-item charge for every current ad.
- First run with `CURRENT`: emit every observed ad as `CURRENT`, then save the baseline.
- Later **fully successful** runs: emit `NEW`, `CHANGED`, or `ENDED` only.
- `ENDED` is an inference: an ad is absent from the rolling query window for `missingRunsToEnd` consecutive complete runs (default 2). X's route does not expose an explicit end timestamp.
- If any country/date page fails, a request/ad cap is reached, or all changes do not fit `maxItems`, that advertiser's state is **not advanced**. A partial scrape therefore cannot mark every prior ad `ENDED`.

`CHANGED` includes changes in public metadata, targeting, reach, or impressions. Each row contains the previous/current SHA-256 fingerprints.

### Example

```json
{
  "advertisers": ["Apple"],
  "countries": ["FR", "DE"],
  "lookbackDays": 2,
  "firstRunMode": "CURRENT",
  "missingRunsToEnd": 2,
  "maxItems": 1000
}
```

### Start monitoring in 2 minutes

1. Leave `firstRunMode` as `BASELINE` and click **Start** once. This saves the initial snapshot with zero Dataset rows, so the first inventory is not billed per ad.
2. On the finished run page, click **Schedule** → **Create new schedule**, select a daily interval, and keep the same named Key-value store.
3. Future complete runs emit only `NEW`, `CHANGED`, or `ENDED` rows. Add a Dataset-item webhook or export the Dataset as JSON/CSV for alerts and reporting.

Use a distinct `stateStoreName` for each independent advertiser monitoring job. Do not change or purge that named store between scheduled runs.

For a reproducible historical source check:

```json
{
  "advertisers": ["Apple"],
  "countries": ["FR"],
  "startDate": "2023-08-26",
  "endDate": "2024-08-25",
  "pageDays": 366,
  "firstRunMode": "CURRENT",
  "stateStoreName": "x-ads-monitor-demo"
}
```

### Dataset fields

`advertiser`, `tweetId`, `lineItemId`, `accountId`, `creativeUrl`, `country`, `account`, `fundingInstrument`, `approvalStatus`, `targeting`, `impressions`, `reach`, `changeType`, `firstSeenAt`, `lastSeenAt`, `observedAt`, `fingerprints`, and `sourceUrl`.

### Source and privacy

The Actor first loads `https://ads.x.com/ads-repository`, retaining only the anonymous guest/CSRF session issued by X, then calls the exact public frontend `user-search` and `ads-search` POST payloads. These are undocumented frontend routes, not a supported X API; schema validation fails closed if they drift. No X login, user-supplied cookie, proxy bypass, or personal-data collection is used. Respect X's terms, public-data policy, and applicable law.

### Pagination and limits

The live route returns an array and exposes no continuation token. The Actor creates deterministic pages by **country × inclusive date window** (`pageDays`), deduplicates `(tweetId, lineItemId, country)`, retries 429/5xx/network errors, and enforces `maxRequests`, `maxAdsPerAdvertiser`, and `maxItems`.

### Local development

```bash
python -m venv .venv
. .venv/bin/activate
pip install -r requirements-dev.txt
PYTHONPATH=src pytest -q
APIFY_LOCAL_STORAGE_DIR=./storage python -m src
```

Live request evidence and the observed schemas are recorded in `research/live-endpoint-evidence.json`. The included sample is a real public ad identity and contains no private data.

# Actor input Schema

## `advertisers` (type: `array`):

One to 20 X screen names without passwords or cookies, for example Apple.

## `countries` (type: `array`):

X Ads Repository country codes. Each country is fetched independently for failure isolation.

## `lookbackDays` (type: `integer`):

Default rolling query window used when fixed dates are omitted.

## `startDate` (type: `string`):

Optional YYYY-MM-DD integration/backfill start. Supply endDate too. Fixed-date state is isolated from rolling state.

## `endDate` (type: `string`):

Optional YYYY-MM-DD integration/backfill end. Supply startDate too.

## `firstRunMode` (type: `string`):

BASELINE (recommended) stores the initial snapshot silently to avoid charging for every current ad. CURRENT emits the initial snapshot. Later complete runs emit NEW/CHANGED/ENDED.

## `missingRunsToEnd` (type: `integer`):

An ad is inferred ENDED only after this many consecutive fully successful observations omit it.

## `pageDays` (type: `integer`):

Split long date ranges into bounded inclusive windows; country × date window is one page.

## `maxItems` (type: `integer`):

Hard dataset row limit. An advertiser state is not committed when all its changes do not fit, preventing silent loss.

## `maxRequests` (type: `integer`):

Hard request budget including landing-page session and advertiser lookup requests.

## `maxAdsPerAdvertiser` (type: `integer`):

Safety cap. Exceeding it marks the fetch incomplete and prevents state advancement.

## `retries` (type: `integer`):

Retries for throttling, server errors, and network failures with exponential backoff.

## `stateStoreName` (type: `string`):

Named Key-value store shared by scheduled runs. Change this to isolate customers or monitoring jobs.

## `resetState` (type: `boolean`):

Delete state for the supplied advertiser scopes before this run; use deliberately.

## Actor input object example

```json
{
  "advertisers": [
    "Apple"
  ],
  "countries": [
    "FR"
  ],
  "lookbackDays": 2,
  "firstRunMode": "BASELINE",
  "missingRunsToEnd": 2,
  "pageDays": 90,
  "maxItems": 1000,
  "maxRequests": 500,
  "maxAdsPerAdvertiser": 10000,
  "retries": 3,
  "stateStoreName": "x-ads-daily-delta-monitor-v1",
  "resetState": false
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("immense_insulator/x-ads-daily-delta-monitor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("immense_insulator/x-ads-daily-delta-monitor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call immense_insulator/x-ads-daily-delta-monitor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,immense_insulator/x-ads-daily-delta-monitor"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/0BBeXFgeQS3U9YloP/builds/0U7aLsynygvWsdQLO/openapi.json
