MagicFeedback Popup SDK uses a renderer architecture that allows you to customize how popups are displayed. By default, the SDK provides browser-based rendering, but you can create custom renderers for specialized environments.
Create a class that implements the PopupRenderer interface:
import { PopupRenderer, DeepdotsEventType, PopupActions } from '@magicfeedback/popup-sdk';export class MyCustomRenderer implements PopupRenderer { private isVisible = false; init(): void { // Initialize your custom rendering system console.log('Custom renderer initialized'); } show( surveyId: string, productId: string, actions: PopupActions | undefined, emit: (type: DeepdotsEventType, surveyId: string, data?: Record<string, unknown>) => void, onClose: () => void, env?: string ): void { this.isVisible = true; // Emit popup shown event emit('popup_shown', surveyId); // Your custom rendering logic here console.log('Showing popup:', { surveyId, productId, env }); // Example: Show popup and handle user interaction this.renderCustomUI(surveyId, productId, actions, (data) => { // User completed the survey emit('survey_completed', surveyId, data); onClose(); }); } hide(): void { this.isVisible = false; // Clean up your custom UI console.log('Hiding popup'); } private renderCustomUI( surveyId: string, productId: string, actions: PopupActions | undefined, onComplete: (data: Record<string, unknown>) => void ): void { // Implement your custom UI rendering logic // This could integrate with a modal library, native UI, etc. }}
2
Register the Renderer
Use the setRenderer() method to register your custom renderer:
src/core/deepdots-popups.ts
import { DeepdotsPopups } from '@magicfeedback/popup-sdk';import { MyCustomRenderer } from './my-custom-renderer';const popups = new DeepdotsPopups();// Set custom renderer before initializingpopups.setRenderer(new MyCustomRenderer());// Initialize the SDKpopups.init({ apiKey: 'your-api-key', mode: 'client', popups: [/* your popup definitions */]});
The setRenderer() method automatically calls init() on your renderer if the SDK is already initialized.
3
Handle Events
Your renderer should emit appropriate events during the popup lifecycle:
// When popup is shownemit('popup_shown', surveyId, { popupId: 'popup-id' });// When user interactsemit('popup_clicked', surveyId, { action: 'button-clicked' });// When survey is completedemit('survey_completed', surveyId, { rating: 5, feedback: 'Great product!'});