Embed Script Implementation
Developer-focused reference
This guide covers how to implement the Partner Fleet marketplace embed script in your application. The embed script renders the In-App Marketplace iframe, handles JWT authentication, passes integration status to the marketplace, and routes postMessage events between the marketplace and your application.
Get the snippet from your admin
Partner Fleet generates the embed snippet for you with your specific subdomain and trusted origins pre-filled. Copy it directly from Settings > In-App Marketplace > Developer Settings > Embed Script. Typing the snippet manually risks errors in account-specific values.
Basic Setup
1. Add Container Element
Add a container element where the script will render the marketplace iframe:
<div id="iframe-container"></div>2. Include the Script
Add the Partner Fleet script to your page:
<script src="https://your-partner-fleet-domain/inapp_script.js"></script>Important
Replace
your-partner-fleet-domainwith your configured CNAME domain. The auto-generated snippet from your admin already has the correct value.
Basic Implementation
Initialize the embedded iframe with your JWT configuration:
const embeddedIframe = new EmbeddedIframe({
// Required Configuration
iframeOrigin: 'https://your-partner-fleet-domain',
trustedOrigins: ['https://your-partner-fleet-domain'],
containerId: 'iframe-container',
// JWT Configuration
initialToken: 'YOUR_INITIAL_JWT_TOKEN', // Optional: Can be empty string if using getJwtToken
getJwtToken: function() {
return new Promise((resolve, reject) => {
// Implement your token retrieval logic here
try {
const token = generateNewToken(); // Your token generation function
resolve(token);
} catch (error) {
reject('Token generation failed');
}
});
}
});The getJwtToken function should return a Promise resolving to a fresh JWT for the current user. The embed will call this function on initial load and again when the token is near expiration. See the JWT SSO Implementation guide for the JWT payload structure and signing requirements.
Advanced Implementation: Passing Integration Status
In addition to the JWT, the embed script accepts an integrations array that pre-populates each end user's integration status for each listing. The marketplace uses these statuses to render the correct buttons (Install, Manage, Reinstall, Fix Issues, etc.) on each listing for that user.
Integration status: current and future
Today, you pass integration status only through the embed script's
integrationsarray — it is a separate data stream the iframe receives when it initializes (render time). A future API route will provide an additional way to pass status. The embed script approach remains the canonical method until the new API route ships.
const embeddedIframeWithIntegrations = new EmbeddedIframe({
iframeOrigin: 'https://your-partner-fleet-domain',
trustedOrigins: ['https://your-partner-fleet-domain'],
containerId: 'iframe-container',
initialToken: 'YOUR_INITIAL_JWT_TOKEN',
integrations: [
{
partner_id: 'chrome',
status: 'Pending',
metadata: {
installDate: '2024-03-15',
version: '1.0.0'
}
},
{
partner_id: 'chili-piper',
status: 'Pending',
metadata: {
configuration: {
enabled: true,
settings: {}
}
}
}
],
getJwtToken: function() {
return new Promise((resolve, reject) => {
fetchNewToken()
.then(token => resolve(token))
.catch(error => reject(error));
});
}
});Integration Object Structure
{
partner_id: string, // Partner identifier
status: string, // Integration status
metadata: object // Additional integration data
}Configuration Options
Required Parameters
| Parameter | Type | Description |
|---|---|---|
iframeOrigin | string | Your Partner Fleet marketplace domain (typically your CNAME) |
trustedOrigins | array | Allowed origins for postMessage events. Typically the same as iframeOrigin. |
containerId | string | DOM element ID where the script renders the iframe |
getJwtToken | function | Returns Promise resolving to new JWT token. Required for production setups. |
Optional Parameters
| Parameter | Type | Description |
|---|---|---|
initialToken | string | Initial JWT token for authentication. Useful for the first render before the embed calls getJwtToken. |
integrations | array | Pre-populated integration statuses for the user. See Advanced Implementation above. |
urlVariables | object | Variables for dynamic URL substitution in CTA destinations (for example, domain). See the Dynamic Domains guide. |
Handling postMessage Events
When you configure a CTA destination as Send to page in my app on the Buttons & Actions, Permissions, or Per-Listing Overrides tab, clicking the button triggers a postMessage event from the embedded marketplace to your application. Your application listens for these events and routes the user accordingly.
Basic listener
window.addEventListener('message', (event) => {
// Verify the message comes from your trusted origin
if (event.origin !== 'https://your-partner-fleet-domain') return;
const { action, path, listingId, ...rest } = event.data;
if (action === 'navigate') {
window.location.href = path;
}
});Always verify event.origin against your trusted origin to prevent malicious sites from sending fake postMessage events. For more advanced handler patterns including modal triggers and multi-action routing, see the Handling postMessage Events guide.
CNAME and Embed Origin
If you've configured a custom CNAME (for example, marketplace.yourcompany.com), your iframeOrigin and trustedOrigins should use that CNAME, not the Partner Fleet subdomain. The embed snippet generated in Developer Settings uses the correct values automatically.
Why CNAME matters
Serving the marketplace from your own subdomain makes it appear first-party to your end users, avoids cross-domain cookie restrictions, and removes the need for Content Security Policy changes in your application. Setting up the CNAME is one of the highest-leverage things you can do for the user experience.
Allowed Domains
The marketplace will only render on domains you've authorized. Configure these in Settings > In-App Marketplace > Developer Settings > Allowed Domains. If your embed doesn't render and you don't see JavaScript errors, check the Allowed Domains list first.
HTML Container Requirements
The container element:
- Must have a unique ID.
- Should have a defined width (either via CSS or class).
- Should have a defined height if parent element height is not set.
Example with custom dimensions:
<div id="iframe-container" style="width: 100%; height: 600px;"></div>Script Behavior
Automatic Features
Responsive Sizing
- Adjusts height based on content.
- Maintains full width of container.
- Handles window resize events.
Token Management
- Requests new tokens when needed.
- Handles token refresh automatically.
- Maintains session continuity.
Cross-Origin Communication
- Securely handles messages between your application and the marketplace.
- Validates message origins.
- Manages integration status updates.
Event Handling
The script automatically handles:
- Window resize events.
- Content height changes.
- Initial load sizing.
- Token expiration.
- Token refresh requests.
- Authentication failures.
- Status update requests.
- Integration creation events.
- Metadata updates.
Best Practices
Container Setup
- Place container in a responsive layout.
- Avoid fixed height constraints.
- Consider mobile viewports.
Token Management
- Implement robust token generation logic.
- Handle token refresh failures gracefully.
- Include proper error handling.
Performance
- Load script asynchronously if possible.
- Initialize after DOM is ready.
- Handle loading states appropriately.
Common Issues and Solutions
| Issue | Solution |
|---|---|
| Marketplace doesn't render at all | Check that your domain is in the Allowed Domains list at Settings > In-App Marketplace > Developer Settings. |
| Iframe does not render | Check container ID exists in DOM and has dimensions. |
| Token refresh failures | Verify JWT generation logic; use Test Tools to decode and validate. |
| Size adjustment issues | Ensure container has no fixed height. |
| Cross-origin errors | Verify domain configuration; confirm iframeOrigin matches the rendered iframe origin. |
| postMessage events do not arrive | Confirm you add the event listener before the marketplace loads; verify event.origin check matches your iframeOrigin. |
Support
Need Help?
If you encounter any issues with the embed script implementation, contact our support team.
What's Next
- JWT SSO Implementation — backend signing and payload structure.
- Handling postMessage Events from the In-App Marketplace — advanced postMessage patterns.
- Dynamic Domains Configuration — multi-environment URL substitution.
- Test Tools — validate your token before deploying.
- Developer Settings — admin configuration reference.
Updated 2 months ago

