Skip to content

Instantly share code, notes, and snippets.

@nathandentzau
Last active June 12, 2020 16:09
Show Gist options
  • Save nathandentzau/872b353bf047117606bd2190b6b74aa4 to your computer and use it in GitHub Desktop.
Save nathandentzau/872b353bf047117606bd2190b6b74aa4 to your computer and use it in GitHub Desktop.
require_relative "lib/ga/optimizely_event_client"
account_id = 392850087
experiment_id = 18203860323
campaign_id = 18191831043
variation_ids = {
original: 18194071072,
variation: 18183880934
}
events = {
cwe_enrollment_created: 17843193008,
cwe_paid_enrollment_created: 17838941605,
cwe_free_enrollment_created: 17847132950,
consumer_part_time_lead_created: 17810520483,
consumer_full_time_lead_created: 17812541781,
consumer_lead_created: 17834001224,
prospect_created: 17719310255
}
visitors = [
{ event: :cwe_enrollment_created, variation: :original },
{ event: :cwe_paid_enrollment_created, variation: :variation },
{ event: :cwe_free_enrollment_created, variation: :original },
{ event: :consumer_part_time_lead_created, variation: :variation },
{ event: :consumer_full_time_lead_created, variation: :original },
{ event: :consumer_lead_created, variation: :variation },
{ event: :prospect_created, variation: :original }
].map { |record| record.merge(visitor_id: SecureRandom.uuid) }
GA::OptimizelyEventClient.account_id = account_id
GA::OptimizelyEventClient.event_ids = events
visitors.each do |data|
puts GA::OptimizelyEventClient.activate(
campaign_id: campaign_id,
experiment_id: experiment_id,
variation_id: variation_ids[data[:variation]],
visitor_id: data[:visitor_id],
created_at: Time.now.to_i - (5 * 60)
)
end
sleep 60
visitors.each do |data|
puts GA::OptimizelyEventClient.convert(
event_type: data[:event],
visitor_id: data[:visitor_id],
converted_at: Time.now,
record_id: data[:visitor_id]
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment