Skip to content

Instantly share code, notes, and snippets.

Embed
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: https://github.com/keenlabs/keen-gem
Dotenv.load
# allow timeframe to be specified via the command line
# usage: ruby collection_counts.rb previous_7_days
if !ARGV[0].nil?
timeframe = ARGV[0]
end
# 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)
else
results = Keen.count(collection,
:timeframe => timeframe
)
end
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.