Skip to main content

Embedding as an iframe Widget

If you embed your own widget as an iframe on third-party sites and want to track interactions inside it:

<script>
window.b2mConfig = {
apiKey: 'YOUR_API_KEY',
batchSize: 1,
sendInterval: 5000,
enableSPATracking: false,
eventGroups: {
widget: {
enabled: true,
events: ['widget_loaded', 'widget_action', 'widget_add_to_cart'],
autoTrack: []
}
}
};
</script>
<script src="https://edge.b2metric.com/b2m-web-sdk.js"></script>

Replace the event names with your widget's actual events. In an iframe context, batchSize, sendInterval and SPA tracking are not auto-tuned the way they are in a standard script-tag install, so set them explicitly.