Skip to main content

Getting Started

AdMesh is a conversational advertising platform that enables platforms (like AI assistants, search engines, and chat applications) to monetize through contextually relevant product recommendations. AdMesh provides two SDKs for integration:
  • React SDK (admesh-ui-sdk): For frontend integration with citation format and product card layouts
  • AdMesh Weave Node SDK (admesh-weave-node): For backend Node.js integration with weave format
AspectWeave FormatCitation Format
What it isInline product cards embedded in conversationClickable links within conversational text
Best forVisual-heavy platforms, mobile appsText-based platforms, chat interfaces
IntegrationAdMesh Weave Node SDK (backend)React SDK (frontend)
User ExperienceRich, interactive cardsMinimal, non-intrusive links
ImplementationBackend Node.js integrationFrontend React integration
PerformanceRequires more bandwidthLightweight
Choose Weave if:
  • Your platform supports rich media/cards
  • You want a visual, interactive experience
  • You have sufficient bandwidth
Choose Citation if:
  • Your platform is text-based
  • You want minimal UI changes
  • You want lightweight integration
For detailed comparison, see Choose Integration.
AspectReact SDKAdMesh Weave Node SDK
Supported FormatsCitation, Product CardsWeave Format
Best forFrontend React applicationsBackend Node.js applications
Setup Time5-10 minutes15-30 minutes
CustomizationLimited (UI components)Full control (backend logic)
MaintenanceAutomatic updatesManual updates
LanguageJavaScript/TypeScript (React)Node.js (JavaScript/TypeScript)
DeploymentFrontend (browser)Backend (server)
Use React SDK if:
  • Your platform is built with React
  • You want citation or product card format
  • You want quick frontend integration
  • You need UI components for recommendations
Use AdMesh Weave Node SDK if:
  • You need weave format (inline product cards)
  • Your backend is built with Node.js
  • You want to embed recommendations in LLM responses
  • You need backend-side recommendation logic
For details, see React SDK or AdMesh Weave Node SDK.

React SDK Integration

Install via npm:
npm install admesh-ui-sdk
Or with yarn:
yarn add admesh-ui-sdk
For detailed instructions, see Installation.
The React SDK supports:
  • Citation Format - Clickable links within conversational text
  • Product Card Layouts - Individual product recommendation cards
Not supported: Weave Format (use AdMesh Weave Node SDK instead)
Basic usage with AdMeshProvider:
import { AdMeshProvider, AdMeshRecommendations } from 'admesh-ui-sdk';

export const MyApp = () => {
  const sessionId = 'user-session-123';

  return (
    <AdMeshProvider
      apiKey={process.env.REACT_APP_ADMESH_API_KEY}
      sessionId={sessionId}
    >
      <YourChatComponent />
    </AdMeshProvider>
  );
};

export const YourChatComponent = () => {
  const messages = [
    { messageId: 'msg_1', role: 'user', content: 'Show me laptops' },
    { messageId: 'msg_2', role: 'assistant', content: 'Here are some options...' }
  ];

  return (
    <div>
      {messages.map(msg => <div key={msg.messageId}>{msg.content}</div>)}
      <AdMeshRecommendations messages={messages} format="citation" />
    </div>
  );
};
Key points:
  • Wrap your app with <AdMeshProvider> and pass sessionId
  • Use <AdMeshRecommendations> to display recommendations
  • The SDK handles message deduplication and recommendation fetching automatically
For more examples, see Installation.
The sessionId parameter identifies a unique user session in AdMesh:
  • Purpose: Track recommendations across a conversation
  • Format: Any string (e.g., 'user-session-123')
  • Scope: Should be unique per user session
  • Lifetime: Persists for the duration of the conversation

Example:

// Generate a unique session ID for each user
const sessionId = `user-${Date.now()}`;

<AdMeshProvider apiKey={apiKey} sessionId={sessionId}>
  <App />
</AdMeshProvider>

Best Practices:

  • Generate a new sessionId for each user session
  • Store it in state or context
  • Pass the same sessionId throughout the conversation
  • Don’t change sessionId mid-conversation
Note: This is different from your platform’s chat ID. For example, in Perplexica:
  • chatId = Perplexica’s internal chat identifier
  • sessionId = AdMesh session identifier (passed to AdMeshProvider)
Use the theming API:
import {
  AdMeshLayout,
  mergeTheme,
  injectCustomTheme
} from 'admesh-ui-sdk';

const theme = mergeTheme({
  mode: 'dark',
  primaryColor: '#3b82f6',
  accentColor: '#ffffff'
});

injectCustomTheme(theme);

