Simple collection count and delta reports. Growth hacking metrics delivered to your inbox however often you want.
Install: meteor add em0ney:reporter
This is a package designed to email a summary of collection counts and statistics to users. It is built on-top of:
- aldeed:collection2 [To define collections to store stats]
- percolatestudio:synced-cron [To schedule email digests]
- wylio:mandrill [To send email using mandrill]
- underscore [Everyone's favourite js library]
- momentjs:moment [To format the time in the email message]
Currently, Reporter will give you the daily count of configured collections and Deltas against the last 5 periods. For more job types, raise an issue on this repo and we'll be happy to oblige.
Either: $ export MANDRILL_API_KEY=xxxxxxxxxxxxx
in your session before starting meteor or $ MANDRILL_API_KEY=xxxxxxxxxxx meteor
The package comes with the following out of the box jobs:
send_delta_email
: send configured recipients the configured collection counts and deltas for the last 5 runs
Configure this as follows. Any options omitted will be sourced from the existing configuration object.
Reporter.update_job('send_delta_email', {
schedule: '15 10 ? * *', // cron schedule: every day at 10:15 am
collections: ['Meteor.users', 'Posts', 'Comments'],
recipients: ['user@example.com', 'other-user@example.com'],
fromAddress: 'app@example.com',
subject: 'my custom subject'
});
Cron expression help later.js cron reference
If you do not wish to run an out of the box job, simply fun the following:
Reporter.remove_job('send_delta_email');
Reporter.init();
And that's it!
if (Meteor.isServer) {
Meteor.startup(function() {
Reporter.update_job('send_delta_email', {
schedule: '15 10 ? * *', // cron schedule: every day at 10:15 am
collections: ['Meteor.users', 'Posts', 'Comments'],
recipients: ['user@example.com', 'other-user@example.com'],
fromAddress: 'app@example.com',
dateConfig: 'MMM Do, HH:mm', // OPTIONAL. moment.js format. If omitted, uses .ago()
subject: 'my custom subject'
});
Reporter.init();
});
}
This function declares each SyncedCron job for the entered job configuration and initialises SyncedCron to run. Must be called for this entered job configurations to take effect.
config_obj: {schedule: String, collections: [String], recipients: [String], fromAddress: String, subject: String, fn: Function}
This adds a job to be initialised in the init()
function. Job keys must be unique. If called on an existing job, the entire job config will be replaced with that passed in.
config_obj: {schedule: String, collections: [String], recipients: [String], fromAddress: String, subject: String, fn: Function}
This updates the config for the given job config. For any arguments that aren't provided, the existing setting from the previous config will be used.
This removes a job.
This reloads the configuration referenced by job_key, such that SyncedCron reloads the schedule for it. It should be called after update_job
if init()
has already been called.
e.g.
Reporter.init();
...
Reporter.update_job('send_delta_email', {
schedule: '15 10 ? * *', // cron schedule: every day at 10:15 am
collections: ['Meteor.users', 'Posts', 'Comments'],
recipients: ['user@example.com', 'other-user@example.com'],
fromAddress: 'app@example.com',
dateConfig: 'MMM Do, HH:mm', // OPTIONAL. moment.js format. If omitted, uses .ago()
subject: 'my custom subject'
});
Reporter.reload_job('send_delta_email');
config_obj: {schedule: String, collections: [String], recipients: [String], fromAddress: String, subject: String, fn: Function}
The config_obj
is provided as the first and only argument to the function for each scheduled job. After collecting data and creating an HTML formatted email body, call send_results(html_body, config_obj)
to send that email to each of the job's configured recipients through Mandrill's API.
Coming soon! Under development are features like:
- Optional integration with
alanning:roles
and defining recipients as emails or roles - Ability to include recent documents that make up the deltas in the email
- Personalised email templates
- Admin page to configure schedule and collections for jobs
- Dashboard page