Tag Manager - Crawl Rate - On Page SEO

How To:  Automatically Noindex Expired Event Pages Using GTM

Calendar

TL;DR:
If your website has expired event pages that need to remain accessible to users but no longer need to appear in Google, you can use Google Tag Manager to noindex them automatically. I did this by reading the event date from the page, comparing it with the current date and adding a robots noindex directive once the event had passed. This should only be used where you’ve deliberately decided expired events no longer need to remain indexed.

Why I needed to automatically noindex expired events

Event websites can accumulate hundreds or even thousands of old event pages over time.

Sometimes there’s a good reason to keep those pages available to users. A venue, for example, may want to retain an archive showing previous events rather than deleting the pages once each event has finished.

That doesn’t necessarily mean every expired event page needs to remain indexed by Google.

I encountered exactly this problem while working as a Google Tag Manager consultant for a client whose website contained several years of historical events. The client wanted to keep the old event pages on the website, but we didn’t need those expired pages continuing to appear in search.

Manually adding a noindex tag to every event once it had passed wasn’t realistic. It would require ongoing housekeeping and would inevitably be forgotten.

Instead, I used Google Tag Manager to read the event date from the page, compare it with the current date and automatically add a robots noindex directive once the event had expired.

This is a specific implementation of the broader technique I’ve covered in my guide to adding a noindex tag using Google Tag Manager.

One important point before using this approach: don’t automatically noindex old content simply because it has a date in the past. An expired event page can still have search value, backlinks or useful historical information. This solution is for situations where you’ve deliberately decided those pages should remain accessible on the website but no longer need to appear in search.

Step 1 – Capture the event date with GTM

The first step was to grab the event date and time from each page.  This was done by getting the datetime attribute from the particular div on the page – to do this, we set a variable which pulled in the DOM element using a CSS selector as followed:

Event Date

Step 2 – Identify the event pages

I then created a trigger that detected when an event was being viewed as follows:

Event URL

Step 3 – Add noindex when the event date has passed

And that in turn fired the following custom html tag:

NoIndex Old Event

The code used is as follows:

<script>
var dateInPast = function(firstDate, secondDate) 
{
  if (firstDate.setHours(0, 0, 0, 0) <= secondDate.setHours(0, 0, 0, 0)) {
    return true;
  }
  return false;
};

var event_date = new Date({{Event Date}});
var today_date = new Date();
var in_the_past = dateInPast(event_date, today_date);

if (in_the_past)
{	
	jQuery('meta[name="robots"]').remove();
	var meta = document.createElement('meta');
	meta.name = 'robots';
	meta.content = 'noindex, follow';
	jQuery('head').append(meta);
}
</script>

Here, a function is created which passed in the event date and compares it to todays date.  If that date is in the past, it returns true, and in turn, removes any existing robots tag and inserts a new one.

If you site doesn’t support JQuery, you can use this code instead to add the new robots tag:

var metatag = document.createElement('meta');
metatag.setAttribute('name', 'robots');
metatag.content = 'noindex,follow';
document.getElementsByTagName('head')[0].appendChild(metatag);

Should you noindex expired event pages?

Not every expired event should automatically be removed from Google’s index.

Some historical event pages continue to attract searches, earn links or provide useful information long after the event has finished. In those cases, retaining the page in search may make perfect sense.

This implementation was useful because the client had a large archive of old event pages they wanted to retain on the website, while having no particular reason for those pages to continue appearing in search.

Using the event date meant the process could happen automatically rather than relying on somebody remembering to update each page manually.

If your CMS can handle this directly, I’d generally implement the noindex logic there. If it can’t, GTM can provide a useful fallback for this type of automated rule.




About The Author

I'm Dave Ashworth, a freelance SEO and website optimisation consultant with a background in development and a focus on fixing what's broken, improving what's working, and helping businesses grow through clear, practical SEO.

I combine hands-on technical know-how with years of experience in analytics, content strategy and platform optimisation. Whether it's an audit, a migration, or ongoing performance support, my work's about making websites stronger, faster, and easier to understand for - users, search engines and AI platforms.

When I'm not writing guides or sharing insights, I'm working directly with clients to solve problems, track results, and keep their sites moving in the right direction.

Dave Ashworth

get in touch

If you need some expert website optimisation and configuration, want to find out more, or even just have a question, fill in the form below as I will always be happy to help