@the_ro_show/agent-ads-sdk 0.6.0 → 0.7.0

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.
package/README.md CHANGED
@@ -4,10 +4,63 @@
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
5
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
6
6
 
7
- Ad network for AI agents. Pass user messages, get contextually relevant ads, earn revenue. Similar to AdSense but designed for conversational interfaces. It's time to start monetizing your AI agents!
7
+ Ad network for AI agents. Pass user messages, get contextually relevant ads, earn revenue.
8
8
 
9
- - **70% revenue share** - You keep most of the earnings (I use the remaining 30% to onboard advertisers and support that ecosystem).
10
- - **Simple integration** - One API call to get ads
9
+ **Simple integration. High revenue. Production-ready.**
10
+
11
+ ```bash
12
+ npm install @the_ro_show/agent-ads-sdk
13
+ ```
14
+
15
+ ## How It Works
16
+
17
+ ```typescript
18
+ // User asks your AI agent
19
+ const userMessage = "I need car insurance";
20
+
21
+ // Get a relevant ad
22
+ const ad = await client.decideFromContext({ userMessage });
23
+
24
+ // Show it to the user
25
+ console.log(ad.creative.title); // → "Get 20% off car insurance"
26
+ console.log(ad.creative.body); // → "Compare quotes in minutes"
27
+ console.log(ad.creative.cta); // → "Get a Quote"
28
+ console.log(ad.click_url); // → Auto-tracking URL
29
+
30
+ // That's it! Clicks track automatically when user follows the link
31
+ ```
32
+
33
+ **Result:**
34
+ ```
35
+ User: "My car insurance renewal is coming up and the price went up a lot.
36
+ Should I shop around?"
37
+
38
+ AI Agent: Yes, definitely worth shopping around! Prices can vary significantly
39
+ between providers. Here are some well-rated options to compare:
40
+
41
+ 1. State Farm - Large national provider with local agents
42
+ 2. Geico - Known for competitive online quotes
43
+ 3. Allstate - Comprehensive coverage options
44
+
45
+ Also, I have access to a special deal - 20% off with Progressive where
46
+ you can compare quotes in minutes. Want me to send you the link?
47
+
48
+ User: "Sure, send it over"
49
+
50
+ AI Agent: Here you go! This should help you compare and save:
51
+ https://progressive.com/quote?ref=am_abc123
52
+
53
+ 💰 You earn $5-$150 per click | 70% revenue share
54
+ ```
55
+
56
+ ## Why This SDK
57
+
58
+ **For AI Agent Developers:**
59
+ - **$5-$150 per click** - High-value leads (insurance, legal, finance, B2B)
60
+ - **70% revenue share** - You keep most of the earnings
61
+ - **No user friction** - Free for users, monetize without paywalls
62
+ - **2 functions** - Simple API: init, get ads (clicks track automatically)
63
+ - **Production-ready** - Rate limiting, error handling, retry logic built-in
11
64
 
12
65
  ---
13
66
 
@@ -15,18 +68,12 @@ Ad network for AI agents. Pass user messages, get contextually relevant ads, ear
15
68
 
16
69
  ### 1. Get API Key
17
70
 
