Class: Greenfinch::Tracker
- Defined in:
- lib/greenfinch-ruby/tracker.rb
Overview
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
Instance Attribute Summary collapse
-
#groups ⇒ Object
readonly
An instance of Greenfinch::Groups.
-
#people ⇒ Object
readonly
An instance of Greenfinch::People.
Instance Method Summary collapse
-
#initialize(token, service_name, debug, error_handler = nil, use_internal_domain: false, &block) ⇒ Tracker
constructor
Takes your Greenfinch project token, as a string.
-
#track(distinct_id, event, properties = {}, ip = nil) ⇒ Object
A call to #track is a report that an event has occurred.
Methods inherited from Events
Constructor Details
#initialize(token, service_name, debug, error_handler = nil, use_internal_domain: false, &block) ⇒ Tracker
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, |
@kestrel.set(MY_GREENFINCH_QUEUE, [type,].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!
55 56 57 58 59 60 |
# 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 |
Instance Attribute Details
#groups ⇒ Object (readonly)
An instance of Greenfinch::Groups. Use this to send groups updates
34 35 36 |
# File 'lib/greenfinch-ruby/tracker.rb', line 34 def groups @groups end |
#people ⇒ Object (readonly)
An instance of Greenfinch::People. Use this to send profile updates
31 32 33 |
# File 'lib/greenfinch-ruby/tracker.rb', line 31 def people @people end |
Instance Method Details
#track(distinct_id, event, properties = {}, ip = nil) ⇒ Object
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'
})
80 81 82 83 84 |
# 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 |