Analytics tags let you view subsets of your analytics data, which, in turn, allows you to better understand the behavior of your users. Analytics tags are strings which you conditionally assign to specific searches to identify the behavior of a subset of your users.

For instance, let’s say you run a social media website where users can authenticate and create a profile. In their profile, they must provide their date of birth. This piece of information can help you determine their age. When they make a search, you can send that information to Algolia.

Later on, when you consult your Algolia analytics data, you can better understand the behavior and needs of your users based on their age group, instead of looking at all your users collectively.

Identifying your user’s age group

Sending the specific birth year or age of each of your users wouldn’t be optimal, because you would end up with a lot of unhelpful tags. For example, you likely don’t want to see analytics for all users who are exactly 21, or those who were born in 1975. Instead, you probably want a general overview of how teens, young adults, and seniors behave.

Therefore, you need to fetch your user’s information and transform it, before you can send it to Algolia.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function getAgeGroup($birthYear)
{
    if ($birthYear >= 1996) {
        return "Generation Z";
    } else if ($birthYear <= 1995 && $birthYear >= 1977) {
        return "Generation Y";
    } else {
        return "Generation X or older";
    }
}

$birthYear = 1975; // Fetch your user's birth year from your back end

$ageGroup = getAgeGroup($birthYear);

Whenever a user makes a search, you want to send their age group along with the query. You can do this whether you’re using InstantSearch, or an API client directly.

Using InstantSearch

If you’re using InstantSearch to build your front end, you can pass the analyticsTags parameter when making the query.

1
2
3
4
5
6
7
val query = query {
    analyticsTags {
        +ageGroup
    }
}

val searcher = SearcherSingleIndex(index, query)

Using the API

You can also pass the analyticsTags parameter if you’re using one of the API clients.

1
2
3
4
5
$results = $index->search('query', [
  'analyticsTags' => [
    $ageGroup
  ]
]);

Viewing segmented analytics data

You can view your segmented analytics data on the Algolia dashboard.

  1. Go to your dashboard and head over to the Analytics section.
  2. Select your index.
  3. In the Tags input, select the tag you want to filter on.
  4. The graphs should update to the selected tag.

Did you find this page helpful?