<AdMeshLayout recommendations={recommendations} theme={theme} />
For detailed styling options, see Styling System.
Yes! The React SDK is platform-agnostic and works with:
  • Tailwind CSS
  • Bootstrap
  • Material-UI
  • Chakra UI
  • Styled Components
  • Emotion
The SDK’s styles are isolated and won’t conflict with your framework.

Weave Format Integration

Weave format requires the AdMesh Weave Node SDK for backend Node.js integration:
  1. Install SDK: npm install admesh-weave-node
  2. Initialize SDK: Set up with your API key
  3. Call Recommendation API: Get recommendations for user query
  4. Embed in LLM Response: Integrate recommendations into your LLM response
  5. Track Interactions: Fire exposure, click, and conversion pixels
Note: Weave format is a backend integration for Node.js applications. It embeds product recommendations directly in LLM responses.For step-by-step guide, see AdMesh Weave Node SDK.
Backend (Node.js) Flow:
1. User Query (frontend)

2. Backend receives query

3. Backend calls AdMesh /recommend endpoint

4. Backend receives recommendations with signed URLs

5. Backend embeds recommendations in LLM response

6. Frontend receives response with embedded ads

7. Frontend fires exposure pixel when ad is shown

8. Frontend fires click pixel when user clicks

9. Conversions tracked via tracking pixels
Key Point: Weave format integration happens on the backend (Node.js) using the AdMesh Weave Node SDK. The frontend receives the response with recommendations already embedded.
Backend (Node.js) generates the cards:The AdMesh Weave Node SDK returns product data that your backend embeds in the LLM response:
{
  "recommendations": [
    {
      "id": "rec_123",
      "title": "Product Name",
      "description": "Product description",
      "image_url": "https://...",
      "price": "$99.99",
      "click_url": "https://track.useadmesh.com/click?...",
      "exposure_pixel": "https://track.useadmesh.com/exposure?..."
    }
  ]
}
Backend responsibility:
  • Call AdMesh Weave Node SDK to get recommendations
  • Format recommendations as product cards
  • Embed cards in LLM response text
  • Return complete response to frontend
Frontend responsibility:
  • Display the LLM response with embedded cards
  • Fire exposure pixel when card is shown
  • Fire click pixel when user clicks
  • Handle card interactions
Frontend tracking (JavaScript):
// Fire exposure pixel when card is shown
const exposurePixel = new Image();
exposurePixel.src = recommendation.exposure_pixel;

// Fire click pixel when user clicks
window.open(recommendation.click_url, '_blank');

// Conversions are tracked brand-side via localStorage and tracking pixels
// See brand integration guide for conversion tracking implementation
Backend tracking (Node.js):The AdMesh Weave Node SDK handles backend-side tracking:
  • Exposure tracking when recommendations are generated
  • Click tracking via signed URLs
  • Conversion tracking via tracking pixels
For detailed tracking implementation, see AdMesh Weave Node SDK.

Citation Format Integration

Citation format can be integrated via:
  1. React SDK (recommended for React apps)
  2. Direct API (for any platform)
Using React SDK:
import { AdMeshLayout } from 'admesh-ui-sdk';

<AdMeshLayout
  recommendations={recommendations}
  layout="citation"
