This easy-to-follow tutorial will show you how to deploy the noindex meta robots tag on a URL using Google Tag Manager and jQuery. This method is useful for digital marketers and SEO professionals that unfortunately do not have access to edit the DOM head on a client's website. Which can be an all too often common occurrence.
Usages of this tag:
This method overrides any existing meta robots tag as well as injecting a fresh meta robots tag if there was no meta robots tag present in the DOM head.
Step 1 - Log in to GTM and create a new tag. We are going to name the tag NoIndex MetaRobots, although, you can set the tag name to whatever you like. The tag configuration type is Custom HTML. Next, paste the following JavaScript snippet into the text editor box.
Step 2 - Next up is the firing trigger configuration, I have named this trigger NoIndex MetaRobots trigger. Set the trigger type as 'Page View DOM Ready'. We want the trigger to fire on 'Some DOM ready events' (do not set it all DOM ready events). The event conditions are 'Page URL' > 'Contains' > /url-goes-here/ save the trigger.
Step 3 - You can now publish the new tag and trigger to your live GTM container. View the rendered HTML to the page that you have deployed the tag to fire on (refresh browser window if you already had it open. Also, there is a big difference to view the page source and viewing the rendered HTML. I use a Chrome extension called 'View Rendered Source'.
Here is it in practice
The method above requires jquery 3.0 or newer. You can check the jquery version by entering this snippet in the browser console.
One final point. If you need to deploy the noindex tag on multiple URLs, then using a lookup table will save you time. Thanks for reading, feel free to comment below.
Usages of this tag:
- Noindex thin and low-quality pages (old blog posts, etc)
- Noindex rogue facetted/parameter URLs
- Noindex duplicate content URLs
This method overrides any existing meta robots tag as well as injecting a fresh meta robots tag if there was no meta robots tag present in the DOM head.
Step 1 - Log in to GTM and create a new tag. We are going to name the tag NoIndex MetaRobots, although, you can set the tag name to whatever you like. The tag configuration type is Custom HTML. Next, paste the following JavaScript snippet into the text editor box.
Code:
<script>
jQuery('meta[name="robots"]').remove();
var meta = document.createElement('meta');
meta.name = 'robots';
meta.content = 'noindex';
jQuery('head').append(meta);
</script>
Step 2 - Next up is the firing trigger configuration, I have named this trigger NoIndex MetaRobots trigger. Set the trigger type as 'Page View DOM Ready'. We want the trigger to fire on 'Some DOM ready events' (do not set it all DOM ready events). The event conditions are 'Page URL' > 'Contains' > /url-goes-here/ save the trigger.
Step 3 - You can now publish the new tag and trigger to your live GTM container. View the rendered HTML to the page that you have deployed the tag to fire on (refresh browser window if you already had it open. Also, there is a big difference to view the page source and viewing the rendered HTML. I use a Chrome extension called 'View Rendered Source'.
Here is it in practice
The method above requires jquery 3.0 or newer. You can check the jquery version by entering this snippet in the browser console.
Code:
jQuery.fn.jquery
One final point. If you need to deploy the noindex tag on multiple URLs, then using a lookup table will save you time. Thanks for reading, feel free to comment below.
Attachments
Last edited: