class Greenfinch::Tracker
Use Greenfinch::Tracker
to track events and profile updates in your application. To track an event, call
tracker = Greenfinch::Tracker.new(YOUR_GREENFINCH_TOKEN) Greenfinch::Tracker.track(a_distinct_id, an_event_name, {properties})
To send people updates, call
tracker = Greenfinch::Tracker.new(YOUR_GREENFINCH_TOKEN) tracker.people.set(a_distinct_id, {properties})
To send groups updates, call
tracker = Greenfinch::Tracker.new(YOUR_GREENFINCH_TOKEN) tracker.groups.set(group_key, group_id, {properties})
You can find your project token in the settings dialog for your project, inside of the Greenfinch
web application.
Greenfinch::Tracker
is a subclass of Greenfinch::Events
, and exposes an instance of Greenfinch::People
as Tracker#people
and an instance of Greenfinch::Groups
as Tracker#groups
Attributes
An instance of Greenfinch::Groups
. Use this to send groups updates
An instance of Greenfinch::People
. Use this to send profile updates
Public Class Methods
Takes your Greenfinch
project token, as a string.
tracker = Greenfinch::Tracker.new(YOUR_GREENFINCH_TOKEN)
By default, the tracker will send an message to Greenfinch
synchronously with each call, using an instance of Greenfinch::Consumer
.
You can also provide a block to the constructor to specify particular consumer behaviors (for example, if you wanted to write your messages to a queue instead of sending them directly to Greenfinch
)
tracker = Greenfinch::Tracker.new(YOUR_GREENFINCH_TOKEN) do |type, message| @kestrel.set(MY_GREENFINCH_QUEUE, [type,message].to_json) end
If a block is provided, it is passed a type (one of :event or :profile_update) and a string message. This same format is accepted by Greenfinch::Consumer#send!
and Greenfinch::BufferedConsumer#send!
Greenfinch::Events::new
# File lib/greenfinch-ruby/tracker.rb, line 55 def initialize(token, service_name, debug, error_handler=nil, use_internal_domain: false, &block) super(token, service_name, debug, error_handler, use_internal_domain: use_internal_domain, &block) @token = token @service_name = service_name @debug = debug end
Public Instance Methods
A call to track
is a report that an event has occurred. track
takes a distinct_id representing the source of that event (for example, a user id), an event name describing the event, and a set of properties describing that event. Properties are provided as a Hash with string keys and strings, numbers or booleans as values.
tracker = Greenfinch::Tracker.new(YOUR_GREENFINCH_TOKEN) # Track that user "12345"'s credit card was declined tracker.track("12345", "Credit Card Declined") # Properties describe the circumstances of the event, # or aspects of the source or user associated with the event tracker.track("12345", "Welcome Email Sent", { 'Email Template' => 'Pretty Pink Welcome', 'User Sign-up Cohort' => 'July 2013' })
Greenfinch::Events#track
# File lib/greenfinch-ruby/tracker.rb, line 80 def track(distinct_id, event, properties={}, ip=nil) # This is here strictly to allow rdoc to include the relevant # documentation super end