Euromonitor International sells market research data: market sizes, and the market shares of companies and brands. For one of our clients, a Laravel application must read this data and show it next to their own numbers.
The Euromonitor API has many parameters, and large data sets come back as files from a queued job. We wrote a package to make this easier: Laravel Euromonitor.
What the package does
Laravel Euromonitor gives a fluent API client for Laravel.
- It gets an access token with your API portal credentials.
- It reads the catalog: categories, geographies, data types, share types, companies and brands.
- It reads market sizes, company shares and brand shares.
- It validates each query before it sends the request.
- It starts mass extraction jobs for large data sets.
- It downloads the result file on the queue, and sends an event when the file is ready.
Install the package
composer require bernskiold/laravel-euromonitor
Add the credentials from the Euromonitor API portal to your .env file:
EUROMONITOR_USERNAME=
EUROMONITOR_PASSWORD=
EUROMONITOR_API_KEY=
You can publish the configuration file to change the queue, the disk and the folder for downloaded files:
php artisan vendor:publish --provider="Bernskiold\LaravelEuromonitor\LaravelEuromonitorServiceProvider" --tag="config"
Read the catalog
Each query starts on the Euromonitor facade. Use the catalog to find the IDs of geographies, categories, companies and brands. Then use these IDs in the data queries.
use Bernskiold\LaravelEuromonitor\Facades\Euromonitor;
$brands = Euromonitor::brands()
->geographies([21]) // Belgium
->categories([11069]) // Toilet Paper
->perPage(1000)
->all()
->get();
$brands->first()->brandId; // 903112
$brands->first()->brandName; // "Lotus"
The IDs are stable. Find an entity one time, and then filter by its ID. Do not match on names, because names can change.
The catalog has one record for each combination of geography and category. Thus, the same brand can occur more than one time in a full list.
Read brand and company shares
Use brandShares() or companyShares(). Select the unit with percentages(), actual() or ranking(). A share query also needs a share type and one or more geographies.
$shares = Euromonitor::brandShares()
->percentages()
->shareType(0)
->geographies([21])
->categories([11069])
->brands([903112, 903118])
->all()
->get();
$shares->first()->entityName(); // "Lotus"
$shares->first()->companyId; // 674613
Each share has the brand ID and the company ID next to the names. You can filter brand shares by brand or by company.
Read market sizes
Use marketSize() to read the size of a market. Give categories or industry codes. You can also select a data type, a currency and a growth type.
$sizes = Euromonitor::marketSize()
->geographies([21])
->categories([11069])
->inEUR()
->all()
->get();
Each market size has a collection of data points, with one value for each year.
Get large data sets on the queue
A live query is good for a small set of data. For a full industry, use mass extraction. Call dispatch() instead of all(). Euromonitor then makes a file on their servers.
$job = Euromonitor::brandShares()
->percentages()
->industryCodes('CT')
->geographies([21])
->dispatch();
The package starts a queued job that waits for the file. The job checks the status again until the file is ready, for up to two hours. Then it downloads the file to your disk and sends an EuromonitorFileDownloaded event. The event has the data set, the file path and the disk.
Write a listener for this event to read the file and keep the data. For share files, the ParseEntityShareFile action changes each row into a share object.
To control the download yourself, call downloadFileManually() before dispatch(). You can then use Euromonitor::jobs() to read the status and the download URL.
Remove old files
The downloaded files can be large. Schedule the purge command to remove them after some days:
php artisan euromonitor:purge-downloaded-files --days=7
A limit to know
Mass extraction accepts only one industry code in each job. If you give more than one, the package stops the query with an exception. To extract more than one industry, start one job for each industry code.
Get the package
Laravel Euromonitor is open source, with the MIT license. You need your own Euromonitor subscription to use the API. The code is on GitHub. If you find a problem or have an idea, open an issue. We are happy to hear from you.