@the_ro_show/agent-ads-sdk 0.15.1 → 0.16.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 +65 -26
- package/dist/index.d.mts +1 -48
- package/dist/index.d.ts +1 -48
- package/dist/index.js +0 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +0 -72
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,12 +5,24 @@
|
|
|
5
5
|
|
|
6
6
|
Monetize your AI application with contextual advertising. AttentionMarket matches user intent with relevant sponsored content, enabling you to generate revenue from every conversation.
|
|
7
7
|
|
|
8
|
+
## 📚 Documentation
|
|
9
|
+
|
|
10
|
+
**Full documentation with REST API reference, mobile integration guides, and examples:**
|
|
11
|
+
### → [https://rtrivedi.github.io/agent-ads-sdk/](https://rtrivedi.github.io/agent-ads-sdk/)
|
|
12
|
+
|
|
8
13
|
## Installation
|
|
9
14
|
|
|
10
15
|
```bash
|
|
11
16
|
npm install @the_ro_show/agent-ads-sdk
|
|
12
17
|
```
|
|
13
18
|
|
|
19
|
+
### For Non-Node.js Platforms
|
|
20
|
+
|
|
21
|
+
See our [REST API Reference](https://rtrivedi.github.io/agent-ads-sdk/docs/api-reference) for direct HTTP integration in any language:
|
|
22
|
+
- Python, Go, Ruby, PHP
|
|
23
|
+
- iOS/Swift, Android/Kotlin
|
|
24
|
+
- Direct cURL/HTTP
|
|
25
|
+
|
|
14
26
|
## Quick Start
|
|
15
27
|
|
|
16
28
|
```typescript
|
|
@@ -85,16 +97,18 @@ const ad = await client.decideFromContext({
|
|
|
85
97
|
});
|
|
86
98
|
```
|
|
87
99
|
|
|
88
|
-
### Performance Impact
|
|
100
|
+
### Expected Performance Impact
|
|
89
101
|
|
|
90
|
-
Smart context
|
|
102
|
+
Smart context is projected to improve key metrics:
|
|
91
103
|
|
|
92
|
-
| Feature | CTR Improvement | Revenue Impact |
|
|
93
|
-
|
|
94
|
-
| Intent Detection | +
|
|
95
|
-
| Interest Matching | +
|
|
96
|
-
| Session Tracking | +
|
|
97
|
-
| Combined | **+
|
|
104
|
+
| Feature | Expected CTR Improvement | Expected Revenue Impact |
|
|
105
|
+
|---------|-------------------------|------------------------|
|
|
106
|
+
| Intent Detection | +30-40% | +35-45% |
|
|
107
|
+
| Interest Matching | +20-30% | +25-35% |
|
|
108
|
+
| Session Tracking | +10-20% | +15-25% |
|
|
109
|
+
| Combined | **+50-70%** | **+60-80%** |
|
|
110
|
+
|
|
111
|
+
*Note: These are projected improvements based on early testing. Actual results may vary.*
|
|
98
112
|
|
|
99
113
|
### Best Practices
|
|
100
114
|
|
|
@@ -162,8 +176,9 @@ const client = new AttentionMarketClient({
|
|
|
162
176
|
|
|
163
177
|
```typescript
|
|
164
178
|
const client = new AttentionMarketClient({
|
|
165
|
-
apiKey: 'am_live_YOUR_KEY', // Required
|
|
179
|
+
apiKey: 'am_live_YOUR_KEY', // Required: Your AttentionMarket API key
|
|
166
180
|
agentId: 'agt_YOUR_AGENT_ID', // Required for decideFromContext()
|
|
181
|
+
supabaseAnonKey: 'YOUR_ANON_KEY', // Required: Get from dashboard
|
|
167
182
|
// baseUrl defaults to production Supabase endpoint
|
|
168
183
|
// Only override if self-hosting or using different environment
|
|
169
184
|
timeoutMs: 4000, // Optional: request timeout in milliseconds
|
|
@@ -171,6 +186,8 @@ const client = new AttentionMarketClient({
|
|
|
171
186
|
});
|
|
172
187
|
```
|
|
173
188
|
|
|
189
|
+
**Note:** You need both `apiKey` (AttentionMarket) and `supabaseAnonKey` (infrastructure) for authentication. Get both from your [developer dashboard](https://api.attentionmarket.ai).
|
|
190
|
+
|
|
174
191
|
## Core Concepts
|
|
175
192
|
|
|
176
193
|
### Placements
|
|
@@ -528,28 +545,20 @@ const ad = await client.decideFromContext({
|
|
|
528
545
|
|
|
529
546
|
### Click Tracking
|
|
530
547
|
|
|
531
|
-
Clicks are automatically tracked when users visit `click_url`.
|
|
548
|
+
Clicks are automatically and securely tracked when users visit the `click_url`.
|
|
532
549
|
|
|
533
|
-
|
|
534
|
-
await client.trackClick({
|
|
535
|
-
agent_id: 'agt_YOUR_AGENT_ID',
|
|
536
|
-
request_id: ad.request_id,
|
|
537
|
-
decision_id: ad.decision_id,
|
|
538
|
-
unit_id: ad._ad.unit_id,
|
|
539
|
-
tracking_token: ad.tracking_token,
|
|
540
|
-
href: ad.click_url,
|
|
541
|
-
click_context: "User clicked 'Get a Quote' button"
|
|
542
|
-
});
|
|
543
|
-
```
|
|
544
|
-
|
|
545
|
-
Simplified tracking from ad object:
|
|
550
|
+
**Important:** Always use the provided `click_url` or `tracking_url` for click tracking. These URLs contain HMAC-signed tokens that prevent click fraud and ensure accurate attribution.
|
|
546
551
|
|
|
547
552
|
```typescript
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
553
|
+
// When user clicks the ad, redirect them to:
|
|
554
|
+
window.location.href = ad.click_url;
|
|
555
|
+
|
|
556
|
+
// Or in a chat/messaging context, share:
|
|
557
|
+
const shareableLink = ad.tracking_url;
|
|
551
558
|
```
|
|
552
559
|
|
|
560
|
+
Manual click tracking has been removed for security reasons. All clicks must go through the redirect URLs to ensure fraud prevention and accurate tracking.
|
|
561
|
+
|
|
553
562
|
### Conversion Tracking
|
|
554
563
|
|
|
555
564
|
Track conversions (purchases, signups, etc.) to improve advertiser ROI and your quality score:
|
|
@@ -625,6 +634,36 @@ Use test API keys (`am_test_...`) for development and testing. Test keys:
|
|
|
625
634
|
|
|
626
635
|
Switch to live keys (`am_live_...`) when deploying to production.
|
|
627
636
|
|
|
637
|
+
## 🌍 REST API for Mobile & Other Platforms
|
|
638
|
+
|
|
639
|
+
For non-Node.js platforms, use our REST API directly:
|
|
640
|
+
|
|
641
|
+
### iOS/Swift Example
|
|
642
|
+
```swift
|
|
643
|
+
// See full guide: https://rtrivedi.github.io/agent-ads-sdk/docs/mobile-integration
|
|
644
|
+
let url = URL(string: "https://peruwnbrqkvmrldhpoom.supabase.co/functions/v1/decide")!
|
|
645
|
+
var request = URLRequest(url: url)
|
|
646
|
+
request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")
|
|
647
|
+
request.setValue(supabaseAnonKey, forHTTPHeaderField: "apikey")
|
|
648
|
+
// ... see docs for complete example
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
### Python Example
|
|
652
|
+
```python
|
|
653
|
+
# See full guide: https://rtrivedi.github.io/agent-ads-sdk/docs/api-reference
|
|
654
|
+
import requests
|
|
655
|
+
response = requests.post(
|
|
656
|
+
"https://peruwnbrqkvmrldhpoom.supabase.co/functions/v1/decide",
|
|
657
|
+
headers={
|
|
658
|
+
"Authorization": f"Bearer {api_key}",
|
|
659
|
+
"apikey": supabase_anon_key
|
|
660
|
+
},
|
|
661
|
+
json={"user_message": "I need insurance"}
|
|
662
|
+
)
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
**📖 Full REST API Documentation:** [https://rtrivedi.github.io/agent-ads-sdk/docs/api-reference](https://rtrivedi.github.io/agent-ads-sdk/docs/api-reference)
|
|
666
|
+
|
|
628
667
|
## 🤖 Claude Code Integration
|
|
629
668
|
|
|
630
669
|
Building with Claude Code? We've created ready-to-use prompts for seamless integration.
|
package/dist/index.d.mts
CHANGED
|
@@ -773,24 +773,6 @@ interface CreateImpressionEventParams {
|
|
|
773
773
|
* @returns EventIngestRequest ready to pass to client.track()
|
|
774
774
|
*/
|
|
775
775
|
declare function createImpressionEvent(params: CreateImpressionEventParams): EventIngestRequest;
|
|
776
|
-
interface CreateClickEventParams {
|
|
777
|
-
agent_id: string;
|
|
778
|
-
request_id: string;
|
|
779
|
-
decision_id: string;
|
|
780
|
-
unit_id: string;
|
|
781
|
-
tracking_token: string;
|
|
782
|
-
href: string;
|
|
783
|
-
click_context: string;
|
|
784
|
-
occurred_at?: string;
|
|
785
|
-
metadata?: Record<string, unknown>;
|
|
786
|
-
}
|
|
787
|
-
/**
|
|
788
|
-
* Helper to create a click event payload.
|
|
789
|
-
*
|
|
790
|
-
* @param params - Event parameters (snake_case to match API)
|
|
791
|
-
* @returns EventIngestRequest ready to pass to client.track()
|
|
792
|
-
*/
|
|
793
|
-
declare function createClickEvent(params: CreateClickEventParams): EventIngestRequest;
|
|
794
776
|
/**
|
|
795
777
|
* Options for URL sanitization
|
|
796
778
|
*/
|
|
@@ -922,35 +904,6 @@ declare class AttentionMarketClient {
|
|
|
922
904
|
trackImpression(params: Omit<CreateImpressionEventParams, 'occurred_at'> & {
|
|
923
905
|
occurred_at?: string;
|
|
924
906
|
}): Promise<EventIngestResponse>;
|
|
925
|
-
/**
|
|
926
|
-
* Convenience method to track a click event.
|
|
927
|
-
* Creates a click event using createClickEvent() and calls track().
|
|
928
|
-
*/
|
|
929
|
-
trackClick(params: Omit<CreateClickEventParams, 'occurred_at'> & {
|
|
930
|
-
occurred_at?: string;
|
|
931
|
-
}): Promise<EventIngestResponse>;
|
|
932
|
-
/**
|
|
933
|
-
* Ultra-simple method to track a click from an ad returned by decideFromContext().
|
|
934
|
-
* Automatically extracts all required fields from the ad object.
|
|
935
|
-
*
|
|
936
|
-
* @param ad - The ad object returned by decideFromContext()
|
|
937
|
-
* @param options - Just click_context (what you showed the user)
|
|
938
|
-
*
|
|
939
|
-
* @example
|
|
940
|
-
* ```typescript
|
|
941
|
-
* const ad = await client.decideFromContext({ userMessage: "I need car insurance" });
|
|
942
|
-
* if (ad) {
|
|
943
|
-
* await client.trackClickFromAd(ad, {
|
|
944
|
-
* click_context: "Progressive: Get 20% off - Compare quotes"
|
|
945
|
-
* });
|
|
946
|
-
* }
|
|
947
|
-
* ```
|
|
948
|
-
*/
|
|
949
|
-
trackClickFromAd(ad: AdResponse, options: {
|
|
950
|
-
click_context: string;
|
|
951
|
-
metadata?: Record<string, unknown>;
|
|
952
|
-
occurred_at?: string;
|
|
953
|
-
}): Promise<EventIngestResponse>;
|
|
954
907
|
/**
|
|
955
908
|
* Send feedback on an ad's performance to earn conversion-validated bonuses.
|
|
956
909
|
*
|
|
@@ -1584,4 +1537,4 @@ declare function getVertical(taxonomy: string): string | null;
|
|
|
1584
1537
|
*/
|
|
1585
1538
|
declare function suggestTaxonomies(query: string): string[];
|
|
1586
1539
|
|
|
1587
|
-
export { type APIError, APIRequestError, type AdResponse, type AdScore, type AdUnit, type AgentSignupRequest, type AgentSignupResponse, AttentionMarketClient, AttentionMarketError, type Constraints, type Context, type
|
|
1540
|
+
export { type APIError, APIRequestError, type AdResponse, type AdScore, type AdUnit, type AgentSignupRequest, type AgentSignupResponse, AttentionMarketClient, AttentionMarketError, type Constraints, type Context, type CreateImpressionEventParams, type CreateOpportunityParams, type DecideFromContextRequest, type DecideRequest, type DecideResponse, type Disclosure, type EventIngestRequest, type EventIngestResponse, type EventType, type FormattedAd, type Intent, MockAttentionMarketClient, type MockClientConfig, type NaturalFormatOptions, NetworkError, type OfferResponse, type Opportunity, type ParsedTaxonomy, type Placement, type PlacementType, type PolicyResponse, type Privacy, type RequestOfferFromContextParams, type RequestOfferParams, type SDKConfig, type SanitizeURLOptions, type SponsoredSuggestion, type SponsoredTool, type TaxonomyIntent, TimeoutError, type ToolCall, type Tracking, buildTaxonomy, createImpressionEvent, createOpportunity, detectIntent, escapeHTML, formatInlineMention, formatNatural, generateTimestamp, generateUUID, getBaseTaxonomy, getVertical, isValidTaxonomy, matchesTaxonomy, parseTaxonomy, sanitizeURL, suggestTaxonomies, validateAdFits };
|
package/dist/index.d.ts
CHANGED
|
@@ -773,24 +773,6 @@ interface CreateImpressionEventParams {
|
|
|
773
773
|
* @returns EventIngestRequest ready to pass to client.track()
|
|
774
774
|
*/
|
|
775
775
|
declare function createImpressionEvent(params: CreateImpressionEventParams): EventIngestRequest;
|
|
776
|
-
interface CreateClickEventParams {
|
|
777
|
-
agent_id: string;
|
|
778
|
-
request_id: string;
|
|
779
|
-
decision_id: string;
|
|
780
|
-
unit_id: string;
|
|
781
|
-
tracking_token: string;
|
|
782
|
-
href: string;
|
|
783
|
-
click_context: string;
|
|
784
|
-
occurred_at?: string;
|
|
785
|
-
metadata?: Record<string, unknown>;
|
|
786
|
-
}
|
|
787
|
-
/**
|
|
788
|
-
* Helper to create a click event payload.
|
|
789
|
-
*
|
|
790
|
-
* @param params - Event parameters (snake_case to match API)
|
|
791
|
-
* @returns EventIngestRequest ready to pass to client.track()
|
|
792
|
-
*/
|
|
793
|
-
declare function createClickEvent(params: CreateClickEventParams): EventIngestRequest;
|
|
794
776
|
/**
|
|
795
777
|
* Options for URL sanitization
|
|
796
778
|
*/
|
|
@@ -922,35 +904,6 @@ declare class AttentionMarketClient {
|
|
|
922
904
|
trackImpression(params: Omit<CreateImpressionEventParams, 'occurred_at'> & {
|
|
923
905
|
occurred_at?: string;
|
|
924
906
|
}): Promise<EventIngestResponse>;
|
|
925
|
-
/**
|
|
926
|
-
* Convenience method to track a click event.
|
|
927
|
-
* Creates a click event using createClickEvent() and calls track().
|
|
928
|
-
*/
|
|
929
|
-
trackClick(params: Omit<CreateClickEventParams, 'occurred_at'> & {
|
|
930
|
-
occurred_at?: string;
|
|
931
|
-
}): Promise<EventIngestResponse>;
|
|
932
|
-
/**
|
|
933
|
-
* Ultra-simple method to track a click from an ad returned by decideFromContext().
|
|
934
|
-
* Automatically extracts all required fields from the ad object.
|
|
935
|
-
*
|
|
936
|
-
* @param ad - The ad object returned by decideFromContext()
|
|
937
|
-
* @param options - Just click_context (what you showed the user)
|
|
938
|
-
*
|
|
939
|
-
* @example
|
|
940
|
-
* ```typescript
|
|
941
|
-
* const ad = await client.decideFromContext({ userMessage: "I need car insurance" });
|
|
942
|
-
* if (ad) {
|
|
943
|
-
* await client.trackClickFromAd(ad, {
|
|
944
|
-
* click_context: "Progressive: Get 20% off - Compare quotes"
|
|
945
|
-
* });
|
|
946
|
-
* }
|
|
947
|
-
* ```
|
|
948
|
-
*/
|
|
949
|
-
trackClickFromAd(ad: AdResponse, options: {
|
|
950
|
-
click_context: string;
|
|
951
|
-
metadata?: Record<string, unknown>;
|
|
952
|
-
occurred_at?: string;
|
|
953
|
-
}): Promise<EventIngestResponse>;
|
|
954
907
|
/**
|
|
955
908
|
* Send feedback on an ad's performance to earn conversion-validated bonuses.
|
|
956
909
|
*
|
|
@@ -1584,4 +1537,4 @@ declare function getVertical(taxonomy: string): string | null;
|
|
|
1584
1537
|
*/
|
|
1585
1538
|
declare function suggestTaxonomies(query: string): string[];
|
|
1586
1539
|
|
|
1587
|
-
export { type APIError, APIRequestError, type AdResponse, type AdScore, type AdUnit, type AgentSignupRequest, type AgentSignupResponse, AttentionMarketClient, AttentionMarketError, type Constraints, type Context, type
|
|
1540
|
+
export { type APIError, APIRequestError, type AdResponse, type AdScore, type AdUnit, type AgentSignupRequest, type AgentSignupResponse, AttentionMarketClient, AttentionMarketError, type Constraints, type Context, type CreateImpressionEventParams, type CreateOpportunityParams, type DecideFromContextRequest, type DecideRequest, type DecideResponse, type Disclosure, type EventIngestRequest, type EventIngestResponse, type EventType, type FormattedAd, type Intent, MockAttentionMarketClient, type MockClientConfig, type NaturalFormatOptions, NetworkError, type OfferResponse, type Opportunity, type ParsedTaxonomy, type Placement, type PlacementType, type PolicyResponse, type Privacy, type RequestOfferFromContextParams, type RequestOfferParams, type SDKConfig, type SanitizeURLOptions, type SponsoredSuggestion, type SponsoredTool, type TaxonomyIntent, TimeoutError, type ToolCall, type Tracking, buildTaxonomy, createImpressionEvent, createOpportunity, detectIntent, escapeHTML, formatInlineMention, formatNatural, generateTimestamp, generateUUID, getBaseTaxonomy, getVertical, isValidTaxonomy, matchesTaxonomy, parseTaxonomy, sanitizeURL, suggestTaxonomies, validateAdFits };
|
package/dist/index.js
CHANGED
|
@@ -27,7 +27,6 @@ __export(index_exports, {
|
|
|
27
27
|
NetworkError: () => NetworkError,
|
|
28
28
|
TimeoutError: () => TimeoutError,
|
|
29
29
|
buildTaxonomy: () => buildTaxonomy,
|
|
30
|
-
createClickEvent: () => createClickEvent,
|
|
31
30
|
createImpressionEvent: () => createImpressionEvent,
|
|
32
31
|
createOpportunity: () => createOpportunity,
|
|
33
32
|
detectIntent: () => detectIntent,
|
|
@@ -247,31 +246,6 @@ function createImpressionEvent(params) {
|
|
|
247
246
|
}
|
|
248
247
|
return event;
|
|
249
248
|
}
|
|
250
|
-
function createClickEvent(params) {
|
|
251
|
-
const event = {
|
|
252
|
-
event_id: generateUUID(),
|
|
253
|
-
occurred_at: params.occurred_at ?? generateTimestamp(),
|
|
254
|
-
agent_id: params.agent_id,
|
|
255
|
-
request_id: params.request_id,
|
|
256
|
-
decision_id: params.decision_id,
|
|
257
|
-
unit_id: params.unit_id,
|
|
258
|
-
event_type: "click",
|
|
259
|
-
tracking_token: params.tracking_token
|
|
260
|
-
};
|
|
261
|
-
if (params.metadata !== void 0) {
|
|
262
|
-
event.metadata = {
|
|
263
|
-
...params.metadata,
|
|
264
|
-
href: params.href,
|
|
265
|
-
click_context: params.click_context
|
|
266
|
-
};
|
|
267
|
-
} else {
|
|
268
|
-
event.metadata = {
|
|
269
|
-
href: params.href,
|
|
270
|
-
click_context: params.click_context
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
return event;
|
|
274
|
-
}
|
|
275
249
|
var HTML_ESCAPES = {
|
|
276
250
|
"&": "&",
|
|
277
251
|
"<": "<",
|
|
@@ -897,52 +871,6 @@ var AttentionMarketClient = class {
|
|
|
897
871
|
const event = createImpressionEvent(params);
|
|
898
872
|
return await this.track(event);
|
|
899
873
|
}
|
|
900
|
-
/**
|
|
901
|
-
* Convenience method to track a click event.
|
|
902
|
-
* Creates a click event using createClickEvent() and calls track().
|
|
903
|
-
*/
|
|
904
|
-
async trackClick(params) {
|
|
905
|
-
const event = createClickEvent(params);
|
|
906
|
-
return await this.track(event);
|
|
907
|
-
}
|
|
908
|
-
/**
|
|
909
|
-
* Ultra-simple method to track a click from an ad returned by decideFromContext().
|
|
910
|
-
* Automatically extracts all required fields from the ad object.
|
|
911
|
-
*
|
|
912
|
-
* @param ad - The ad object returned by decideFromContext()
|
|
913
|
-
* @param options - Just click_context (what you showed the user)
|
|
914
|
-
*
|
|
915
|
-
* @example
|
|
916
|
-
* ```typescript
|
|
917
|
-
* const ad = await client.decideFromContext({ userMessage: "I need car insurance" });
|
|
918
|
-
* if (ad) {
|
|
919
|
-
* await client.trackClickFromAd(ad, {
|
|
920
|
-
* click_context: "Progressive: Get 20% off - Compare quotes"
|
|
921
|
-
* });
|
|
922
|
-
* }
|
|
923
|
-
* ```
|
|
924
|
-
*/
|
|
925
|
-
async trackClickFromAd(ad, options) {
|
|
926
|
-
if (!this.agentId) {
|
|
927
|
-
throw new Error("agentId is required for trackClickFromAd(). Set it in the constructor.");
|
|
928
|
-
}
|
|
929
|
-
const trackParams = {
|
|
930
|
-
agent_id: this.agentId,
|
|
931
|
-
request_id: ad.request_id,
|
|
932
|
-
decision_id: ad.decision_id,
|
|
933
|
-
unit_id: ad._ad.unit_id,
|
|
934
|
-
tracking_token: ad.tracking_token,
|
|
935
|
-
href: ad.click_url,
|
|
936
|
-
click_context: options.click_context
|
|
937
|
-
};
|
|
938
|
-
if (options.metadata) {
|
|
939
|
-
trackParams.metadata = options.metadata;
|
|
940
|
-
}
|
|
941
|
-
if (options.occurred_at) {
|
|
942
|
-
trackParams.occurred_at = options.occurred_at;
|
|
943
|
-
}
|
|
944
|
-
return await this.trackClick(trackParams);
|
|
945
|
-
}
|
|
946
874
|
/**
|
|
947
875
|
* Send feedback on an ad's performance to earn conversion-validated bonuses.
|
|
948
876
|
*
|
|
@@ -2057,7 +1985,6 @@ function suggestTaxonomies(query) {
|
|
|
2057
1985
|
NetworkError,
|
|
2058
1986
|
TimeoutError,
|
|
2059
1987
|
buildTaxonomy,
|
|
2060
|
-
createClickEvent,
|
|
2061
1988
|
createImpressionEvent,
|
|
2062
1989
|
createOpportunity,
|
|
2063
1990
|
detectIntent,
|