In this tutorial we will show you an example using the fields=facets parameter and how you can exploit it together with the other filters of the API to get aggregated analysis.

Goal

We want quantitative information, divided into 4 segments by size. What and how many social networks are used by up to 5 employees? How many 6 to 10? 11-100? And over 100?

We want to find out that around 4% of the companies that employ up to 5 employees use social networks, 13% of those with a staff of between 6 and 10, 19% in the 11-100 range, and 31% of those over 100 employees.

We also want to find out that with the rise in the size of the companies, Facebook becomes relatively less dominant, going almost in line with the second and third most used social network, when it comes to very large companies.

To get this type of count you can use the facet!

Let’s start

Using the fields=facet parameter the responses will no longer contain business data, but the aggregations tell us how many companies match the criteria of the request. Let’s specify in what field to do faceting, ie where to get aggregates, using facetFields, in our case with socials.*.

To interact with social networks and the number of company employees we will need the socials and economics packages. The number of employees is filterable through employeesMin and employeesMax.

Up to 5 employees:

https://api.atoka.io/v2/companies?packages=socials&fields=facets&facetFields=socials.*&employeesMax=5&token=TOKEN
{
    "meta": { "count": 3800034 },
    "facets": {
        "socials": {
            "facebook": { "count": 145637 },
            "twitter": { "count": 35509 },
            "googleplus": { "count": 22678 },
            "youtube": { "count": 17581 },
            "instagram": { "count": 13936 },
            "linkedin": { "count": 9777 },
            "vimeo": { "count": 1648 },
            "flickr": { "count": 1290 }
        }
    }
}
  • meta.count tells us how many companies match filters, companies up to 5 employees
  • facets.socials contains the facet list: for each value, the aggregate number is reported. About 145,000 people use Facebook, 35,000 Twitter and so on

From 6 to 10 employees:

https://api.atoka.io/v2/companies?packages=socials&fields=facets&facetFields=socials.*&employeesMin=5&employeesMax=10&token=TOKEN
{
    "meta": { "count": 376793 },
    "facets": {
        "socials": {
            "facebook": { "count": 49002 },
            "twitter": { "count": 11234 },
            "googleplus": { "count": 7499 },
            /*omitted*/
        }
    }
}

From 11 to 100 employees:

https://api.atoka.io/v2/companies?packages=socials&fields=facets&facetFields=socials.*&employeesMin=10&employeesMax=100&token=TOKEN
{
    "meta": { "count": 234119 },
        "facets": {
        "socials": {
            "facebook": { "count": 44633 },
            "twitter": { "count": 14005 },
            "youtube": { "count": 10894 },
            /*omitted*/
        }
    }
}

More than 100 employees:

https://api.atoka.io/v2/companies?packages=socials&fields=facets&facetFields=socials.*&employeesMin=100&token=TOKEN
{
    "meta": { "count": 13503 },
    "facets": {
        "socials": {
            "facebook": { "count": 4199 },
            "twitter": { "count": 2335 },
            "youtube": { "count": 2267 }
        }
    }
}

In other words, the data says that Facebook is the most widely used social network by all Italian companies, followed by Twitter, which is in second place. Google Plus wins third place, but only among the companies with up to 10 employees, after this threshold companies tend to prefer YouTube. Thanks to the data of these 4 calls, the graphs above were drawn.

By following the same procedure and using APIs in a very similar way, it is possible to analyze and segment companies from Lombardy, those with turnover more than 10 million euros, those that exist for more than 10 years or the startups. Or any combination of these and so many other criterias!

How much does it cost?

While for data packages we get in the response we consume companies:* credits, in the case of aggregated data coming from facets, we consume companies:facets credits.

Each field we get in the response costs us 1 credit companies:facets: therefore each fo the requests in the example will cost us 16 credits (the number of fields in the socials package).

Atoka trick

To decrease the amount of credits consumed by each call, we can request only the facets we are really interested in. Let’s suppose we only case about Facebook, Twitter, Instagram and LinkedIn. We can use the parameter facetFields with this list of fields.

https://api.atoka.io/v2/companies?packages=socials&fields=facets&facetFields=socials.facebook,socials.twitter,socials.instagram,socials.linkedin&employeesMin=100&token=TOKEN

Each call will then cost 4 credits companies:facets.