/>
Using Direct API: See Citation Format for API details.
Citation format displays recommendations as clickable links within conversational text:
Here are some great options for you:
- [Ad] Product Name (https://...)
- [Ad] Another Product (https://...)
Each link is tracked for clicks and conversions.
With React SDK:
const theme = mergeTheme({
  primaryColor: '#3b82f6',
  customCSS: `
    .admesh-link {
      color: #3b82f6;
      text-decoration: underline;
    }
  `
});

injectCustomTheme(theme);

API Integration

  1. Log in to your AdMesh Dashboard
  2. Go to SettingsAPI Keys
  3. Click Generate New Key
  4. Copy your API key (format: admesh_prod_xxx)
  5. Store securely (never commit to version control)
Include your API key in the Authorization header:
curl -H "Authorization: Bearer admesh_prod_xxx" \
  https://api.useadmesh.com/recommend
Or in your code:
const response = await fetch('https://api.useadmesh.com/recommend', {
  headers: {
    'Authorization': 'Bearer admesh_prod_xxx'
  }
});
The /recommend endpoint returns recommendations for a user query:
POST /recommend
Content-Type: application/json
Authorization: Bearer admesh_prod_xxx

{
  "query": "best laptop for programming",
  "user_id": "user_123",
  "session_id": "session_456"
}
Response:
{
  "recommendations": [
    {
      "id": "rec_123",
      "title": "Product Name",
      "description": "...",
      "click_url": "https://...",
      "exposure_pixel": "https://..."
    }
  ]
}
Tracking URLs are cryptographically signed URLs for tracking interactions:
  • exposure_pixel: Fire when recommendation is shown
  • click_url: Redirect when user clicks
All URLs include:
  • HMAC-SHA256 signature
  • TTL (time-to-live, default 300 seconds)
  • Nonce for idempotency
Conversions are tracked brand-side via localStorage and tracking pixels, not through pre-generated URLs.Never modify these URLs - they’re signed and will fail if altered.

Performance & Optimization

Minimum requirements:
  • API Response Time: < 500ms
  • Recommendation Latency: < 1 second
  • Pixel Firing: < 100ms
  • SDK Bundle Size: ~25KB gzipped
Recommended:
  • API Response Time: < 200ms
  • Recommendation Latency: < 500ms
  • Pixel Firing: < 50ms
Best practices:
  1. Cache Recommendations: Cache results for 5-10 minutes
  2. Lazy Load SDK: Load SDK only when needed
  3. Batch Requests: Combine multiple requests when possible
  4. Use CDN: Serve SDK from CDN for faster delivery
  5. Monitor Latency: Track API response times
Rate limits:
  • Free Tier: 100 requests/minute
  • Pro Tier: 1,000 requests/minute
  • Enterprise: Custom limits
If you exceed limits, you’ll receive a 429 (Too Many Requests) response.
Implement exponential backoff:
async function callAPI(url, retries = 3) {
  for (let i = 0; i < retries; i++) {
    try {
      const response = await fetch(url);
      if (response.status === 429) {
        const delay = Math.pow(2, i) * 1000;
        await new Promise(r => setTimeout(r, delay));
        continue;
      }
      return response;
    } catch (error) {
      console.error('API error:', error);
    }
  }
}

Contextual Relevance

Contextual relevance scoring measures how well a recommendation matches a user’s query. Scores range from 0-100:
  • 90-100: Highly relevant
  • 70-89: Relevant
  • 50-69: Somewhat relevant
  • < 50: Not relevant
Higher scores mean better recommendations.
Relevance is calculated using:
  1. Semantic Matching: Compare query embeddings with product embeddings
  2. Keyword Matching: Match query keywords with product keywords
  3. Category Matching: Match query intent with product categories
  4. User History: Consider user’s past interactions
For details, see Contextual Relevance Score.
To improve scores:
  1. Better Product Data: Provide detailed titles, descriptions, keywords
  2. Accurate Categories: Assign correct product categories
  3. Rich Metadata: Include price, brand, ratings, etc.
  4. Update Regularly: Keep product data current

Testing & Debugging

Testing steps:
  1. Test API Key: Verify API key is valid
  2. Test Endpoint: Call /recommend with test query
  3. Test Rendering: Verify recommendations display correctly
  4. Test Tracking: Verify pixels fire correctly
  5. Test Edge Cases: Test with no results, errors, etc.
Debugging tips:
  1. Check Console: Look for JavaScript errors
  2. Check Network: Verify API requests are successful
  3. Check Pixels: Verify tracking pixels are firing
  4. Check Logs: Review server logs for errors
  5. Enable Debug Mode: Add debug=true to API requests
Pre-launch checklist:
  • API key is valid and secure
  • Recommendations display correctly
  • Tracking pixels fire correctly
  • Error handling works
  • Performance meets requirements
  • Mobile responsiveness works
  • Accessibility is compliant
  • Security is verified
To report bugs:
  1. Email: [email protected]
  2. Dashboard: Click HelpReport Bug
  3. GitHub: Open issue in AdMesh repository
Include:
  • Description of the issue
  • Steps to reproduce
  • Expected vs. actual behavior
  • Screenshots/logs if applicable

Common Issues

Check:
  1. API Key: Verify key is correct and not expired
  2. Authorization Header: Ensure header format is correct
  3. Endpoint URL: Verify you’re using correct endpoint
  4. Request Body: Validate JSON is properly formatted
  5. Network: Check internet connection
Troubleshoot:
  1. API Response: Verify API returns recommendations
  2. Rendering: Check if recommendations are being rendered
  3. Styling: Verify CSS isn’t hiding recommendations
  4. JavaScript: Check for JavaScript errors in console
  5. Permissions: Verify API key has correct permissions
Check:
  1. Pixel URL: Verify pixel URL is correct
  2. Network: Check if pixel request is being sent
  3. Ad Blockers: Disable ad blockers and test
  4. CORS: Verify CORS headers are correct
  5. Timing: Ensure pixel fires at correct time
Optimize:
  1. Cache Results: Cache recommendations for 5-10 minutes
  2. Lazy Load: Load SDK only when needed
  3. Compress: Enable gzip compression
  4. CDN: Use CDN for static assets
  5. Monitor: Track API response times

Additional Resources