On this page
Use Google Tag Manager (GTM) to add the tracking snippet to your website. Create a Custom HTML tag, configure when it can run, test it in Preview, then publish the container and check your first visit in CUX.
This guide is for a web container already installed on your website. Installing the snippet through GTM and enabling dataLayer Capture are separate tasks.
Before you start
You need access to your website's GTM container, permission to publish it, and a CUX website project.
Check whether the snippet is already installed directly, through a plugin or through another tag. Use one installation method for the same project on a page. Adding another copy can initialize tracking more than once.
If your site requires consent before analytics starts, have your consent setup ready before enabling the tag.
Copy your project's snippet
- Open the website project you want to collect data for.
- Go to Project Settings > Data Collection.
- Copy the complete Tracking Code, including the opening and closing
<script>tags.
Use the snippet from that project rather than copying an example token from an article. For a website spanning subdomains, check Cross-subdomain Tracking before copying the code. See where to find your snippet for related guidance.
Create a Custom HTML tag
- In GTM, open the web container installed on this website.
- Select Tags > New.
- Give the tag a recognizable name, such as CUX tracking.
- Select Tag Configuration > Custom HTML.
- Paste the complete snippet into the HTML field.
Google's Custom HTML instructions explain this tag type.
Configure when the tag runs
Choose a trigger for the pages you intend to record. All Pages covers page loads, but use it only with the collection conditions your website needs. Add exceptions for pages you deliberately exclude.
If collection depends on consent, configure the required checks under Advanced Settings > Consent Settings or use your consent management platform's documented trigger setup. Do not assume that pasting a snippet into Custom HTML makes it follow Google Consent Mode automatically.
Not set does not add a consent check. With Require additional consent for tag to fire, GTM checks the specified consent types when the trigger runs. Your consent platform must also provide a trigger opportunity after a visitor grants consent on the current page. Confirm this behavior with the person responsible for your consent setup. See Google's consent settings guide.
These checks control tag startup; changing a GTM consent condition does not unload a script that is already running. If visitors can withdraw consent, also test your website's collection-stop behavior.
Configure one initialization of the snippet per page. On a single-page application, do not reload the snippet on every virtual navigation. Include those navigation changes in your test journey.
Save the tag after configuring its trigger and consent conditions.
Test with Preview and Tag Assistant
- Select Preview in the GTM workspace.
- In Tag Assistant, enter a test page URL and select Connect.
- Follow the prompts to connect the website to the debug session.
- Perform a short journey with synthetic data. Check the events in Tag Assistant to see when CUX tracking fires.
- If consent is required, test both a fresh visit without consent and a visit where consent is granted. Confirm the tag stays blocked until the required choice is made, then runs without requiring an unrelated page reload.
- Check another page and, if applicable, navigation within your single-page application. Confirm the snippet is not initialized repeatedly on the same page.
Use Google's Preview guide if the debug session does not connect.
A fired tag shows that GTM ran the tag. You still need to check that the collector loaded and data reached your project. Preview changes are not yet published for regular visitors.
Publish the container
When the test passes:
- In GTM, select Submit.
- Choose Publish and Create Version.
- Add a version name and description identifying the tracking change.
- Review the workspace changes, then select Publish.
Follow your team's approval process if someone else publishes the container. Saving a tag or creating a version without publishing does not make it active for regular visitors. See Google's publishing instructions.
Verify the published installation
End the Preview session and open the website normally. Repeat the short test journey under the intended consent conditions.
In CUX, open Visits in the same project and select the date range containing your test. Find the visit and check its pages and interactions. Data may need processing before it appears; a missing visit does not by itself identify the cause.
If no matching visit appears, check:
- The correct GTM container version is published and installed on the test page.
- The tag's trigger, exceptions and consent conditions allow it to run for this test.
- The snippet belongs to the project you are viewing and has not been added twice.
- Browser extensions or your site's Content Security Policy are not blocking the collector or its connections.
- Your test traffic is not excluded by project settings, and the selected date range includes the test.
Ask your developer to inspect script and connection failures if the tag fires but the visit is missing. Keep the site's security and consent controls in place while diagnosing the problem. Continue with web tracking troubleshooting or submit a support ticket with the project ID, test URL, test time and checks you have completed.