Class: Itly::Plugin::Mixpanel
- Inherits:
-
Itly::Plugin
- Object
- Itly::Plugin
- Itly::Plugin::Mixpanel
- Defined in:
- lib/itly/plugin/mixpanel/mixpanel.rb,
lib/itly/plugin/mixpanel/options.rb,
lib/itly/plugin/mixpanel/version.rb,
lib/itly/plugin/mixpanel/call_options.rb,
lib/itly/plugin/mixpanel/error_handler.rb
Overview
Mixpanel plugin class for Itly SDK
Defined Under Namespace
Classes: CallOptions, ErrorHandler, Options
Constant Summary collapse
- VERSION =
'0.1.1'
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
Instance Method Summary collapse
-
#alias(user_id:, previous_id:, options: nil) ⇒ Object
Associate one user ID with another (typically a known user ID with an anonymous one).
-
#id ⇒ String
Get the plugin ID.
-
#identify(user_id:, properties: nil, options: nil) ⇒ Object
Identify a user.
-
#initialize(project_token:, disabled: false) ⇒ Mixpanel
constructor
Instantiate a new Plugin::Mixpanel.
-
#load(options:) ⇒ Object
Initialize Mixpanel::Tracker client.
-
#name ⇒ Object
Mixpanel specific plugin options class for calls to plugin methods.
-
#track(user_id:, event:, options: nil) ⇒ Object
Track an event.
Constructor Details
#initialize(project_token:, disabled: false) ⇒ Mixpanel
Instantiate a new Plugin::Mixpanel
22 23 24 25 26 |
# File 'lib/itly/plugin/mixpanel/mixpanel.rb', line 22 def initialize(project_token:, disabled: false) super() @project_token = project_token @disabled = disabled end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
14 15 16 |
# File 'lib/itly/plugin/mixpanel/mixpanel.rb', line 14 def client @client end |
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
14 15 16 |
# File 'lib/itly/plugin/mixpanel/mixpanel.rb', line 14 def disabled @disabled end |
Instance Method Details
#alias(user_id:, previous_id:, options: nil) ⇒ Object
Associate one user ID with another (typically a known user ID with an anonymous one).
Raise an error if the client fails
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/itly/plugin/mixpanel/mixpanel.rb', line 105 def alias(user_id:, previous_id:, options: nil) super return unless enabled? # Log log = Itly::Loggers.vars_to_log user_id: user_id, previous_id: previous_id, options: @logger&.info "#{id}: alias(#{log})" # Send through the client @client.alias user_id, previous_id end |
#id ⇒ String
Get the plugin ID
122 123 124 |
# File 'lib/itly/plugin/mixpanel/mixpanel.rb', line 122 def id 'mixpanel' end |
#identify(user_id:, properties: nil, options: nil) ⇒ Object
Identify a user
Raise an error if the client fails
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/itly/plugin/mixpanel/mixpanel.rb', line 59 def identify(user_id:, properties: nil, options: nil) super return unless enabled? # Log log = Itly::Loggers.vars_to_log user_id: user_id, properties: properties, options: @logger&.info "#{id}: identify(#{log})" # Send through the client @client.people.set user_id, properties end |
#load(options:) ⇒ Object
Initialize Mixpanel::Tracker client
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/itly/plugin/mixpanel/mixpanel.rb', line 33 def load(options:) super # Get options @logger = .logger # Log @logger&.info "#{id}: load()" if @disabled @logger&.info "#{id}: plugin is disabled!" return end # Configure client @client = ::Mixpanel::Tracker.new @project_token, ErrorHandler.new end |
#name ⇒ Object
Mixpanel specific plugin options class for calls to plugin methods
16 17 18 19 20 21 22 23 |
# File 'lib/itly/plugin/mixpanel/call_options.rb', line 16 %w[Identify Group Page Track Alias].each do |name| class_eval( <<-EVAL, __FILE__, __LINE__ + 1 class #{name}Options < CallOptions # class IdentifyOptions < CallOptions end # end EVAL ) end |
#track(user_id:, event:, options: nil) ⇒ Object
Track an event
Raise an error if the client fails
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/itly/plugin/mixpanel/mixpanel.rb', line 80 def track(user_id:, event:, options: nil) super return unless enabled? # Log log = Itly::Loggers.vars_to_log( user_id: user_id, event: event&.name, properties: event&.properties, options: ) @logger&.info "#{id}: track(#{log})" # Send through the client @client.track user_id, event.name, event.properties end |