Created
March 28, 2017 01:58
-
-
Save mikekavouras/29413ebe90c36a77c7660a1074685db3 to your computer and use it in GitHub Desktop.
This file contains 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
# call | |
AmplitudeTracker.track(user.teespring_id, "should_send_notification", { | |
type: "seller_variation_upsell" | |
}) | |
# tracker | |
class AmplitudeTracker | |
BASE_URL = "https://api.amplitude.com".freeze | |
TRACK_URL = "/httpapi".freeze | |
IDENTIFY_URL = "/identify".freeze | |
def self.track(user_id, event_name, event_properties) | |
AmplitudeWorker.perform_async(BASE_URL + TRACK_URL, { | |
api_key: ENV['AMPLITUDE_API_KEY'], | |
event: { | |
event_type: event_name, | |
user_id: user_id.to_s, | |
event_properties: event_properties, | |
}.to_json, | |
}) | |
end | |
end | |
# worker | |
require 'typhoeus' | |
class AmplitudeWorker | |
include Sidekiq::Worker | |
def perform(url, properties) | |
Typhoeus::Request.new( | |
url, | |
method: :get, | |
params: properties, | |
).run | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment