Last active
August 29, 2015 14:02
-
-
Save wetzler/df3537e0fb63602be996 to your computer and use it in GitHub Desktop.
Pushpop script to check for 1) New users and 2) Newly active users sending data for the first time in 7 days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
TEMPLATES_DIRECTORY = File.expand_path('../templates', __FILE__) | |
require 'date' | |
require 'pushpop' | |
require 'active_support/all' #for datetime calculation e.g. weeks.ago.at_beginning_of_week | |
job do | |
every 24.hours | |
keen 'new_project_members' do | |
event_collection 'create_user' | |
analysis_type 'select_unique' | |
target_property 'user.email' | |
timeframe ({ | |
:start => 24.hours.ago | |
}) | |
filters [{ | |
property_name: "reason", | |
operator: "eq", | |
property_value: "added to project" | |
}] | |
end | |
keen 'data_senders_last_24hr' do | |
event_collection 'events_added_api_call' | |
analysis_type 'sum' | |
target_property 'num_successful_events' | |
group_by 'project.organization.name' | |
timeframe ({ | |
:start => 24.hours.ago | |
}) | |
end | |
keen 'data_senders_previous_3_days' do | |
event_collection 'events_added_api_call' | |
analysis_type 'count' | |
group_by 'project.organization.name' | |
timeframe ({ | |
:start => (24*8).hours.ago, | |
:end => 24.hours.ago | |
}) | |
end | |
step 'newbs' do |_, step_responses| | |
newbs = [] | |
step_responses['data_senders_last_24hr'].each do |o| | |
if h = step_responses['data_senders_previous_3_days'].find { |h| h['project.organization.name'] == o['project.organization.name']} | |
# do nothing | |
else | |
newbs << o | |
end | |
end | |
newbs | |
end | |
sendgrid do |response, step_responses| | |
to '[email protected]' | |
from '[email protected]' | |
subject 'Customer Activity Report' | |
body 'report.html.erb', response, step_responses, TEMPLATES_DIRECTORY | |
preview ENV['PREVIEW'] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment