Install with Google Tag Manager
Deploy the SiteTrellis chat widget through a Google Tag Manager Custom HTML tag with the right trigger, consent settings, and preview testing.
Last updated:
If your marketing team already manages scripts with Google Tag Manager (GTM), you can deploy the SiteTrellis widget as a Custom HTML tag without changing your site's code. GTM's interface is updated often, so the names below are a guide; the Tag Manager Help Center has the current screens.
Create the tag#
- In your GTM container open Tags and click New.
- Name it "SiteTrellis chat widget".
- Click Tag Configuration and choose Custom HTML.
- Paste the snippet from the SiteTrellis dashboard into the HTML box.
- Leave Support document.write unchecked.
- Under Advanced Settings > Tag firing options choose Once per page.
<script src="https://cdn.sitetrellis.com/v/a44108d9c4521120/widget.js" data-site="site_xxxxxxxx" async></script>
Choose the trigger#
Click Triggering and pick one of:
- All Pages (the built-in "Page View" trigger): fires as soon as GTM runs. A good default.
- Window Loaded: waits until the page has fully loaded, which keeps the chat out of your performance-critical path.
- A custom trigger that matches certain URLs, if the chat should only appear on some pages. Alternatively keep the trigger broad and use SiteTrellis page rules, which you can change without republishing the container.
For single-page applications, the Page View trigger fires once on the first load, which is what you want. Do not use History Change triggers to fire this tag, or you will load the widget repeatedly.
Consent and privacy settings#
The widget stores a small amount of data in the visitor's browser (a session identifier so the conversation continues across pages) and sends the chat to your AI provider. Whether that needs prior consent depends on your jurisdiction and policy; many sites treat it as functional, others as requiring opt-in. This is not legal advice. If you need consent first:
- In the tag's Advanced Settings > Consent Settings, require additional consent for the storage types your policy ties to chat (for example functional storage), so the tag only fires once the visitor has granted it. If you use a consent management platform with Consent Mode, make sure it updates consent before this tag's trigger.
- Alternatively fire the tag from a custom event your consent banner pushes to the data layer.
- The widget also has its own optional consent notice setting (
collect_consentwithconsent_text). See Widget customization.
// Your consent banner, after the visitor accepts functional cookies:
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ event: 'consent_functional_granted' });
// In GTM: create a Custom Event trigger named consent_functional_granted
// and attach it to the SiteTrellis tag instead of All Pages.
Pass data from the data layer (optional)#
You can tell the agent who the visitor is by adding a second Custom HTML tag that fires after the SiteTrellis tag (use tag sequencing under Advanced Settings so it fires after) and reads a GTM variable:
<script>
(function () {
var info = { name: {{DLV - user name}}, email: {{DLV - user email}} };
function go() { window.SiteTrellis('identify', info); }
if (window.SiteTrellis) { go(); return; }
var s = document.querySelector('script[data-site]');
if (s) s.addEventListener('load', go);
})();
</script>
The double-brace tokens are GTM variables that you define, not SiteTrellis variables. Values from the browser are not verified. See Widget JavaScript API.
Test and publish#
- Click Preview in GTM and open your site in the debugging window. Tag Assistant should show "SiteTrellis chat widget" as Tag Fired.
- Check the launcher appears, and in the browser's Network tab that
widget.jsand the config request both return 200. - Make sure your site's origin is in the SiteTrellis Allowed origins list.
- Click Submit in GTM to publish the container version. Nothing changes on the live site until you do.
Troubleshooting GTM installs#
| Symptom | Cause and fix |
|---|---|
| Tag fired in Preview but not live | The container version was not published, or an old container snippet is cached. |
| Tag does not fire | Consent settings are blocking it, a trigger exception applies, or the container snippet is missing on the page. |
| Launcher missing for visitors with ad blockers | Some blockers block GTM itself; the widget cannot load. Direct installation is more resilient. |
| Content Security Policy errors | Allow the widget and API hosts. See Install on any website. |