How to Add Google Analytics to Your Docs
DocStar lets you add Google Analytics to your docs without touching a line of code: you paste one Google Tag Manager (GTM) ID into a collection, and every public page of your help center, API docs or blog starts sending
DocStar lets you add Google Analytics to your docs without touching a line of code: you paste one Google Tag Manager (GTM) ID into a collection, and every public page of your help center, API docs or blog starts sending data to the tags you manage in GTM. With the DocStar MCP connected, your AI agent can do the DocStar side for you across every collection in one prompt, check that it worked, and hand you a baseline from DocStar's own analytics to compare against.
This guide covers how it works, the agent-first setup we recommend, what only you can do, and how to keep tracking accurate as your docs grow.
How Google Analytics works on DocStar docs
DocStar doesn't ask you to paste a tracking script into a theme file. Each collection has a Google Tag Manager ID setting. Once you save a valid ID, the GTM container loads on every public page of that collection right away. From there, Google Analytics, ad pixels, chat widgets or any other tag you configure in GTM run on your docs, and you change them in GTM, not in DocStar.
| What you want | Where it lives |
|---|---|
| Google Analytics, ad pixels, chat widgets | Tags in your GTM container |
| Connecting that container to your docs | The collection's Google Tag Manager ID in DocStar |
| Reads, feedback, SEO score, UTM sources per page | DocStar's built-in Analytics dashboard, no setup needed |
| Which docs page sent a visitor to your website | DocStar's outbound link tagging (utm_source) |
A few details from our Google Tag Manager help page worth knowing up front:
The ID must be
GTM-followed by 6 to 8 capital letters or numbers. Lowercase letters or extra spaces are rejected.Tags run on your public docs only, not inside the DocStar editor, so your team's editing doesn't pollute your numbers.
GTM is the recommended place for scripts. Keep your header and footer for logos and links, and put tracking in GTM.
Why GTM and DocStar Analytics work better together
You don't have to choose. DocStar already counts reads, collects "Was this helpful?" votes and comments, scores every published page for SEO, and records UTM parameters on every visit. That's the docs-specific view: which pages people read and which ones fail them. Our guide on documentation analytics shows how to act on it.
Google Analytics adds the view your marketing and growth teams already use: sessions, traffic channels, and how docs readers move into your product. DocStar connects the two with outbound link tagging. When a reader clicks a link on your docs that points to your own main domain, for example from docs.example.com to example.com/pricing, DocStar adds utm_source with the docs page URL. Your website analytics then show exactly which docs page sent that visitor.
That's the question most teams actually want answered: which docs pages bring people to pricing and sign-up?
Add Google Analytics to your docs with your AI agent
This is the workflow we recommend. DocStar's API covers everything you can do in the DocStar UI, including the collection's GTM ID, so an agent connected to the DocStar MCP can set it on every collection, check it, and report back.
Step 1: Create your GTM container (you)
This part happens in Google's tools, so it's yours:
In Google Tag Manager, create a container for your docs site, or reuse your website's container if you want docs and site in one place.
Inside that container, add your Google Analytics tag and any other tags you need.
Copy the container ID. It looks like
GTM-ABC1234.
Step 2: Connect your agent to DocStar
Add DocStar to Claude Code, Cursor, Codex or another assistant. If DocStar is in your assistant's connector directory, connect it from there. Otherwise add it as a custom remote MCP server:
https://mcp.docstar.io/mcp
The first time the agent needs your workspace, you sign in to DocStar in your browser. There's no API key to copy, and the agent only sees the workspaces and collections your account can access, with your permissions. Full steps are in Connect Your AI Assistant.
Step 3: Give it one prompt
Paste something like this, with your own container ID:
Use the DocStar MCP. List the collections in our workspace and tell me which ones are public docs (help center, API docs, blog). Set the Google Tag Manager ID on each of them to GTM-ABC1234. First check the ID matches the format GTM- plus 6 to 8 capital letters or numbers, show me exactly which collections you'll change, and wait for my OK. After saving, read each collection back and confirm the GTM ID is set. Then pull last month's reads and UTM sources for our 10 most-read pages so I have a baseline to compare with Google Analytics.
Step 4: What the agent does
With that prompt, the agent:
Finds your collections and separates public docs from internal ones.
Validates the ID against the format DocStar accepts, so a stray space or lowercase letter doesn't fail silently.
Shows you its plan and waits. The DocStar MCP is built so the assistant asks before it changes anything.
Sets the GTM ID on each collection you approved.
Reads each collection back to confirm the ID saved, instead of assuming it did.
Builds your baseline from DocStar Analytics: reads and UTM sources for your top pages.
One honest note: unlike page edits, which an agent saves as drafts, a GTM ID takes effect on your public pages as soon as it's saved. That's why the prompt asks the agent to show its plan first. Approve only the collections you mean.
Step 5: Check it works (you)
In Google Tag Manager, click Preview and enter your docs URL.
Open a few pages and confirm your tags fire.
Publish your container in GTM so the tags go live for every reader.
If your docs are on the default DocStar link, consider a custom domain too. Pages on the default link are marked noindex, so search traffic only shows up once your docs live on your own domain. Our guide to launching a help center on your own domain walks through it.
What stays with you
The agent handles the DocStar setup and the checking. A few calls belong to a person:
Your GTM container and tags. Creating the container, choosing which tags run and publishing it happens in your Google account.
Privacy and consent. Make sure your tracking follows your privacy policy and any cookie consent rules for your readers. That's a judgment call, not a setting.
Which collections to track. Internal docs, password-protected docs or a staging collection may not belong in your marketing analytics. You decide.
What the numbers mean. The agent can compare reports. You decide which pages to invest in.
Keep it current
Tracking breaks quietly: someone creates a new collection, swaps containers, or moves links around, and the numbers drift. With DocStar, keeping it right is a prompt, not a project.
New collections. When you launch a new docs site or blog in DocStar, ask your agent: "Set our GTM ID on the new collection and confirm it." Add a line to your team's AGENTS.md so coding agents do it every time they create a collection.
Changing containers. If you move to a new GTM container, one prompt updates every collection and reads them back. DocStar replaces the old ID the moment the new one is saved.
Monthly check. Ask the agent to "compare last month's DocStar reads and UTM sources with the baseline, and flag pages whose reads dropped". Pair it with your Google Analytics report to see which docs pages still send visitors to pricing and sign-up.
Tag the links you share. Ask the agent to add UTM parameters to links in new release notes and changelog drafts, so DocStar's UTM tracking shows which channels bring readers in. Our changelog guide covers writing release notes people read.
Prefer to click?
You can do the same in a minute by hand. Open the collection, click Settings in the left sidebar, open the Google Tag Manager tab, paste your container ID into the Google Tag Manager ID field and click Save. You'll see "Saved & Published Successfuly", and the container loads on your public pages right away. Repeat for each collection, then test with GTM Preview.
Why teams choose DocStar
No code to add tracking. One GTM ID per collection, no theme files, no script tags in your header.
Analytics built in. Reads, feedback, SEO scores and UTM sources are recorded on every published page with nothing to install. See Analytics.
Docs-to-site attribution. Outbound links to your main domain are tagged with the docs page they came from.
Agent-ready. The DocStar MCP lets Claude Code, Cursor or Codex set up and check tracking across every collection, with browser sign-in and your own permissions.
One workspace. API docs, help docs, FAQs, changelog and blog live together, each with its own MCP server, sitemap, llms.txt and Markdown copy of every page.
FAQ
Do I need to add any code to use Google Analytics with DocStar? No. You add a Google Tag Manager ID to the collection's settings, and you manage Google Analytics and other tags inside GTM. DocStar loads the container on every public page.
Will my team's editing show up in Google Analytics? No. GTM tags run on your public docs only, not inside the DocStar editor.
Can my AI agent set the GTM ID for me? Yes. Connect your agent to the DocStar MCP and ask it to set the ID on the collections you choose. It asks before changing anything and can read each collection back to confirm. The ID takes effect on public pages as soon as it's saved.
Do I still need DocStar Analytics if I use Google Analytics? They answer different questions. DocStar Analytics shows reads, "Was this helpful?" feedback, SEO scores and UTM sources per page with no setup. Google Analytics shows how docs traffic fits into your wider site and product funnel.
Why does DocStar say my GTM ID is invalid? The ID must be GTM- followed by 6 to 8 capital letters or numbers. Check for extra spaces or lowercase letters.
Get started free
Your docs are often the first place people meet your product. With DocStar, you can see who reads them and where they go next, and your AI agent sets it up in one prompt. Get started free and connect your docs to Google Analytics today.
Originally published on the DocStar blog. Try DocStar free: https://docstar.io
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.