Guides / Getting analytics / Search analytics / Segmenting your analytics data

Tag Your Users By Age Group

Analytics tags let you view subsets of your analytics data. This lets you better understand your user’s behavior. Analytics tags are strings that you conditionally assign to specific searches. These strings identify an aspect of the searches that clarify the behavior of a specific group of users.

For instance, suppose 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.

This guide outlines the process step by step. It illustrates two ways of implementing analyticsTags: with InstantSearch and with the API clients.

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
let query = Query()
query.analyticsTags = [ageGroup]
let searcher = HitsSearcher(index: index, query: query)

Using an API client

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

After you’ve implemented, tested, and released your app with age group analyticsTags, you can start segmenting your new analytics data based on your user’s platform.

You can do this from the Analytics section of your Algolia dashboard. In the header of the Analytics tab you can find the Tags input field.

Once your users start making searches in your new search implementation, the age group analyticsTags appear in the Tags field. If you select a certain age group, you only see analytics for searches tagged with that age group. This is true for all Analytics subsections.

Depending on your traffic, you may have to wait to get enough tagged data to start drawing meaningful conclusions.

Did you find this page helpful?