Chat with Google Tag Manager
Add website chat through a Google Tag Manager container with a Custom HTML tag that builds the script itself, because Tag Manager drops the data-key attribute.
If your site already loads a Google Tag Manager container, you can add the chat from Tag Manager with no change to the site itself.
Use this snippet, not the plain line
Tag Manager rebuilds every script tag in a Custom HTML tag and keeps only a few
of its attributes. It drops data-key, and without it the chat loads and does
nothing. This snippet builds the tag itself, so the key stays on it:
<script>
(function () {
var s = document.createElement("script");
s.src = "https://app.verticalai.com.au/embed/widget.js";
s.async = true;
s.setAttribute("data-key", "pk_live_xxxxxxxx");
document.body.appendChild(s);
})();
</script>Swap pk_live_xxxxxxxx for your key. For an option such as
data-position="left", add another setAttribute line:
s.setAttribute("data-position", "left");.
Before you start
- A key. Steps 1 to 3 of Add chat to your website cover it. List every address the container runs on, usually your domain with and without www.
- Publish rights on the container.
Add the tag
- In your container, go to Tags, then New.
- Choose Tag Configuration, then Custom HTML.
- Paste the snippet above, with your key. Leave Support document.write off.
- Choose Triggering, then All Pages.
- Name the tag, such as Website chat, and choose Save.
- Choose Submit, then Publish.
Check it
Open the site in a private window and follow Check it works. If the chat button never shows, check the console for an error and that the tag fired. Tag Manager's preview mode shows which tags fired on a page.