Embedding Multiple Videobot Widgets via Google Tag Manager β
Overview β
However, adding multiple widgets, such as sliders, into the same page will not work out of the box. If you try it, you'll quickly notice that only one of them works. This guide will explain the background for this behaviour and how it can be fixed.
This guide explains:
- Why multiple widgets donβt work out of the box
- How to fix it using manual widget creation
- How to embed multiple widgets via Google Tag Manager (GTM)
1. Why Multiple Widgets Donβt Work Out of the Box β
Consider the following snippet for embedding a slider:
<div
id="videobot-widget"
data-widget-type="widget"
data-widget-id="example123"
></div>
<script type="module" src="https://videobot.com/embed/videobot.mjs"></script>
It consists of two parts: the container (div
) and the script (script
). When the script loads, it creates a Videobot into the empty container, if one is available. It finds it on the page using the id
attribute, and specifically the value videobot-widget
(or just videobot
for traditional chat widgets).
By definition, there can only be one id
on any given page, and two elements with the same id
will not function correctly. This also prevents us from directly using two different widgets on the same page.
2. Fix: Embedding Multiple Widgets Manually β
Step 1: Use Unique IDs β
Give each widget its own unique container ID:
<div
id="videobot-widget-1"
data-widget-type="widget"
data-widget-id="example123"
></div>
<div
id="videobot-widget-2"
data-widget-type="widget"
data-widget-id="example456"
></div>
Step 2: Manually Initialize Widgets β
After loading the script, you can manually initialize the widgets using the public API:
<script type="module">
import { Videobot } from 'https://videobot.com/embed/videobot.mjs'
new Videobot('#videobot-widget-1')
new Videobot('#videobot-widget-2')
</script>
3. Embedding via Google Tag Manager (GTM) β
To install multiple widgets through GTM, follow these steps:
β οΈ Important: Do not combine direct embed and GTM-based embed methods on the same page. It will lead to duplicate widgets.
β Prerequisites: β
- GTM installed on your website
- Widget IDs (e.g. from the Videobot dashboard)
Step-by-Step Setup β
Step 1: Create the Script Tag β
- Go to Tags in GTM > Click New
- Choose Tag Configuration > Select Custom HTML
- Paste the following:
<script type="module" src="https://videobot.com/embed/videobot.mjs"></script>
- Check Support document.write
- Name the tag (e.g.
Videobot Script
) - Save the tag without assigning a trigger.
Step 2: Create the Embed Tag β
- Create another Custom HTML tag
- Insert only the widget container creation logic, without the script:
<script>
(function () {
var sliderId = {{Videobot slider id}};
var cornerWidgetId = {{Videobot widget id}};
// Inject slider widget
if (sliderId) {
var targetDiv = document.querySelector('.target-div');
if (targetDiv) {
targetDiv.innerHTML = '';
var widget1 = document.createElement('div');
widget1.id = 'videobot-widget';
widget1.setAttribute('data-widget-type', 'widget');
widget1.setAttribute('data-widget-id', sliderId);
widget1.style.width = '100%';
widget1.style.height = '100%';
targetDiv.appendChild(widget1);
}
}
// Inject corner widget
if (cornerWidgetId) {
var widget2 = document.createElement('div');
widget2.id = 'videobot';
widget2.setAttribute('data-videobot-id', cornerWidgetId);
widget2.setAttribute('data-sync', 'true');
document.body.appendChild(widget2);
}
// Inject script if needed
var moduleScript = document.createElement('script');
moduleScript.setAttribute('type', 'module');
moduleScript.setAttribute('src', 'https://videobot.com/embed/videobot.mjs');
document.body.appendChild(moduleScript);
})();
</script>
- Go to Advanced Settings > Enable necessary consent options
- Under Tag Sequencing, set it to fire after the
Videobot Script
tag - Set a Trigger, e.g.
Consent Initialization β All Pages
- Save and publish your workspace
4. Tips & Recommendations β
- Make sure to test the widgets on all device sizes
- If you're dynamically injecting widgets, ensure the containers are in place before calling
new Videobot(...)
- Keep the widget IDs organized per environment (staging/production)
Summary β
Scenario | Solution |
---|---|
Multiple widgets directly in HTML | Use unique IDs + new Videobot(...) |
Multiple widgets via GTM | Inject containers via GTM tag + include loader script + manual init |