---
title: Filtrar categorías de dimensión personalizada en Matomo
url: "https://www.seopress.org/es/soporte/hooks/filtrar-categorias-de-dimension-personalizada-en-matomo/"
lang: es
updated: 2021-09-29
hook_name: seopress_matomo_cd_categories_ev
required_version: 3.8.5
---

# Filtrar categorías de dimensión personalizada en Matomo

- **Hook name:** `seopress_matomo_cd_categories_ev`
- **Required version:** 3.8.5

```php
<?php
add_filter( 'seopress_matomo_cd_categories_ev', 'sp_matomo_cd_categories_ev' );
function sp_matomo_cd_categories_ev( $js ) {
	// $js is the default Matomo JavaScript line for the Categories custom dimension.
	$categories = get_the_category();
	if ( empty( $categories ) ) {
		return $js;
	}

	$dimension_id = substr( seopress_get_service( 'GoogleAnalyticsOption' )->getCdCategory(), -1 );

	return "_paq.push(['setCustomVariable', " . seopress_js_string( $dimension_id ) . ', ' . seopress_js_string( __( 'Categories', 'wp-seopress' ) ) . ', ' . seopress_js_string( $categories[0]->name ) . ", 'visit']);\n";
}
```

Source: [https://gist.github.com/wp-seopress/74207fc0cf50e9f35861e9ac850eef31](https://gist.github.com/wp-seopress/74207fc0cf50e9f35861e9ac850eef31)



