Skip to content

Instantly share code, notes, and snippets.

@marinhero
Created March 1, 2018 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marinhero/d03d8081c89bb59d2934f1e331297f5c to your computer and use it in GitHub Desktop.
Save marinhero/d03d8081c89bb59d2934f1e331297f5c to your computer and use it in GitHub Desktop.
custom_samplings_generator.rb
#
# Open rails console
# type: load 'custom_samplings_generator.rb'
# type: seed('NPS-YourToken')
# Go to /account_sampling_rules.json?account_token=NPS-YourToken in Survey Server
#
RULES = %w(
on_click
on_login
on_logout
on_purchase
on_checkout
account_delete
new_account
)
def create_params(account_id)
{
account_id: account_id,
rule_name: "#{RULES.sample}_#{rand(1..1000)}",
rule_type: 'event',
survey_throttle_days: rand(1..30),
response_throttle_days: rand(1..100),
decline_throttle_days: rand(1..50),
modal_delay_seconds: rand(1..10),
daily_response_cap: rand(1..100),
registered_user_sample_percentage: rand(50..100),
visitor_user_sample_percentage: rand(50..100),
context_name: nil
}
end
def seed(token)
account_id = Account.where(account_token: token).pluck(:id)[0]
puts '[+] Creating CustomSampling rules'
rand(1..5).times do
CustomSampling.create(create_params(account_id))
end
puts '[+] Done'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment