@the_ro_show/agent-ads-sdk 0.15.1 → 0.16.1
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 +73 -28
- package/dist/index.d.mts +3 -54
- package/dist/index.d.ts +3 -54
- package/dist/index.js +18 -131
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -130
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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,15 +176,17 @@ const client = new AttentionMarketClient({
|
|
|
162
176
|
|
|
163
177
|
```typescript
|
|
164
178
|
const client = new AttentionMarketClient({
|
|
165
|
-
apiKey: 'am_live_YOUR_KEY',
|
|
166
|
-
agentId: 'agt_YOUR_AGENT_ID',
|
|
179
|
+
apiKey: 'am_live_YOUR_KEY', // Required: Your AttentionMarket API key
|
|
180
|
+
agentId: 'agt_YOUR_AGENT_ID', // Required for decideFromContext()
|
|
167
181
|
// baseUrl defaults to production Supabase endpoint
|
|
168
182
|
// Only override if self-hosting or using different environment
|
|
169
|
-
timeoutMs: 4000,
|
|
170
|
-
maxRetries: 2
|
|
183
|
+
timeoutMs: 4000, // Optional: request timeout in milliseconds
|
|
184
|
+
maxRetries: 2 // Optional: automatic retry count
|
|
171
185
|
});
|
|
172
186
|
```
|
|
173
187
|
|
|
188
|
+
**Note:** Get your API key and agent ID from your [developer dashboard](https://api.attentionmarket.ai).
|
|
189
|
+
|
|
174
190
|
## Core Concepts
|
|
175
191
|
|
|
176
192
|
### Placements
|
|
@@ -528,28 +544,27 @@ const ad = await client.decideFromContext({
|
|
|
528
544
|
|
|
529
545
|
### Click Tracking
|
|
530
546
|
|
|
531
|
-
Clicks are automatically tracked when users visit `click_url`.
|
|
547
|
+
Clicks are automatically and securely tracked when users visit the `click_url`.
|
|
548
|
+
|
|
549
|
+
**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.
|
|
532
550
|
|
|
533
551
|
```typescript
|
|
534
|
-
|
|
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
|
-
```
|
|
552
|
+
import { sanitizeURL } from '@the_ro_show/agent-ads-sdk';
|
|
544
553
|
|
|
545
|
-
|
|
554
|
+
// When user clicks the ad, sanitize URL for security
|
|
555
|
+
const safeURL = sanitizeURL(ad.click_url);
|
|
556
|
+
if (safeURL) {
|
|
557
|
+
window.location.href = safeURL;
|
|
558
|
+
}
|
|
546
559
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
click_context: "User clicked on sponsored suggestion"
|
|
550
|
-
});
|
|
560
|
+
// Or in a chat/messaging context, share:
|
|
561
|
+
const shareableLink = ad.tracking_url;
|
|
551
562
|
```
|
|
552
563
|
|
|
564
|
+
**Security Note:** While our backend validates all URLs, it's recommended to use the `sanitizeURL()` helper to protect against potential XSS attacks if the backend is ever compromised or misconfigured.
|
|
565
|
+
|
|
566
|
+
Manual click tracking has been removed for security reasons. All clicks must go through the redirect URLs to ensure fraud prevention and accurate tracking.
|
|
567
|
+
|
|
553
568
|
### Conversion Tracking
|
|
554
569
|
|
|
555
570
|
Track conversions (purchases, signups, etc.) to improve advertiser ROI and your quality score:
|
|
@@ -625,6 +640,36 @@ Use test API keys (`am_test_...`) for development and testing. Test keys:
|
|
|
625
640
|
|
|
626
641
|
Switch to live keys (`am_live_...`) when deploying to production.
|
|
627
642
|
|
|
643
|
+
## 🌍 REST API for Mobile & Other Platforms
|
|
644
|
+
|
|
645
|
+
For non-Node.js platforms, use our REST API directly:
|
|
646
|
+
|
|
647
|
+
### iOS/Swift Example
|
|
648
|
+
```swift
|
|
649
|
+
// See full guide: https://rtrivedi.github.io/agent-ads-sdk/docs/mobile-integration
|
|
650
|
+
let url = URL(string: "https://peruwnbrqkvmrldhpoom.supabase.co/functions/v1/decide")!
|
|
651
|
+
var request = URLRequest(url: url)
|
|
652
|
+
request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")
|
|
653
|
+
request.setValue(supabaseAnonKey, forHTTPHeaderField: "apikey")
|
|
654
|
+
// ... see docs for complete example
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
### Python Example
|
|
658
|
+
```python
|
|
659
|
+
# See full guide: https://rtrivedi.github.io/agent-ads-sdk/docs/api-reference
|
|
660
|
+
import requests
|
|
661
|
+
response = requests.post(
|
|
662
|
+
"https://peruwnbrqkvmrldhpoom.supabase.co/functions/v1/decide",
|
|
663
|
+
headers={
|
|
664
|
+
"Authorization": f"Bearer {api_key}",
|
|
665
|
+
"apikey": supabase_anon_key
|
|
666
|
+
},
|
|
667
|
+
json={"user_message": "I need insurance"}
|
|
668
|
+
)
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
**📖 Full REST API Documentation:** [https://rtrivedi.github.io/agent-ads-sdk/docs/api-reference](https://rtrivedi.github.io/agent-ads-sdk/docs/api-reference)
|
|
672
|
+
|
|
628
673
|
## 🤖 Claude Code Integration
|
|
629
674
|
|
|
630
675
|
Building with Claude Code? We've created ready-to-use prompts for seamless integration.
|
package/dist/index.d.mts
CHANGED
|
@@ -82,7 +82,8 @@ interface DecideFromContextRequest {
|
|
|
82
82
|
placement?: PlacementType;
|
|
83
83
|
/**
|
|
84
84
|
* Optional category hint (e.g., 'legal', 'insurance', 'travel').
|
|
85
|
-
*
|
|
85
|
+
* Defaults to 'general.query'. Only used as fallback - semantic matching
|
|
86
|
+
* uses conversation context, not taxonomy.
|
|
86
87
|
*/
|
|
87
88
|
suggestedCategory?: string;
|
|
88
89
|
/** User's country code. Default: 'US' */
|
|
@@ -773,24 +774,6 @@ interface CreateImpressionEventParams {
|
|
|
773
774
|
* @returns EventIngestRequest ready to pass to client.track()
|
|
774
775
|
*/
|
|
775
776
|
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
777
|
/**
|
|
795
778
|
* Options for URL sanitization
|
|
796
779
|
*/
|
|
@@ -868,11 +851,6 @@ declare class AttentionMarketClient {
|
|
|
868
851
|
private agentId;
|
|
869
852
|
private appId;
|
|
870
853
|
constructor(config: SDKConfig);
|
|
871
|
-
/**
|
|
872
|
-
* Infer taxonomy from user message using keyword matching
|
|
873
|
-
* Returns best-guess taxonomy based on common patterns
|
|
874
|
-
*/
|
|
875
|
-
private inferTaxonomy;
|
|
876
854
|
/**
|
|
877
855
|
* Validate SDK configuration for security
|
|
878
856
|
*/
|
|
@@ -922,35 +900,6 @@ declare class AttentionMarketClient {
|
|
|
922
900
|
trackImpression(params: Omit<CreateImpressionEventParams, 'occurred_at'> & {
|
|
923
901
|
occurred_at?: string;
|
|
924
902
|
}): 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
903
|
/**
|
|
955
904
|
* Send feedback on an ad's performance to earn conversion-validated bonuses.
|
|
956
905
|
*
|
|
@@ -1584,4 +1533,4 @@ declare function getVertical(taxonomy: string): string | null;
|
|
|
1584
1533
|
*/
|
|
1585
1534
|
declare function suggestTaxonomies(query: string): string[];
|
|
1586
1535
|
|
|
1587
|
-
export { type APIError, APIRequestError, type AdResponse, type AdScore, type AdUnit, type AgentSignupRequest, type AgentSignupResponse, AttentionMarketClient, AttentionMarketError, type Constraints, type Context, type
|
|
1536
|
+
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
|
@@ -82,7 +82,8 @@ interface DecideFromContextRequest {
|
|
|
82
82
|
placement?: PlacementType;
|
|
83
83
|
/**
|
|
84
84
|
* Optional category hint (e.g., 'legal', 'insurance', 'travel').
|
|
85
|
-
*
|
|
85
|
+
* Defaults to 'general.query'. Only used as fallback - semantic matching
|
|
86
|
+
* uses conversation context, not taxonomy.
|
|
86
87
|
*/
|
|
87
88
|
suggestedCategory?: string;
|
|
88
89
|
/** User's country code. Default: 'US' */
|
|
@@ -773,24 +774,6 @@ interface CreateImpressionEventParams {
|
|
|
773
774
|
* @returns EventIngestRequest ready to pass to client.track()
|
|
774
775
|
*/
|
|
775
776
|
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
777
|
/**
|
|
795
778
|
* Options for URL sanitization
|
|
796
779
|
*/
|
|
@@ -868,11 +851,6 @@ declare class AttentionMarketClient {
|
|
|
868
851
|
private agentId;
|
|
869
852
|
private appId;
|
|
870
853
|
constructor(config: SDKConfig);
|
|
871
|
-
/**
|
|
872
|
-
* Infer taxonomy from user message using keyword matching
|
|
873
|
-
* Returns best-guess taxonomy based on common patterns
|
|
874
|
-
*/
|
|
875
|
-
private inferTaxonomy;
|
|
876
854
|
/**
|
|
877
855
|
* Validate SDK configuration for security
|
|
878
856
|
*/
|
|
@@ -922,35 +900,6 @@ declare class AttentionMarketClient {
|
|
|
922
900
|
trackImpression(params: Omit<CreateImpressionEventParams, 'occurred_at'> & {
|
|
923
901
|
occurred_at?: string;
|
|
924
902
|
}): 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
903
|
/**
|
|
955
904
|
* Send feedback on an ad's performance to earn conversion-validated bonuses.
|
|
956
905
|
*
|
|
@@ -1584,4 +1533,4 @@ declare function getVertical(taxonomy: string): string | null;
|
|
|
1584
1533
|
*/
|
|
1585
1534
|
declare function suggestTaxonomies(query: string): string[];
|
|
1586
1535
|
|
|
1587
|
-
export { type APIError, APIRequestError, type AdResponse, type AdScore, type AdUnit, type AgentSignupRequest, type AgentSignupResponse, AttentionMarketClient, AttentionMarketError, type Constraints, type Context, type
|
|
1536
|
+
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
|
"<": "<",
|
|
@@ -542,59 +516,6 @@ var AttentionMarketClient = class {
|
|
|
542
516
|
}
|
|
543
517
|
this.http = new HTTPClient(httpConfig);
|
|
544
518
|
}
|
|
545
|
-
/**
|
|
546
|
-
* Infer taxonomy from user message using keyword matching
|
|
547
|
-
* Returns best-guess taxonomy based on common patterns
|
|
548
|
-
*/
|
|
549
|
-
inferTaxonomy(userMessage) {
|
|
550
|
-
const msg = userMessage.toLowerCase();
|
|
551
|
-
if (msg.match(/\b(ecommerce|e-commerce|online store|shopify|sell products?|product brand)\b/)) {
|
|
552
|
-
return "business.ecommerce.platform.trial";
|
|
553
|
-
}
|
|
554
|
-
if (msg.match(/\b(start.*business|launch.*business|business formation|llc|incorporate)\b/)) {
|
|
555
|
-
return "business.ecommerce.platform.trial";
|
|
556
|
-
}
|
|
557
|
-
if (msg.match(/\b(car insurance|auto insurance|vehicle insurance)\b/)) {
|
|
558
|
-
return "insurance.auto.full_coverage.quote";
|
|
559
|
-
}
|
|
560
|
-
if (msg.match(/\b(health insurance|medical insurance)\b/)) {
|
|
561
|
-
return "insurance.health.individual.quote";
|
|
562
|
-
}
|
|
563
|
-
if (msg.match(/\b(life insurance)\b/)) {
|
|
564
|
-
return "insurance.life.term.quote";
|
|
565
|
-
}
|
|
566
|
-
if (msg.match(/\b(insurance)\b/)) {
|
|
567
|
-
return "insurance.auto.full_coverage.quote";
|
|
568
|
-
}
|
|
569
|
-
if (msg.match(/\b(personal loan|debt consolidation|borrow money)\b/)) {
|
|
570
|
-
return "finance.loans.personal.apply";
|
|
571
|
-
}
|
|
572
|
-
if (msg.match(/\b(credit card)\b/)) {
|
|
573
|
-
return "finance.credit_cards.rewards.apply";
|
|
574
|
-
}
|
|
575
|
-
if (msg.match(/\b(mover?s?|moving|relocat(e|ing))\b/)) {
|
|
576
|
-
return "home_services.moving.local.quote";
|
|
577
|
-
}
|
|
578
|
-
if (msg.match(/\b(plumber|plumbing|leak|pipe)\b/)) {
|
|
579
|
-
return "home_services.plumbing.emergency.quote";
|
|
580
|
-
}
|
|
581
|
-
if (msg.match(/\b(electrician|electrical|wiring)\b/)) {
|
|
582
|
-
return "home_services.electrical.repair.quote";
|
|
583
|
-
}
|
|
584
|
-
if (msg.match(/\b(clean(ing|er)|maid service)\b/)) {
|
|
585
|
-
return "home_services.cleaning.regular.book";
|
|
586
|
-
}
|
|
587
|
-
if (msg.match(/\b(hotel|lodging|accommodation)\b/)) {
|
|
588
|
-
return "travel.hotels.luxury.book";
|
|
589
|
-
}
|
|
590
|
-
if (msg.match(/\b(flight|plane ticket|airfare)\b/)) {
|
|
591
|
-
return "travel.flights.domestic.book";
|
|
592
|
-
}
|
|
593
|
-
if (msg.match(/\b(lawyer|attorney|legal help)\b/)) {
|
|
594
|
-
return "legal.general.consultation";
|
|
595
|
-
}
|
|
596
|
-
return "business.ecommerce.platform.trial";
|
|
597
|
-
}
|
|
598
519
|
/**
|
|
599
520
|
* Validate SDK configuration for security
|
|
600
521
|
*/
|
|
@@ -678,7 +599,7 @@ var AttentionMarketClient = class {
|
|
|
678
599
|
const language = params.language || "en";
|
|
679
600
|
const platform = params.platform || "web";
|
|
680
601
|
const placementType = params.placement || "sponsored_suggestion";
|
|
681
|
-
const taxonomy = params.suggestedCategory ||
|
|
602
|
+
const taxonomy = params.suggestedCategory || "general.query";
|
|
682
603
|
if (params.minQualityScore !== void 0) {
|
|
683
604
|
if (typeof params.minQualityScore !== "number" || params.minQualityScore < 0 || params.minQualityScore > 1) {
|
|
684
605
|
throw new Error("minQualityScore must be a number between 0.0 and 1.0");
|
|
@@ -733,6 +654,11 @@ var AttentionMarketClient = class {
|
|
|
733
654
|
if (params.optimizeFor && params.optimizeFor !== "revenue" && params.optimizeFor !== "relevance") {
|
|
734
655
|
throw new Error('optimizeFor must be either "revenue" or "relevance"');
|
|
735
656
|
}
|
|
657
|
+
const validFormats = ["minimal", "standard", "verbose"];
|
|
658
|
+
const responseFormat = params.response_format || "minimal";
|
|
659
|
+
if (!validFormats.includes(responseFormat)) {
|
|
660
|
+
throw new Error(`response_format must be one of: ${validFormats.join(", ")}. Got: ${responseFormat}`);
|
|
661
|
+
}
|
|
736
662
|
const request = {
|
|
737
663
|
request_id: generateUUID(),
|
|
738
664
|
agent_id: this.agentId,
|
|
@@ -761,7 +687,7 @@ var AttentionMarketClient = class {
|
|
|
761
687
|
context,
|
|
762
688
|
user_intent: params.userMessage,
|
|
763
689
|
// Use minimal response format by default for better performance
|
|
764
|
-
response_format:
|
|
690
|
+
response_format: responseFormat,
|
|
765
691
|
// === Smart Context Fields (v0.15.0) ===
|
|
766
692
|
// Include user context if we have any data
|
|
767
693
|
...(interests.length > 0 || recentTopics.length > 0 || purchaseIntent) && {
|
|
@@ -804,7 +730,11 @@ var AttentionMarketClient = class {
|
|
|
804
730
|
tracking_token: response.tracking_token
|
|
805
731
|
});
|
|
806
732
|
} catch (error) {
|
|
807
|
-
console.
|
|
733
|
+
console.error("[AttentionMarket] REVENUE RISK: Failed to auto-track impression. Clicks without impressions will NOT earn revenue.", {
|
|
734
|
+
error: error instanceof Error ? error.message : String(error),
|
|
735
|
+
tracking_token: response.tracking_token,
|
|
736
|
+
unit_id: response["_meta"]?.["unit_id"]
|
|
737
|
+
});
|
|
808
738
|
}
|
|
809
739
|
}
|
|
810
740
|
const adResponse2 = {
|
|
@@ -849,7 +779,11 @@ var AttentionMarketClient = class {
|
|
|
849
779
|
tracking_token: adUnit.tracking.token
|
|
850
780
|
});
|
|
851
781
|
} catch (error) {
|
|
852
|
-
console.
|
|
782
|
+
console.error("[AttentionMarket] REVENUE RISK: Failed to auto-track impression. Clicks without impressions will NOT earn revenue.", {
|
|
783
|
+
error: error instanceof Error ? error.message : String(error),
|
|
784
|
+
tracking_token: adUnit.tracking.token,
|
|
785
|
+
unit_id: adUnit.unit_id
|
|
786
|
+
});
|
|
853
787
|
}
|
|
854
788
|
const adResponse = {
|
|
855
789
|
request_id: response.request_id,
|
|
@@ -897,52 +831,6 @@ var AttentionMarketClient = class {
|
|
|
897
831
|
const event = createImpressionEvent(params);
|
|
898
832
|
return await this.track(event);
|
|
899
833
|
}
|
|
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
834
|
/**
|
|
947
835
|
* Send feedback on an ad's performance to earn conversion-validated bonuses.
|
|
948
836
|
*
|
|
@@ -1245,7 +1133,7 @@ var AttentionMarketClient = class {
|
|
|
1245
1133
|
const context = contextParts.join("\n");
|
|
1246
1134
|
const country = params.context?.geo?.country || "US";
|
|
1247
1135
|
const language = this.normalizeLocale(params.context?.locale);
|
|
1248
|
-
const taxonomy = params.suggestedCategory || "
|
|
1136
|
+
const taxonomy = params.suggestedCategory || "general.query";
|
|
1249
1137
|
const idempotencyKey = options?.idempotencyKey || generateUUID();
|
|
1250
1138
|
const request = {
|
|
1251
1139
|
request_id: idempotencyKey,
|
|
@@ -2057,7 +1945,6 @@ function suggestTaxonomies(query) {
|
|
|
2057
1945
|
NetworkError,
|
|
2058
1946
|
TimeoutError,
|
|
2059
1947
|
buildTaxonomy,
|
|
2060
|
-
createClickEvent,
|
|
2061
1948
|
createImpressionEvent,
|
|
2062
1949
|
createOpportunity,
|
|
2063
1950
|
detectIntent,
|