Crawl Rate - Tag Manager

How To: Easily Configure Multiple URLs & Parameters In One Trigger Using Google Tag Manager

By on 4th October 2021

Reading Time: 3 minutes

  • LinkedIn
  • Twitter
code

As a Google Tag Manager consultant, I am often looking for innovative ways to use it to perform on site SEO. One of the main things I use it it for is to de-index unwanted content such as taxonomy, paginated and parameterised content (I wrote a blog post on how to add a noindex tag via GTM here).  

More often than not when first auditing a site, you will come across lots of unwanted low quality indexed content such as:

  • /category_page?mode=grid3
  • /category_page?limit=16&mode=grid3
  • /category_page?dir=desc&limit=all&order=position
  • /category_page?dir=asc&order=name
  • /category_page?p=3

along with other page types, such as:

  • /catalog/product/view/id/24838
  • /catalog/product/view/id/27703
  • /productalert/add/stock/product_id/11221/
  • /productalert/add/stock/product_id/22112/

And so on.

Basically, Magento, I’m looking at you – but the above is common on most ecommerce sites where filters are involved, or WordPress where taxonomy pages are rife (but easily de-indexable via Yoast)

Until recently, I would manage these by creating a trigger for each indivudal URL structure and parameter, as I basically didn’t know any better.   This approach is perfectly acceptable, so long as the number of variations of triggers is low:

Triggers

But if the number of parameters is high, you need another approach as it basically takes time to do this.   And there’s always got to be a way to save time.

And there are ways to save time.  

Regex

I’ll be honest, I hate Regex.  I’ve been in the coding game to varying degrees for over 20 years and bar the pipe symbol, aka OR which looks like |, I can never get them to work.   So, if I can avoid them, I will.

But the pipe symbol is one option here, to a degree, so far as my limited knowledge goes anyway.

If you want to block URL structures based on folders, you could go with a tag such as the following:

regex

So, on my site, that would fire on:

Where it starts to get messy, is when you want to fire URL parameters via the = symbol (it might be easy, but as I say, I hate regex and am not willing to take this any further).

The other drawback is that if you have many permutations you wish to block, managing them all in one input box gets a bit fiddly. The following solution therefore is FAR better:

Custom JavaScript Variable

This a much more elegant approach, as you can use a bespoke JavaScript function to set up an array of URL structures and parameters to check for – if one of them is present in the current URL, the variable returns true, if not, it returns false.

You would set up a Custom JavaScript Variable as follows:

Custom JavaScript Variable

The full code is as follows:

function() 
{
	var deIndexTheseURLs = 
	[
		'/catalog/',
		'/catalogsearch/',
		'/customer/',
		'cjdata=',
		'colour_shade=',
		'dir=',
		'extension_length=',
		'extension_style=',
		'extension_weight=',
		'gclid=',
		'hair_extension_colour=',
		'limit=',
		'mode=',
		'options=',
		'order=',
		'p=',
		'platform=',
		'product_list_order=',
		'store=',
		'wig_length=',
		'q='
	];

	for (var i = 0; i < deIndexTheseURLs.length; i += 1) 
	{  
		if (document.location.href.indexOf(deIndexTheseURLs[i]) > -1) 
		{
			return true;
		}
	};

return false;
}

Here, the list of structures is easy enough to manage and edit at any time.

The array contains various structure formats, which is then looped through and checks against the current URL to see if the URL structure is a substring.

If it is, it returns true, if not false.

You then set up a trigger to fire when the variable returns true, and associate this with your no index tag as follows:

Custom Javascript Variable Trigger

And that’s it. Easy.  If you have any questions, queries or need any assistance getting this set up, feel free to get in touch, am always happy to help.

Dave Ashworth

About The Author -

I would describe myself as an SEO Expert and a specialist in technical optimisation with a professional approach to making websites better for people and better for search engines.

When I'm not blogging, I deliver website optimisation consultancy and organic SEO solutions by addressing a website's technical issues and identifying opportunities for growth


Get In Touch

Fill in the form below if you want to enhance your website's organic visibility