Short answer: in Google Tag Manager, go to Tags → New → Custom HTML, paste your chat snippet, attach the All Pages trigger, check it in Preview, then Submit and Publish. Before you publish, decide two more things that most install guides leave out: whether the tag should wait for cookie consent, and on which hostnames or pages it must not load (staging, admin, embedded pages).
This guide uses the Shopxare Messenger as the example, but the steps are the same for any chat widget that gives you a <script> snippet. Menu names are from the English Tag Manager interface.

When Tag Manager is the right way, and when it isn't
Tag Manager is a good home for a chat widget when you have no platform plugin, when marketing already manages scripts there, or when one container serves several sites. It is the wrong choice when a platform app does more than a snippet can.
| Your site | Better option | Why |
|---|---|---|
| WordPress / WooCommerce | The plugin | Logged-in users are verified and WooCommerce orders and carts appear next to the chat (guide) |
| Shopify | Theme snippet | Recognises logged-in customers and connects orders (guide) |
| ikas | The ikas app | One click, no code (guide) |
| Custom site, landing pages, several domains | Google Tag Manager | One place for all scripts, consent and page rules |
If your site doesn't have a Tag Manager container yet, adding one only for chat adds a layer you have to maintain. Paste the snippet into the site template instead (how to add live chat to a website).
Before you start
- The Tag Manager container snippet is on every page of the site. Open a few pages with Preview later to confirm.
- You can publish in that container. Without publish rights you can build the tag, but someone else has to release it.
- You have your chat snippet. In Shopxare it is on the install screen, with your App ID filled in (Install the Messenger).
Step 1: create a Custom HTML tag
- Open your container and go to Tags → New.
- Name it so it's easy to find later, for example
Chat – Shopxare Messenger. - Click Tag Configuration and choose Custom HTML.
- Paste the snippet:
<script>
window.Shopxare = window.Shopxare || function () { (Shopxare.q = Shopxare.q || []).push(arguments) };
Shopxare('boot', { app_id: 'YOUR_APP_ID' });
</script>
<script async src="https://app.shopxare.com/widget/v1/loader.js"></script>
Leave Support document.write off. Google's help page says it is only needed when your code calls document.write(), and this snippet doesn't (Custom tags, Tag Manager Help). Tag Manager also minifies Custom HTML and may turn single quotes into double quotes. That is harmless here.
Step 2: trigger and exceptions
Under Triggering, pick All Pages. Then add exceptions, the part people forget. An exception is a trigger that blocks the tag even when the firing trigger matches.
Create a trigger of type Page View → Some Page Views for each rule below and add it under Exceptions:
| Exception | Condition (built-in variable) | Reason |
|---|---|---|
| Staging and preview domains | Page Hostname contains staging (or your test domain) |
Otherwise test visits open real conversations in your inbox |
| Admin and back office | Page Path starts with /admin |
Your team doesn't need the launcher over their tools |
| Embedded pages | Page URL contains embed= |
A launcher inside an iframe looks broken |
Keep chat on the cart and checkout. That is where a delivery or payment question stops a purchase, so it is the last place you want the launcher to disappear. If the round launcher covers a button on mobile, open the chat from your own button instead (hide_default_launcher in the JavaScript API) rather than removing chat from the page.
Step 3: decide about consent
Custom HTML tags have no built-in consent check. Tag Manager fires them as soon as the trigger matches, unless you add one. In the tag, open Advanced Settings → Consent Settings and choose Require additional consent for tag to fire, then add functionality_storage. The tag then waits until that consent type is granted (Tag Manager consent mode support).
This only works if your cookie banner sends consent mode signals to Tag Manager. Most consent platforms have a Tag Manager template for that. To see every tag's consent status in one list, turn on Admin → Container Settings → Enable consent overview.
Whether a chat needs consent at all depends on your country and on what the widget stores. We cover that in Is your live chat GDPR compliant?. The trade-off to keep in mind: with a consent gate, visitors who decline cookies see no chat. Put your support email or a contact page link in the footer so they still have a way to reach you.
Step 4: test in Preview
Click Preview in the workspace. Tag Assistant opens your site in a new tab and shows which tags fired and what triggered them (Preview and debug containers). Check four things:
- On a normal page, the chat tag fired and the launcher appears.
- On a staging URL or
/adminpage, the tag did not fire. - With cookies declined (if you set a consent check), the tag waits, and fires after you accept.
- Send a test message and see it arrive in the inbox.
Step 5: submit and publish
Click Submit, give the version a clear name such as Add live chat (Messenger) with staging exception, and click Publish. If anything goes wrong later, you can go back to the previous version under Versions.
Logged-in customers: pass the ID through the data layer
When a customer is signed in, your team should see who they are without asking. In Shopxare that is identity verification: you send a user_id and a user_hash, an HMAC-SHA256 of the ID computed on your server (Identity verification).
Tag Manager can carry those values, but it must never create the hash. Anyone can read a published container, so the secret stays on your server. Have your site push the values before the container snippet:
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({ user_id: '42', user_hash: 'HASH_FROM_YOUR_SERVER' });
</script>
Create two Data Layer Variable variables (DL - user_id, DL - user_hash) and change the boot line in the tag:
<script>
window.Shopxare = window.Shopxare || function () { (Shopxare.q = Shopxare.q || []).push(arguments) };
var cfg = { app_id: 'YOUR_APP_ID' };
var uid = {{DL - user_id}};
if (uid) { cfg.user_id = String(uid); cfg.user_hash = {{DL - user_hash}}; }
Shopxare('boot', cfg);
</script>
<script async src="https://app.shopxare.com/widget/v1/loader.js"></script>
On logout, call Shopxare('shutdown') so the next person on the same browser can't see earlier conversations (JavaScript API).
Single-page apps
If your shop is built with React, Vue or a similar framework, don't add a History Change trigger to the chat tag. The Messenger notices page changes in single-page apps by itself, and firing the tag again would boot it twice. One page view per full load is enough.
Example: a small ceramics shop
A shop on a custom-built site sells handmade mugs and runs a staging copy at staging.shop.example. Its consent banner already sends consent mode signals. The owner sets up the tag with All Pages, a hostname exception for staging, and a consent check on functionality_storage. In Preview the tag waits on the banner, fires after "Accept", and stays silent on staging.
The first real chat comes in that evening:
Visitor: Is the blue mug dishwasher safe? Shop: Yes, all our glazes are dishwasher safe. Hand washing keeps the colour bright for longer. Shall I check if the blue one is in stock in the larger size?
If the chat doesn't show up
| What you see | Likely cause | Fix |
|---|---|---|
| Tag didn't fire in Preview | Wrong trigger, or an exception matches | Check the trigger conditions on that URL |
| Tag fired, no launcher | Your domain isn't in the allowed list | Add it under Messenger security settings (Customize the Messenger) |
| Works in Preview, not live | Version not published | Submit → Publish |
| Two launchers | Snippet also in the theme or a plugin | Remove one of them |
| Tag waits forever | Banner doesn't send consent signals | Install your consent platform's Tag Manager template |
The Messenger is included in Shopxare's Free plan. If you want to try these steps on your own site, start free and follow the install guide.
FAQ
Can you add live chat with Google Tag Manager?
Yes. Most chat widgets load from a script snippet, and Tag Manager can place that snippet with a Custom HTML tag on the pages you choose. Platform plugins can do more (orders, verified customers), so use them when your platform has one.
Which trigger should a live chat tag use?
All Pages (Page View) with exceptions for staging, admin and embedded pages. Avoid History Change triggers unless your chat vendor tells you to, because they can load the widget twice.
Does live chat need cookie consent?
It depends on your country and on what the widget stores in the browser. If your banner blocks functional storage, add a consent check on functionality_storage in Consent Settings. Our GDPR checklist goes through the details.
How do I hide the chat on certain pages?
Add a Some Page Views trigger with a Page Path or Page URL condition and put it under Exceptions in the chat tag.
Why does my chat appear twice?
The snippet is loaded from two places, usually the theme or a plugin plus Tag Manager. Keep one.