How to add an AI chatbot with Google Tag Manager

In Google Tag Manager, create a Custom HTML tag with the Feedbot script, trigger it on All Pages (or only the pages you pick), test it in Preview, then Submit and publish. The chatbot goes live without touching your site's code.

  • Setup: 10 minutes
  • Publish permission on the GTM container
  • Free plan, no card
  • Updated

Google Tag Manager is the easiest route when you can’t, or don’t want to, edit your site’s templates: marketing teams, agencies, or platforms where code changes go through a release. Feedbot (our product) installs with one script tag, so it fits in a GTM Custom HTML tag as is.

What you need

  • A Feedbot bot id from Dashboard → Bot → Install (the Free plan is enough to start).
  • A GTM web container already installed on your site, and permission to publish it.

Add the chatbot tag

  1. In Google Tag Manager, open your container and go to Tags → New.

  2. Name the tag, for example Feedbot chat.

  3. Click Tag Configuration and choose Custom HTML.

  4. Paste the snippet:

    <script src="https://w.feedbotai.com/v1/feedbot.js" data-bot-id="YOUR_BOT_ID" async></script>

    Leave Support document.write unchecked. The loader doesn’t use it.

  5. Click Triggering and pick All Pages.

  6. Click Save.

  7. Click Preview, enter your site URL and check that the chat button appears and that Tag Assistant shows Feedbot chat under Tags Fired.

  8. Back in GTM, click Submit, add a version name such as “Add Feedbot chat”, and click Publish.

The steps for Custom HTML tags are described in Google’s custom tags help.

Show the chatbot on some pages only

GTM triggers decide where the tag runs. Common setups:

Goal Trigger type Condition
Every page Page View, All Page Views (none)
Pricing and checkout only Page View, Some Page Views Page Path matches RegEx `^/(pricing
Everything except the blog Page View, Some Page Views Page Path does not start with /blog
Only one subdomain Page View, Some Page Views Page Hostname equals app.example.com

On a single-page app, a Page View trigger fires once per full page load, so a route-based trigger only applies on the first page a visitor lands on. Once loaded, the widget stays across in-app navigation. For SPAs, it’s simpler to load it everywhere, or to install it in code (see the React guide).

Open the chat from a button

Add a second Custom HTML tag, triggered on All Pages, that defines the queue stub:

<script>
window.Feedbot = window.Feedbot || function () { (Feedbot.q = Feedbot.q || []).push(arguments) };
</script>

Then any link or button on the site can call Feedbot('open') or Feedbot('sendMessage', 'I have a question about pricing'). See the JavaScript API.

Identify logged-in users

If your site pushes user data to the dataLayer, for example:

dataLayer.push({ userId: "u_123", userEmail: "[email protected]", feedbotHash: "HASH_FROM_YOUR_SERVER" });

create Data Layer Variables for those keys and add a Custom HTML tag:

<script>
window.Feedbot = window.Feedbot || function () { (Feedbot.q = Feedbot.q || []).push(arguments) };
Feedbot("identify", { userId: {{DLV - userId}}, email: {{DLV - userEmail}}, hash: {{DLV - feedbotHash}} });
</script>

GTM inserts variable values as JavaScript values, so don’t wrap {{...}} in quotes. Fire the tag on a Custom Event trigger matching the event your site pushes after login. The hash must be computed on your server; the secret never goes into GTM. See Identify users.

GTM’s consent settings can hold the tag until the visitor agrees. Open the tag, go to Advanced Settings → Consent Settings, select Require additional consent for tag to fire and add functionality_storage. Google explains the options in consent mode support. The widget keeps a visitor id in local storage, so decide with your privacy policy whether chat counts as functional. If you gate it, visitors who decline won’t see the chat; a hosted chat link on your contact page is a fallback.

Troubleshooting

Symptom Cause Fix
Works in Preview, not on the live site Container not published Click Submit → Publish.
Tag fired, no button Bot id typo, or domain not in Allowed domains Check the console for [Feedbot] errors. Add your domain in Bot → Install → Allowed domains.
Tag never fires Trigger condition too narrow, or consent not granted Check Tags Not Fired in Tag Assistant and the consent state.
Wrong bot appears Script also hardcoded in the site with another bot id; the first one loaded wins Remove the hardcoded copy.
Blocked by CSP Strict policy Allow https://w.feedbotai.com in script-src and https://api.feedbotai.com in connect-src.

Train it on your site

On Free, the bot learns from text and FAQ you add. From Starter, import your website by URL or sitemap and upload files. See knowledge base.

Next steps

  • Install docs for data-* options like position, color and language.
  • Running Ghost or Bubble? Their built-in code fields are an alternative to GTM: Ghost, Bubble.

Questions

Can't find an answer? Ask the bot in the corner, or write to us.

Can I add a chatbot through Google Tag Manager?

Yes. Any chatbot that installs with a script tag can go in a GTM Custom HTML tag. For Feedbot, paste the one-line script into the tag, trigger it on All Pages and publish the container.

Can I show the chatbot only on some pages with GTM?

Yes. Instead of All Pages, create a Page View trigger that fires on Some Page Views, with a condition such as Page Path starts with /pricing. The tag loads only where the trigger matches.

Does the chatbot need consent under GDPR or consent mode?

The widget stores a visitor id in the browser's local storage so the conversation survives reloads. Whether that needs consent depends on your legal basis; many sites treat a requested support chat as functional. If you gate it, require functionality_storage in the tag's consent settings.

Will adding the chatbot via GTM slow down my site?

The loader is about 6 KB gzipped, runs asynchronously and loads the chat only on hover, click or idle time. GTM adds its own small delay, so the button may appear a moment later than with a hardcoded tag.

Can I identify logged-in users through GTM?

Yes, if your site pushes the user id and a server-computed hash to the dataLayer. Read them with Data Layer Variables and call Feedbot('identify', ...) in a second Custom HTML tag.

Keep exploring

Put one agent on your site today

Start on the free plan. Upgrade when conversations grow.