Why is it important to have company information in your product analytics?

Having relevant information about a company in your product analytics can help you understand how different organizations are interacting with your product or service. This information can be used to segment your customers and narrow down the focus of your analytics on a specific segment.

For example, these are the important data points we send every day from our database to June:

The idea is to call identify/group from background jobs to further enrich user/company traits.

How to use a cron job to update company traits with information from a database:

In this example, we will use a cron job to update company traits with the number of orders sent by each company in the last 30 days.

We will assume that we are using the June Python SDK, which allows us to send data to June.

Step 1: Set up a cron job

We will set up a daily cron job to update company traits.

To create a daily cron job that runs at midnight, add the following line to the crontab file:

0 0 * * * /path/to/your/script
Replace "/path/to/your/script" with the file path to the script that will update company traits.

Step 2: Create a script to update company traits

Here is a Python example script that uses the June SDK to update company traits:

# Query database for number of orders by company in last 30 days 
# Replace this with your own database query

orders_by_company = YOUR_DATABASE_QUERY_HERE

# Get current date
today = datetime.date.today()

# Calculate date 30 days ago

thirty_days_ago = today - datetime.timedelta(days=30)

# Update traits for each company

for company_id, num_orders in orders_by_company.items():
analytics.group(company_id, traits{
"orders_last_30_days": num_orders})

This script will update the traits for each company with the number of orders they have sent in the last 30 days.


Using a cron job to update company traits with information from a database is a powerful way to make your analytics way more relevant. By setting up a daily cron job, you can keep company traits up-to-date and use this information to improve your product. By using a job like the one above to send information from your database to your analytics, you won't be limited to using only track events.

Did this answer your question?