Analyzing Demographics

One of the most powerful features of PYLON is the access you're given to demographic details of users. In this document we'll take a look at some of the options you have for analysis. Unlike some sources you may have worked with in the past the Facebook Graph contains demographic details for the vast majority of users.

tip icon

Remember when you write any query you need to consider whether you are looking for stories, engagements or both. The targets in the fb.topics.* namespace represents topics found in original stories, whereas the fb.parent.topics.* namespace represents topics found in stories which are the parent of an engagement.

You can read our introduction to Facebook topic data for more details.

Analysis query filters

Demographic details give you a great way to subset your data for further analysis. For example you may want to analyze the top links shared by males versus females.

When you submit an analysis query you can provide an optional filter parameter (written as CSDL) to subset the data in your index before the analysis query is run. You can use the example CSDL below for this purpose.

Types of interactions

All interactions from a demographic

To filter to both stories and engagements created by a certain demographic use both the fb.author.* targets. This example will capture stories created by people from 35 to 44 and engagements by the same age group on stories posted by anyone of any age group.

fb.author.age == "35-44"

note icon

You might have expected this filter to have read as follows to capture both stories and engagements:

fb.author.age == "35-44" OR fb.parent.author.age == "35-44"

However this would be incorrect. As both stories and engagements have the fb.author.* targets the first condition will capture all stories and engagements from the demographic. The second condition using the fb.parent.author.age target will additionally capture engagements by any user on stories created by 35-44 year olds, so engagements by users outside our target demographic.

Stories only from a demographic

To filter to just stories created by a demographic use targets from fb.author.* and specify stories only with the fb.type target.

fb.type == "story" AND fb.author.age == "35-44"

Engagements only by a demographic

To filter to just engagements created by a demographic use targets from fb.author.* and specify the engagement types you need using the fb.type target.

fb.type IN "like,comment,reshare" AND fb.author.age == "35-44"

Engagements on stories created by a demographic

To filter to all engagements on stories created by a demographic just can use targets from the fb.parent.author.* namespace, as only engagements have these targets. In this example using the parent target restricts the data to engagements only and the target itself specifies the age of the author who created the story being engaged on.

fb.parent.author.age == "35-44"

Filtering by age & gender

Age groups

Let's start by looking at age. Authors are grouped in to age bands, these are detailed on the targets pages fb.author.age and fb.parent.author.age.

Note that accounts of users under 18 are not available for recording and therefore analysis.

To filter to interactions from one specific age group:

fb.author.age == "35-44"

Or, to filter to interactions by multiple age groups:

fb.author.age in "18-24, 25-34, 35-44"

Genders

Looking at gender, authors can be identified as male, female or unknown (when a user hasn't specified this information). For genders you'll be working with the fb.author.gender and fb.parent.author.gender targets.

To filter to a specific gender:

fb.author.gender == "male"

To exclude a gender:

fb.author.gender != "unknown"

You can of course combine multiple conditions, such as to look for males between 35 & 44:

fb.author.age == "35-44" AND fb.author.gender == "male"

Filtering by location

When working with location there a few targets you can work with:

To filter to interactions from a particular country you could write a filter like so:

fb.author.country == "United States"

Or you could use country codes instead:

fb.author.country_code == "US"

To filter to a list of countries:

fb.author.country_code in "US,UK"

To filter to regions:

fb.author.region in "New York,California"

Equally you can make use of the country_region targets, for example you could filter to England in the UK. (These targets can be useful when there are regions with the same name in different countries you are trying to distinguish between.)

fb.author.country_region in "United Kingdom|England"

Filtering by author type

Authors on Facebook are either users or pages. You can distinguish between the two using the fb.author.type and fb.parent.author.type targets.

To filter to just users posting stories or engaging:

fb.author.type == "user"

To exclude a type:

fb.author.type != "page"

Analysis targets

You can use any of the demographic targets as your target for analysis queries.

Analyzing author type

Analyzing author type is a common requirement, this allows you to distinguish between users and pages (which usually belong to brands or organisations).

For example to analyze which type of user is posting stories or engaging:

{
    "analysis_type": "freqDist",
    "parameters": {
        "target": "fb.author.type",
        "threshold": 2
    }
}

Or to analyze which type of author is driving more engagement with their posted stories:

{
    "analysis_type": "freqDist",
    "parameters": {
        "target": "fb.parent.author.type",
        "threshold": 2
    }
}

Note that we're using a parent target here that immediately cuts the data set being analyzed to engagements only. The target itself gives the age of the author of the stories being engaged with.

Analyzing age groups

Analyzing author age is another common requirement, giving you a demographic breakdown of your audience.

For example to analyze which age groups are posting stories or engaging:

{
    "analysis_type": "freqDist",
    "parameters": {
        "target": "fb.author.age",
        "threshold": 2
    }
}

Or to analyze which ages of authors are driving more engagement with their posted stories:

{
    "analysis_type": "freqDist",
    "parameters": {
        "target": "fb.parent.author.age",
        "threshold": 2
    }
}

Analyzing genders

You can also breakdown your audience by gender.

For example to analyze which genders are posting stories or engaging:

{
    "analysis_type": "freqDist",
    "parameters": {
        "target": "fb.author.gender",
        "threshold": 2
    }
}

Or to analyze which genders of authors are driving more engagement with their posted stories:

{
    "analysis_type": "freqDist",
    "parameters": {
        "target": "fb.parent.author.gender",
        "threshold": 2
    }
}

Analyzing location

Finally let's take a look at analysis of author locations. There are many available targets for location, but they all function in the same way.

As one example, to analyze the countries of authors who are posting stories or engaging:

{
    "analysis_type": "freqDist",
    "parameters": {
        "target": "fb.author.country",
        "threshold": 2
    }
}

Analyzing regions

Analysis of author regions is not as immediately obvious as you may think, this is because regions have the same name in many countries such as 'North' and 'South'.

This query would give you the region of authors who are posting stories or engaging:

{
    "analysis_type": "freqDist",
    "parameters": {
        "target": "fb.author.region",
        "threshold": 2
    }
}

However, in the list of results you would not be able to distinguish between regions that have the same name but are in different countries.

Instead you could modify your query as follows:

{
    "analysis_type": "freqDist",
    "parameters": {
        "target": "fb.author.country_region",
        "threshold": 2
    }
}

The fb.author.country_region and fb.parent.author.country_region targets give you both the country and region for the authors allowing you disguish between countries.

Using demographic targets in query filters and analysis

You can make use of topics in your query filter and as your target for analysis:

{
    "analysis_type": "freqDist",
    "filter": "fb.author.gender == \"male\"",
    "parameters": {
        "target": "fb.author.region",
        "threshold": 5
    }
}

But what does this mean?

This query is saying first filter my dataset to interactions that come from males, then analyze this subset of the data to provide a frequency distribution of author regions returning the top 5 regions.