Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Count event totals for all of your Keen collections
require 'dotenv'
require 'keen'
# Don't forget to specify your Keen Master Key, Ready Key, and Project ID in your environment variables!
# Reference:
# allow timeframe to be specified via the command line
# usage: ruby collection_counts.rb previous_7_days
if !ARGV[0].nil?
timeframe = ARGV[0]
# iterates over collections and counts the total number of events in each
# assumes you have your Keen credentials in .env
Keen.event_collections.each {|collection|
collection = collection["name"]
# count
if timeframe.nil?
results = Keen.count(collection)
results = Keen.count(collection,
:timeframe => timeframe
puts "#{collection}\t#{results}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.