FLAT
70% OFF
Black Friday Sale
17d 09h 11m
Grab Now
17 days, 9 hours and 11 minutes left.

Google Tag Manager, Microsoft Clarity and custom code

Add Google Tag Manager, Microsoft Clarity and your own head, body and footer code to every front-end page, without editing theme files.

Updated 4 min read
On this page

The Code and tracking tab adds tracking tags and your own code to your site's front-end pages. You don't need to edit your theme or install a separate header and footer plugin.

Everything is empty by default. Nothing is added to your site until you fill in a field.

What you can add

Field What RankFlect SEO adds Where
Google Tag Manager container ID The Tag Manager container snippet, and its noscript part. The snippet in the head; the noscript part right after the opening body tag.
Microsoft Clarity project ID The Clarity tracking code. The head.
Code in the head Your code, as you enter it. Inside <head>.
Code after the body opens Your code, as you enter it. Right after <body>. Needs a theme that supports wp_body_open (most current themes do).
Code before the body closes Your code, as you enter it. Just before </body>.

Code is only added to front-end pages. It is never added in wp-admin, feeds, sitemaps, robots.txt, embeds or REST API responses.

Add Google Tag Manager

  1. In Google Tag Manager, open your container and copy its ID. It starts with GTM-, for example GTM-ABC1234.
  2. In WordPress, go to RankFlect SEO → Settings → Code and tracking.
  3. In the Tracking tags card, paste the ID into Google Tag Manager container ID.
  4. Click Save changes.

RankFlect SEO checks the ID before saving. If it does not look like a container ID, the field shows "This does not look like a container ID. It starts with GTM- and is not saved until it is valid."

What is sent to Google

Visitors' browsers load www.googletagmanager.com/gtm.js (or ns.html when JavaScript is off). Tag Manager then runs the tags you set up in your container. What those tags send, and to whom, depends on your container, not on RankFlect SEO.

Important If you also have a GA4 Measurement ID in Settings → Webmaster tools and your Tag Manager container loads GA4 too, every visit is counted twice. RankFlect SEO shows a note on the card when both are set. Remove one of them. See Add the Google Analytics 4 tag.

Add Microsoft Clarity

  1. In Microsoft Clarity, open your project and go to Settings → Overview. Copy the Project ID.
  2. In WordPress, go to RankFlect SEO → Settings → Code and tracking.
  3. Paste the ID into Microsoft Clarity project ID.
  4. Click Save changes.

The ID has letters and numbers only. An ID that does not match is not saved.

What is sent to Microsoft

Visitors' browsers load www.clarity.ms/tag, which sends page views, clicks, scrolling and browser data to Microsoft. If your site needs consent before this kind of tracking, check your consent setup before you add the ID.

Add your own code

Use the Custom code card for anything else: another analytics tool, a chat widget, a verification snippet or a small style.

  1. Go to RankFlect SEO → Settings → Code and tracking.
  2. Paste your code into Code in the head, Code after the body opens or Code before the body closes.
  3. Click Save changes.

Important "Code here runs for every visitor. Only paste code from sources you trust; a broken script can break your pages." If a page breaks after a change, empty the field and save again.

Keep your own visits out

Do not load for logged-in editors and admins is on by default. While it is on, the tags and the custom code are not added for logged-in users who can edit posts (contributors, authors, editors and administrators). Your own visits are not tracked.

To check that the code is on your pages, view the page source in a private window, or turn the setting off for a moment.

Who can change custom code

Custom code is powerful, so RankFlect SEO limits who can change it:

  • Only users who can post unfiltered HTML can save custom code. On a normal single site that is administrators. On multisite, only super admins. If DISALLOW_UNFILTERED_HTML is set in wp-config.php, nobody can.
  • For everyone else, the custom code fields are read-only with the note "Only administrators who can post unfiltered HTML can change custom code." They can still save the Tag Manager and Clarity IDs.
  • AI agents can never change this tab, even with an administrator's token. Requests over MCP and Application Passwords are refused. See Approval mode, dry runs and undo.
  • Settings imports skip custom code for users who cannot save it.

FAQ

Does this replace the GA4 tag in Webmaster tools?

No. The GA4 tag stays where it was. Use one or the other for GA4: either the GA4 Measurement ID, or a GA4 tag inside your Tag Manager container.

No. If your site must ask for consent first, add your tags through your consent management tool, or set up consent in your Tag Manager container.

My code after the body opens does not show up. Why?

Your theme probably does not call wp_body_open. Move the code to Code in the head or Code before the body closes, or ask your theme developer to add the hook.

Is this a Pro feature?

No. Code and tracking is free in RankFlect SEO.

Was this page helpful?

Still need help?

Email us with your WordPress and RankFlect SEO versions and what you tried. Pro customers get priority replies.

Contact support