[Documentation](https://groundhogg.io/documentation/) » [Classes](https://groundhogg.io/documentation/#doc-classes)

# \Groundhogg\Tag

Published Tuesday, June 9, 2026 · Last updated Tuesday, June 9, 2026

extends `Base_Object`

Represents a contact tag used for segmentation. Tags are applied to contacts to group and filter them for funnels, broadcasts, and reports. Instantiate with a tag ID, name, or slug.

## Methods

| Method | Returns | Description |
| --- | --- | --- |
| `get_id()` | `int` | Returns the tag ID. |
| `get_name()` | `string` | Returns the tag’s display name. |
| `get_slug()` | `string` | Returns the tag’s URL-friendly slug. |
| `get_description()` | `string` | Returns the tag’s description. |
| `get_contact_count()` | `int` | Returns the number of contacts currently holding this tag. |
| `get_contact_ids()` | `int[]` | Returns an array of contact IDs for all contacts with this tag. |
| `is_preference_tag()` | `bool` | Returns `true` if this tag is used as a marketing preference option on the preferences page. |
| `exists()` | `bool` | Returns `true` if the tag exists in the database. |

## Usage

Here’s a pseudo code example for a hypothetical tag-based segmentation report.

```

<?php

add_action( 'groundhogg/admin/report/lead_score', 'my_plugin_tag_breakdown_report' );

/**
 * Show a breakdown of contacts per tag in the lead score report.
 *
 * @return void
 */
function my_plugin_tag_breakdown_report() {

    $tag_ids = [ MY_PLUGIN_VIP_TAG_ID, MY_PLUGIN_CUSTOMER_TAG_ID, MY_PLUGIN_LEAD_TAG_ID ];

    echo 'Contact counts by tag';

    foreach ( $tag_ids as $id ) {
        $tag = new \Groundhogg\Tag( $id );

        if ( ! $tag->exists() ) {
            continue;
        }

        echo '' . esc_html( $tag->get_name() ) . ': ' . $tag->get_contact_count() . '';
    }

    echo '';
}
```
