Skip to content

Instantly share code, notes, and snippets.

@wetzler
Created April 7, 2015 17:08
Show Gist options
  • Save wetzler/e9f0bdf8271a60f5e8dd to your computer and use it in GitHub Desktop.
Save wetzler/e9f0bdf8271a60f5e8dd to your computer and use it in GitHub Desktop.
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