Can You Use Javascript/GTM to Add a Noindex Meta Robots Tag?

Can you use Google Tag Manager to add a noindex tag for SEO?

Published: Last updated:

By:

Robot

Robot illustration - kaboompics

Earlier this month Google published a new JavaScript SEO basics document.

Understand the JavaScript SEO basics @ Google Developers' Portal (external link)

The guide was created by Google's Martin Splitt and Lizzi Harvey.

A question on BigSEO as to whether or not it is possible to use Google Tag Manager (GTM) to add a robots meta tag to pages was submitted recently, and one area that the guide covers in using JavaScript to add or change meta robots tags - so we took a look at the new resources for an answer.

When Googlebot encounters "noindex" in the robots meta tag, it doesn't render or index the page.

Using JavaScript to change or remove the robots meta tag might not work as expected. Googlebot skips rendering and JavaScript execution if the meta robots tag initially contains "noindex". If you want to use JavaScript to change the content of the robots meta tag, do not set the meta tag's value to "noindex".

From this we can infer that it is possible to add a robots meta tag/attribute to a page, as long as the page does not already have a robots noindex tag - because in this case Google will not render or index the URL in the first instance.

We wanted to be 100% sure of this, so submitted feedback to Google via Twitter that the documentation could be a little clearer.

Barry Schwartz at Search Engine Roundtable pushed the feedback direct to Martin and Lizzi.

Martin Splitt replied, confirming that this interpretation is correct - that yes, it is possible to add or change a meta robots tag - as long as the page doesn't already have a noindex meta robots tag in place.

Thanks, that's great feedback! We will make this clear. You can use JS (also without jQuery) to add or change the robots meta tag. The exception is using JS to change the tag when it was initially "noindex", because rendering is skipped then.

So if you are searching for an answer to the question of whether or not it is possible to do this via JavaScript or GTM, you now have a clear answer - but it should still be considered that adding meta robots attributes via JavaScript is not necessarily a good idea.

Google have now confirmed that they will try to honour the directive in certain circumstances if found in JavaScript, but this 'may not work as expected', and it should always be considered that Google is not the only search engine.

Update (13th August 2019): Google have updated the JS SEO Basics document to include a clear statement on JS meta noindex usage, and an example.

Direct from the docs:

You can prevent Googlebot from indexing a page or following links through the meta robots tag.

Also an example usage is included on the page, whereby a meta noindex tag is supplied via JS after an API fails to provide a response.

chevron-down