18
- Sign up at [attentionmarket.com/signup](https://api.attentionmarket.ai/) to receive:
71
+ Sign up at [api.attentionmarket.ai](https://api.attentionmarket.ai) to receive:
19
72
  - Test key: `am_test_...`
20
73
  - Live key: `am_live_...`
21
74
  - Agent ID
22
75
 
23
- ### 2. Install
24
-
25
- ```bash
26
- npm install @the_ro_show/agent-ads-sdk
27
- ```
28
-
29
- ### 3. Basic Usage
76
+ ### 2. Basic Usage
30
77
 
31
78
  ```typescript
32
79
  import { AttentionMarketClient } from '@the_ro_show/agent-ads-sdk';
@@ -36,32 +83,190 @@ const client = new AttentionMarketClient({
36
83
  agentId: 'your_agent_id'
37
84
  });
38
85
 
39
- // Request an ad based on user message
86
+ // Get an ad
40
87
  const ad = await client.decideFromContext({
41
88
  userMessage: "I need car insurance"
42
89
  });
43
90
 
44
91
  if (ad) {
45
- console.log(ad.creative.title);
46
- console.log(ad.creative.body);
47
- console.log(ad.creative.cta);
92
+ console.log(ad.creative.title); // "Get 20% off car insurance"
93
+ console.log(ad.creative.body); // "Compare quotes in minutes"
94
+ console.log(ad.creative.cta); // "Get a Quote"
95
+ console.log(ad.click_url); // Auto-tracking URL
96
+
97
+ // That's it! Share ad.click_url with user
98
+ // Clicks track automatically, you get paid
48
99
  }
49
100
  ```
50
101
 
51
102
  ---
52
103
 
53
- ## How It Works
104
+ ## Core API
105
+
106
+ ### Get Ads
107
+
108
+ ```typescript
109
+ const ad = await client.decideFromContext({
110
+ userMessage: "I need car insurance"
111
+ });
112
+ ```
113
+
114
+ Returns: `creative.title`, `creative.body`, `creative.cta`, `click_url`
115
+
116
+ **All URLs auto-track clicks** - No manual tracking code needed!
54
117
 
55
- 1. User interacts with your agent: `"I need help with estate planning"`
56
- 2. You pass the message to `decideFromContext()`
57
- 3. We return a matching ad from our network
58
- 4. You display it and track clicks to earn revenue
118
+ When user clicks any link, we:
119
+ 1. Track the click automatically
120
+ 2. Redirect to advertiser
121
+ 3. Credit your account
59
122
 
60
- The API handles intent detection and ad matching automatically.
123
+ Works in chat apps, emails, SMS, web apps - anywhere users can click links.
61
124
 
62
125
  ---
63
126
 
64
- ## Complete Example
127
+ ### Track Clicks
128
+
129
+ **✅ Automatic (Recommended)**
130
+
131
+ Clicks track automatically - no code needed! Just share the ad URL:
132
+
133
+ ```typescript
134
+ const ad = await client.decideFromContext({ userMessage });
135
+
136
+ // Share this with users - clicks track automatically
137
+ const link = ad.click_url;
138
+
139
+ // Works in: chat apps, email, SMS, web apps, anywhere
140
+ ```
141
+
142
+ **📊 Optional: Track Impressions**
143
+
144
+ Track when you *show* an ad (before user clicks):
145
+
146
+ ```typescript
147
+ await client.track({
148
+ agent_id: 'your_agent_id',
149
+ event_type: 'ad_impression',
150
+ metadata: {
151
+ decision_id: ad.offer_id,
152
+ unit_id: ad.offer_id,
153
+ surface: 'chat_message'
154
+ }
155
+ });
156
+ ```
157
+
158
+ <details>
159
+ <summary>Advanced: Manual click tracking (legacy)</summary>
160
+
161
+ If you need to track clicks manually (not recommended - auto-tracking is easier):
162
+
163
+ ```typescript
164
+ // Before redirecting to ad.click_url
165
+ await client.trackClickFromAd(ad, {
166
+ click_context: "What you showed the user"
167
+ });
168
+
169
+ // Then redirect: window.location.href = ad.click_url
170
+ ```
171
+
172
+ **Note:** Auto-tracking is simpler and works in more scenarios (email, SMS, etc).
173
+
174
+ </details>
175
+
176
+ ---
177
+
178
+ ## API Reference
179
+
180
+ ### Essential Functions
181
+
182
+ #### `new AttentionMarketClient(config)`
183
+ Initialize the SDK with your API key and agent ID
184
+
185
+ ```typescript
186
+ const client = new AttentionMarketClient({
187
+ apiKey: process.env.ATTENTIONMARKET_API_KEY,
188
+ agentId: 'your_agent_id'
189
+ });
190
+ ```
191
+
192
+ #### `client.decideFromContext(params)`
193
+ Get a contextually relevant ad based on user's message
194
+
195
+ ```typescript
196
+ const ad = await client.decideFromContext({
197
+ userMessage: "I need car insurance"
198
+ });
199
+ // Returns: { creative, click_url, tracking_url, tracking_token, ... }
200
+ ```
201
+
202
+ #### `ad.click_url` ⭐ NEW: Auto-tracking
203
+ All ad URLs now track clicks automatically via server-side redirects
204
+
205
+ ```typescript
206
+ const ad = await client.decideFromContext({ userMessage });
207
+
208
+ // Just share this URL - clicks track automatically!
209
+ const link = ad.click_url;
210
+
211
+ // When user clicks:
212
+ // 1. We track the click
213
+ // 2. User is redirected to advertiser
214
+ // 3. You get paid
215
+ ```
216
+
217
+ **No manual tracking code needed.** Works in chat apps, emails, SMS, anywhere.
218
+
219
+ #### `client.track(event)` (Optional)
220
+ Track impressions or custom events
221
+
222
+ ```typescript
223
+ await client.track({
224
+ agent_id: 'your_agent_id',
225
+ event_type: 'ad_impression',
226
+ metadata: {
227
+ decision_id: ad.offer_id,
228
+ surface: 'chat'
229
+ }
230
+ });
231
+ ```
232
+
233
+ ### Testing
234
+
235
+ #### `MockAttentionMarketClient`
236
+ Mock client for testing without API calls
237
+
238
+ ```typescript
239
+ import { MockAttentionMarketClient } from '@the_ro_show/agent-ads-sdk';
240
+
241
+ const client = new MockAttentionMarketClient({
242
+ fillRate: 1.0, // Always return ads
243
+ latencyMs: 100, // Simulate API latency
244
+ verbose: true // Log activity
245
+ });
246
+ ```
247
+
248
+ ### Utilities
249
+
250
+ #### `escapeHTML(text)` & `sanitizeURL(url)`
251
+ Sanitize ad content before rendering in HTML
252
+
253
+ ```typescript
254
+ import { escapeHTML, sanitizeURL } from '@the_ro_show/agent-ads-sdk';
255
+
256
+ const safeTitle = escapeHTML(ad.creative.title);
257
+ const safeURL = sanitizeURL(ad.click_url);
258
+ ```
259
+
260
+ ---
261
+
262
+ ## Advanced Features
263
+
264
+ <details>
265
+ <summary><strong>Click to view: Complete example, testing, security, and advanced APIs</strong></summary>
266
+
267
+ <br>
268
+
269
+ ### Complete Example
65
270
 
66
271
  Full integration including ad retrieval, display, and click tracking:
67
272
 
@@ -80,7 +285,7 @@ async function handleUserMessage(userMessage: string) {
80
285
  return null; // No ads available
81
286
  }
82
287
 
83
- // Display ad (you can customize this)
288
+ // Display ad (customize as needed)
84
289
  const displayMessage = `\n[Sponsored] ${ad.disclosure.sponsor_name}\n${ad.creative.title}\n${ad.creative.body}\n${ad.creative.cta}\n`;
85
290
  console.log(displayMessage);
86
291
 
@@ -92,7 +297,7 @@ async function handleUserMessage(userMessage: string) {
92
297
  unit_id: ad.offer_id,
93
298
  tracking_token: ad.tracking_token,
94
299
  href: ad.click_url,
95
- click_context: displayMessage // What was actually shown to user
300
+ click_context: displayMessage // What was actually shown
96
301
  });
97
302
 
98
303
  return ad;
@@ -101,83 +306,97 @@ async function handleUserMessage(userMessage: string) {
101
306
 
102
307
  ---
103
308
 
104
- ## API Reference
105
-
106
- ### Primary API
309
+ ### Testing
107
310
 
108
- #### `decideFromContext(params)` → `Promise <OfferResponse | null>`
311
+ #### `MockAttentionMarketClient`
109
312
 
110
- Pass a user message and optionally conversation history. Returns a matching ad or null if no fill.
313
+ Mock client for testing without API calls. Simulates latency and fill rate behavior.
111
314
 
112
315
  ```typescript
113
- const ad = await client.decideFromContext({
114
- userMessage: "I need help with estate planning",
115
- conversationHistory: ["My father passed away recently"], // Optional
116
- context: { geo: { city: 'NYC', country: 'US' } } // Optional
117
- });
118
- ```
316
+ import { MockAttentionMarketClient } from '@the_ro_show/agent-ads-sdk';
119
317
 
120
- Returns ad with:
121
- - `creative.title` - Ad headline
122
- - `creative.body` - Ad description
123
- - `creative.cta` - Call to action
124
- - `click_url` - URL to open on click
125
- - `tracking_token` - Required for revenue tracking
126
- - `disclosure` - Sponsor information
318
+ const client = new MockAttentionMarketClient({
319
+ fillRate: 1.0, // Always return ads (0.0 = never, 0.5 = 50%)
320
+ latencyMs: 100, // Simulate API latency
321
+ verbose: true // Log activity
322
+ });
127
323
 
128
- ### Revenue Tracking
324
+ // Works exactly like the real client
325
+ const ad = await client.decideFromContext({ userMessage: "test" });
326
+ ```
129
327
 
130
- #### `trackClick(params)` → `Promise<void>`
328
+ ---
131
329
 
132
- Records user clicks for revenue attribution. Call this when a user clicks an ad. Handles deduplication and retries automatically.
330
+ ### Using Test vs Live Keys
133
331
 
134
- **Required:** `click_context` - The actual message shown to the user. This helps optimize ad creative based on what converts.
332
+ **Test Environment:**
333
+ ```typescript
334
+ const client = new AttentionMarketClient({
335
+ apiKey: process.env.ATTENTIONMARKET_TEST_KEY // am_test_...
336
+ });
337
+ ```
135
338
 
339
+ **Production Environment:**
136
340
  ```typescript
137
- await client.trackClick({
138
- agent_id: 'your_agent_id',
139
- request_id: ad.request_id,
140
- decision_id: ad.offer_id,
141
- unit_id: ad.offer_id,
142
- tracking_token: ad.tracking_token,
143
- href: ad.click_url,
144
- click_context: "The message shown to user that they clicked"
341
+ const client = new AttentionMarketClient({
342
+ apiKey: process.env.ATTENTIONMARKET_API_KEY // am_live_...
145
343
  });
146
344
  ```
147
345
 
148
- ### Testing
346
+ ---
149
347
 
150
- #### `MockAttentionMarketClient`
348
+ ### Security
151
349
 
152
- Mock client for testing without API calls. Simulates latency and fill rate behavior.
350
+ #### Server-Side Only
153
351
 
154
- ```typescript
155
- import { MockAttentionMarketClient } from '@the_ro_show/agent-ads-sdk';
352
+ **IMPORTANT:** This SDK must run server-side. Never expose your API key in client-side code.
156
353
 
157
- const client = new MockAttentionMarketClient({
158
- fillRate: 1.0, // Always return ads (0.0 = never, 0.5 = 50% of time)
159
- latencyMs: 100, // Simulate API latency
160
- verbose: true // Log what's happening
161
- });
354
+ **✅ Supported:**
355
+ - Node.js servers
356
+ - Serverless functions (AWS Lambda, Vercel, Cloudflare Workers)
357
+ - Server-side rendering (Next.js, Remix)
162
358
 
163
- // Works exactly like the real client
164
- const ad = await client.decideFromContext({ userMessage: "test" });
359
+ **❌ Not supported:**
360
+ - Browser JavaScript
361
+ - Client-side React/Vue/Angular
362
+ - Mobile apps
363
+
364
+ #### API Key Management
365
+
366
+ Store your API key in environment variables:
367
+
368
+ ```bash
369
+ export ATTENTIONMARKET_API_KEY=am_live_...
165
370
  ```
166
371
 
167
- ---
372
+ Never commit API keys to version control. Add to `.gitignore`:
168
373
 
169
- ## Advanced Features
374
+ ```
375
+ .env
376
+ .env.local
377
+ ```
170
378
 
171
- <details>
172
- <summary><strong>Click to view advanced APIs (most developers don't need these)</strong></summary>
379
+ #### Sanitize Ad Content
173
380
 
174
- <br>
381
+ Ad content comes from third-party advertisers. Always sanitize before rendering in HTML:
175
382
 
176
- The simple `decideFromContext()` API handles everything for 90% of use cases. But if you need more control:
383
+ ```typescript
384
+ import { escapeHTML, sanitizeURL } from '@the_ro_show/agent-ads-sdk';
385
+
386
+ const safeTitle = escapeHTML(ad.creative.title);
387
+ const safeURL = sanitizeURL(ad.click_url);
388
+
389
+ if (safeURL) {
390
+ element.innerHTML = `<a href="${safeURL}">${safeTitle}</a>`;
391
+ }
392
+ ```
393
+
394
+ ---
177
395
 
178
396
  ### Manual Category Targeting
179
397
 
180
398
  #### `decide()` - Specify exact categories
399
+
181
400
  When you know the exact category, use manual taxonomy matching for deterministic results.
182
401
 
183
402
  ```typescript
@@ -198,8 +417,9 @@ See [TAXONOMY_SYSTEM.md](./TAXONOMY_SYSTEM.md) for all categories.
198
417
 
199
418
  ### 🌐 Intenture Network APIs (Agent-to-Agent)
200
419
 
201
- #### `requestOffer()` - Intent-key based matching for high confidence scenarios
202
- When you KNOW what the user wants (they said "order coffee" or "book lawyer"), use intent-keys like `coffee.purchase.delivery` for deterministic matching. Enables agent-to-agent coordination and revenue sharing.
420
+ #### `requestOffer()` - Intent-key based matching
421
+
422
+ When you KNOW what the user wants (they said "order coffee" or "book lawyer"), use intent-keys like `coffee.purchase.delivery` for deterministic matching.
203
423
 
204
424
  ```typescript
205
425
  const offer = await client.requestOffer({
@@ -209,8 +429,9 @@ const offer = await client.requestOffer({
209
429
  });
210
430
  ```
211
431
 
212
- #### `requestOfferFromContext()` - Semantic discovery for fuzzy intents
213
- When you're NOT sure what they need (they said "I'm so tired"), pass the conversation and let semantic search find relevant offers. Auto-limits history to last 5 messages.
432
+ #### `requestOfferFromContext()` - Semantic discovery
433
+
434
+ When you're NOT sure what they need (they said "I'm so tired"), pass the conversation and let semantic search find relevant offers.
214
435
 
215
436
  ```typescript
216
437
  const offer = await client.requestOfferFromContext({
@@ -221,8 +442,9 @@ const offer = await client.requestOfferFromContext({
221
442
  });
222
443
  ```
223
444
 
224
- #### Revenue Share (Preview) - Track referrals between agents
225
- If another agent sends users to you, include their agent_id to split revenue (0-50%). Currently in preview mode (logs only) - payouts activate Q2 2026. Think affiliate marketing for AI agents.
445
+ #### Revenue Share (Preview)
446
+
447
+ If another agent sends users to you, include their agent_id to split revenue (0-50%). Currently in preview mode - payouts activate Q2 2026.
226
448
 
227
449
  ```typescript
228
450
  const offer = await client.requestOffer({
@@ -237,8 +459,9 @@ const offer = await client.requestOffer({
237
459
 
238
460
  ### 🧠 Intent Detection
239
461
 
240
- #### `detectIntent()` - Auto-detect where users are in their journey
241
- Analyzes queries to determine if they're researching ("what is X?"), comparing ("X vs Y"), getting quotes ("how much?"), or ready to buy ("I want X"). Returns 'research', 'compare', 'quote', 'apply', 'support', or 'other'.
462
+ #### `detectIntent()` - Auto-detect user journey stage
463
+
464
+ Analyzes queries to determine if they're researching, comparing, getting quotes, or ready to buy.
242
465
 
243
466
  ```typescript
244
467
  detectIntent("What is car insurance?") // → 'research'
@@ -248,7 +471,6 @@ detectIntent("I want to buy car insurance") // → 'apply'
248
471
  ```
249
472
 
250
473
  #### `buildTaxonomy()` - Type-safe taxonomy builder
251
- Constructs valid taxonomies like "insurance.auto.full_coverage.quote" with validation. Pass vertical, category, subcategory, and intent - it handles the formatting and catches errors.
252
474
 
253
475
  ```typescript
254
476
  const taxonomy = buildTaxonomy('insurance', 'auto', 'full_coverage', 'quote');
@@ -256,7 +478,6 @@ const taxonomy = buildTaxonomy('insurance', 'auto', 'full_coverage', 'quote');
256
478
  ```
257
479
 
258
480
  #### `suggestTaxonomies()` - Smart taxonomy recommendations
259
- Pass a user query and get back 3-5 relevant taxonomy suggestions ranked by relevance. Great for when you're not sure which category to use.
260
481
 
261
482
  ```typescript
262
483
  const suggestions = suggestTaxonomies("I need a lawyer for divorce");
@@ -265,7 +486,7 @@ const suggestions = suggestTaxonomies("I need a lawyer for divorce");
265
486
 
266
487
  #### Taxonomy Utilities
267
488
  - `isValidTaxonomy(taxonomy)` - Validate taxonomy format
268
- - `parseTaxonomy(taxonomy)` - Parse taxonomy into components
489
+ - `parseTaxonomy(taxonomy)` - Parse into components
269
490
  - `getBaseTaxonomy(taxonomy)` - Get taxonomy without intent
270
491
  - `matchesTaxonomy(tax1, tax2)` - Check if taxonomies match
271
492
  - `getVertical(taxonomy)` - Extract industry vertical
@@ -275,7 +496,6 @@ const suggestions = suggestTaxonomies("I need a lawyer for divorce");
275
496
  ### 🎨 Response Formatting
276
497
 
277
498
  #### `formatNatural()` - Convert ads into natural conversation
278
- Transforms sponsored suggestions into conversational responses that feel native to your agent. Handles disclosure labels, CTA integration, and tone matching automatically.
279
499
 
280
500
  ```typescript
281
501
  const formatted = formatNatural(ad, {
@@ -286,15 +506,13 @@ const formatted = formatNatural(ad, {
286
506
  ```
287
507
 
288
508
  #### `formatInlineMention()` - Subtle in-message placement
289
- Weaves ads into your agent's response as natural mentions. Like "Btw, Lemonade offers great rates for new drivers [Sponsored]". Less intrusive than separate ad blocks.
290
509
 
291
510
  ```typescript
292
511
  const mention = formatInlineMention(ad);
293
512
  // → "Btw, Lemonade offers 20% off for new drivers [Sponsored]"
294
513
  ```
295
514
 
296
- #### `validateAdFits()` - Check if ad matches conversation context
297
- Before showing an ad, validate it fits the current conversation. Checks relevance, tone, and user intent to avoid jarring placements.
515
+ #### `validateAdFits()` - Check if ad matches context
298
516
 
299
517
  ```typescript
300
518
  const fits = validateAdFits(ad, conversationContext);
@@ -308,7 +526,6 @@ if (fits) {
308
526
  ### 📊 Event Tracking
309
527
 
310
528
  #### `trackImpression()` - Log when users see an ad
311
- Record that an ad was shown to a user. Required for billing and analytics. Include the unit_id and tracking token from the ad response.
312
529
 
313
530
  ```typescript
314
531
  await client.trackImpression({
@@ -320,29 +537,11 @@ await client.trackImpression({
320
537
  });
321
538
  ```
322
539
 
323
- #### `trackClick()` - Log when users click an ad
324
- Record when users interact with ads. This is how you get paid. Automatically deduplicates to prevent double-charging.
325
-
326
- **Required:** `click_context` - The actual message shown to the user that they clicked.
327
-
328
- ```typescript
329
- await client.trackClick({
330
- agent_id: 'your_agent_id',
331
- request_id: decision.request_id,
332
- decision_id: decision.decision_id,
333
- unit_id: ad.unit_id,
334
- tracking_token: ad.tracking.token,
335
- href: ad.suggestion.action_url,
336
- click_context: 'The message shown to user when they clicked'
337
- });
338
- ```
339
-
340
540
  ---
341
541
 
342
542
  ### 🛠️ Helper Utilities
343
543
 
344
- #### `createOpportunity()` - Build opportunity objects easily
345
- Helper to construct the opportunity payload for decide() calls. Handles defaults and validation.
544
+ #### `createOpportunity()` - Build opportunity objects
346
545
 
347
546
  ```typescript
348
547
  const opportunity = createOpportunity({
@@ -352,46 +551,27 @@ const opportunity = createOpportunity({
352
551
  ```
353
552
 
354
553
  #### Security Helpers
355
- - `escapeHTML(text)` - Sanitize ad content before rendering to prevent XSS attacks
356
- - `sanitizeURL(url)` - Validate and sanitize URLs before opening
357
-
358
- **Always sanitize ad content before displaying in web contexts!**
554
+ - `escapeHTML(text)` - Sanitize ad content before rendering
555
+ - `sanitizeURL(url)` - Validate and sanitize URLs
359
556
 
360
557
  #### ID Generation
361
- - `generateUUID()` - Create unique request IDs (crypto-secure randomness)
362
- - `generateTimestamp()` - Generate timestamps that match our API requirements
363
-
364
- ---
365
-
366
- ### 🧪 Testing
367
-
368
- #### `MockAttentionMarketClient` - Test without real API calls
369
- Drop-in replacement that returns fake ads for testing. Simulates latency, errors, and no-fill scenarios. Perfect for unit tests and local development.
370
-
371
- ```typescript
372
- import { MockAttentionMarketClient } from '@the_ro_show/agent-ads-sdk';
373
-
374
- const client = new MockAttentionMarketClient({
375
- fillRate: 1.0, // Always return ads
376
- latencyMs: 100, // Simulate API latency
377
- verbose: true // Log activity
378
- });
379
-
380
- // Works exactly like real client, but returns mock data
381
- const decision = await client.decide(request);
382
- ```
558
+ - `generateUUID()` - Create unique request IDs
559
+ - `generateTimestamp()` - Generate API-compatible timestamps
383
560
 
384
561
  ---
385
562
 
386
563
  ### ⚠️ Error Handling
387
564
 
388
- #### `APIRequestError` - API returned an error response
389
- Thrown when the backend rejects your request (invalid key, bad params, etc). Includes detailed error message and request_id for debugging.
565
+ #### `APIRequestError` - API returned an error
566
+
567
+ Thrown when the backend rejects your request. Includes detailed error message and request_id.
390
568
 
391
569
  #### `NetworkError` - Connection failed
392
- Network issues, DNS failures, or backend unavailable. Includes automatic retry logic for transient failures.
570
+
571
+ Network issues or backend unavailable. Includes automatic retry logic.
393
572
 
394
573
  #### `TimeoutError` - Request exceeded timeout
574
+
395
575
  Request took too long (default 5s). Configure with `timeoutMs` in constructor.
396
576
 
397
577
  ```typescript
@@ -412,190 +592,61 @@ try {
412
592
 
413
593
  ---
414
594
 
415
- ## Using Test vs Live Keys
595
+ ## Monetize Your AI Agent
416
596
 
417
- ### Test Environment
418
- Use your test key for development:
419
- ```typescript
420
- const client = new AttentionMarketClient({
421
- apiKey: process.env.ATTENTIONMARKET_TEST_KEY // am_test_...
422
- });
423
- ```
424
-
425
- ### Production Environment
426
- Use your live key for production:
427
- ```typescript
428
- const client = new AttentionMarketClient({
429
- apiKey: process.env.ATTENTIONMARKET_API_KEY // am_live_...
430
- });
431
- ```
432
-
433
- ---
597
+ Stop giving away your AI agent for free. Start earning revenue from every conversation.
434
598
 
435
- ## Sanitizing Ad Content
599
+ **Traditional monetization (hard):**
600
+ - Paywalls → 95% of users leave before paying
601
+ - Subscriptions → $10-20/month per user (if they convert)
602
+ - Usage limits → Frustrates users, kills growth
436
603
 
437
- Ad creative comes from third-party advertisers. Always sanitize before rendering in HTML contexts:
604
+ **AttentionMarket (easy):**
605
+ - **Free for users** → No friction, keep all your users
606
+ - **Earn per click** → $5-$150 per click on high-value ads (insurance, legal, finance)
607
+ - **70% revenue share** → You keep most of the earnings
608
+ - **Contextual ads** → Only show relevant ads when users have commercial intent
438
609
 
439
- ```typescript
440
- import { escapeHTML, sanitizeURL } from '@the_ro_show/agent-ads-sdk';
610
+ **Example earnings:**
611
+ - 1,000 users/month × 5% click rate × $50 avg = **$1,750/month** (you keep $1,225)
612
+ - 10,000 users/month × 3% click rate × $75 avg = **$22,500/month** (you keep $15,750)
441
613
 
442
- const safeTitle = escapeHTML(ad.creative.title);
443
- const safeURL = sanitizeURL(ad.click_url);
444
-
445
- if (safeURL) {
446
- element.innerHTML = `<a href="${safeURL}">${safeTitle}</a>`;
447
- }
448
- ```
449
-
450
- <details>
451
- <summary><strong>Security considerations</strong></summary>
452
-
453
- <br>
454
-
455
- ### Server-Side Only
456
-
457
- This SDK must run server-side. Do not use in browsers or mobile apps where the API key would be exposed.
458
-
459
- **Supported:**
460
- - Node.js servers
461
- - Serverless functions (AWS Lambda, Vercel, Cloudflare Workers)
462
- - Server-side rendering (Next.js, Remix)
463
-
464
- **Not supported:**
465
- - Browser JavaScript
466
- - Client-side React/Vue/Angular
467
- - Mobile apps
468
-
469
- ### Additional Guidelines
470
-
471
- See [SECURITY.md](./SECURITY.md) for complete security best practices.
472
-
473
- </details>
614
+ **Integration time:** 10 minutes. Four functions. Production-ready.
474
615
 
475
616
  ---
476
617
 
477
618
  ## Examples
478
619
 
479
- **Minimal integrations** (< 80 lines):
480
- - [Claude Tool Use](./examples/claude-tool-use-minimal.ts)
481
- - [OpenAI Function Calling](./examples/openai-function-calling-minimal.ts)
482
- - [Google Gemini](./examples/gemini-function-calling-minimal.ts)
620
+ **Basic integration** (~50 lines):
621
+ - [basic-example.ts](./examples/basic-example.ts) - Get ads and track clicks
622
+
623
+ **Chatbot integration** (~45 lines):
624
+ - [chatbot-example.ts](./examples/chatbot-example.ts) - Using `tracking_url` for shared links
483
625
 
484
- **Full integrations** (production-ready):
485
- - [Claude Complete](./examples/claude-tool-use-full.ts)
486
- - [OpenAI Complete](./examples/openai-function-calling-full.ts)
487
- - [Safe Web Rendering](./examples/safe-web-rendering.ts)
626
+ **Testing** (~320 lines):
627
+ - [test-with-mocks.ts](./examples/test-with-mocks.ts) - Test without API calls
488
628
 
489
629
  Run any example:
490
630
  ```bash
491
- npx tsx examples/claude-tool-use-minimal.ts
631
+ npx tsx examples/basic-example.ts
492
632
  ```
493
633
 
494
634
  ---
495
635
 
496
- ## Documentation
497
-
498
- - **[Simple Integration Guide](./SIMPLE_INTEGRATION_GUIDE.md)** - Step-by-step for beginners
499
- - **[Taxonomy System](./TAXONOMY_SYSTEM.md)** - Complete taxonomy reference
500
- - **[Migration Guide](./TAXONOMY_MIGRATION_GUIDE.md)** - Upgrading from older versions
501
- - **[Security Guide](./SECURITY.md)** - Security best practices
502
- - **[Advertiser Guide](./ADVERTISER_ONBOARDING_GUIDE.md)** - For advertisers
503
-
504
- ---
505
-
506
- ## Features
507
-
508
- - ✅ **Hierarchical matching** - Advertisers target broadly, agents match specifically
509
- - ✅ **Auto-intent detection** - Automatically detect research vs quote vs apply
510
- - ✅ **50+ high-value taxonomies** - Insurance, legal, finance, B2B SaaS, and more
511
- - ✅ **TypeScript support** - Full type definitions included
512
- - ✅ **Automatic retries** - Exponential backoff for failed requests
513
- - ✅ **Mock client** - Test without API calls
514
- - ✅ **Security helpers** - XSS protection, URL sanitization
515
- - ✅ **Zero dependencies** - No external runtime dependencies
516
-
517
- ---
518
-
519
- ## Pricing
520
-
521
- **Free to use.** You earn money when users click ads:
522
-
523
- - **Insurance:** $20-54 per click
524
- - **Legal:** $50-150 per click
525
- - **Financial:** $15-50 per click
526
- - **B2B SaaS:** $10-100 per click
527
- - **Home Services:** $5-30 per click
528
-
529
- **You keep 70% of revenue.** Paid monthly via Stripe.
530
-
531
- ---
532
-
533
- ## Requirements
534
-
535
- - Node.js 18 or higher
536
- - TypeScript 5.3+ (for development)
537
-
538
- ---
539
-
540
- ## Available Ad Categories
541
-
542
- The network currently has active campaigns in these verticals:
543
-
544
- | Category | CPC Range | Common Intents |
545
- |----------|-----------|----------------|
546
- | Legal | $50-150 | Divorce, estate planning, personal injury, immigration |
547
- | Insurance | $20-54 | Auto, home, life, health |
548
- | Financial | $15-50 | Loans, credit cards, mortgages, investing |
549
- | B2B SaaS | $10-100 | CRM, project management, ecommerce tools |
550
- | Home Services | $5-30 | Moving, cleaning, repairs |
551
- | Travel | $3-20 | Flights, hotels, packages |
552
- | Ecommerce | $2-15 | Retail, subscriptions |
553
- | Education | $10-50 | Courses, certifications |
554
-
555
- The semantic matching API automatically maps user queries to available inventory. If your use case isn't listed, contact support@attentionmarket.com to discuss adding new categories.
556
-
557
- <details>
558
- <summary><strong>View detailed taxonomy reference (advanced users only)</strong></summary>
559
-
560
- <br>
636
+ ## For AI Agents
561
637
 
562
- **Full taxonomy list:** [TAXONOMY_SYSTEM.md](./TAXONOMY_SYSTEM.md)
563
-
564
- Example taxonomies for advanced `decide()` API:
565
- ```typescript
566
- // Insurance
567
- 'insurance.auto.full_coverage.quote'
568
- 'insurance.auto.liability.compare'
569
- 'insurance.home.standard.quote'
570
- 'insurance.life.term.compare'
638
+ **AI agents:** Read **[AI_AGENT_SETUP_GUIDE.md](./AI_AGENT_SETUP_GUIDE.md)** for complete step-by-step integration instructions.
571
639
 
572
- // Legal
573
- 'legal.personal_injury.accident.consultation'
574
- 'legal.family.divorce.consultation'
575
- 'legal.estate_planning.will.consultation'
640
+ **Developers:** Give this document to your AI agent (Claude, ChatGPT, etc.) and say:
641
+ > "Please integrate the AttentionMarket SDK following the AI_AGENT_SETUP_GUIDE.md"
576
642
 
577
- // Financial
578
- 'financial.loans.personal.quote'
579
- 'financial.credit_cards.rewards.compare'
580
- 'financial.investing.brokerage.trial'
581
-
582
- // B2B SaaS
583
- 'business.saas.crm.trial'
584
- 'business.saas.project_management.trial'
585
-
586
- // Home Services
587
- 'home_services.moving.local.quote'
588
- 'home_services.plumbing.emergency.quote'
589
- ```
590
-
591
- </details>
643
+ The agent will handle: getting credentials, installing SDK, writing integration code, testing, and deployment setup.
592
644
 
593
645
  ---
594
646
 
595
647
  ## Support
596
648
 
597
649
  - **Issues:** [GitHub Issues](https://github.com/rtrivedi/agent-ads-sdk/issues)
598
- - **Docs:** [SIMPLE_INTEGRATION_GUIDE.md](./SIMPLE_INTEGRATION_GUIDE.md)
599
650
  - **Email:** support@attentionmarket.com
600
651
 
601
652
  ---
@@ -603,9 +654,3 @@ Example taxonomies for advanced `decide()` API:
603
654
  ## License
604
655
 
605
656
  MIT
606
-
607
- ---
608
-
609
- ## Changelog
610
-
611
- See [CHANGELOG.md](./CHANGELOG.md) for detailed version history.