class Itly::Plugin::Mixpanel

Mixpanel plugin class for Itly SDK

Mixpanel plugin class for Itly SDK

Automatically loaded at runtime in any new Itly object

Constants

VERSION

Attributes

client[R]
disabled[R]

Public Class Methods

new(project_token:, disabled: false) click to toggle source

Instantiate a new Plugin::Mixpanel

@param [String] project_token: specify the Mixpanel project token @param [TrueClass/FalseClass] disabled: set to true to disable the plugin. Default to false

Calls superclass method
# File lib/itly/plugin/mixpanel/mixpanel.rb, line 22
def initialize(project_token:, disabled: false)
  super()
  @project_token = project_token
  @disabled = disabled
end

Public Instance Methods

alias(user_id:, previous_id:, options: nil) click to toggle source

Associate one user ID with another (typically a known user ID with an anonymous one).

Raise an error if the client fails

@param [String] user_id: The ID that the user will be identified by going forward. This is

typically the user's database ID (as opposed to an anonymous ID), or their updated ID
(for example, if the ID is an email address which the user just updated).

@param [String] previous_id: The ID the user has been identified by so far. @param [Itly::Plugin::Mixpanel::AliasOptions] options: the plugin specific options

Calls superclass method
# 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: options
  @logger&.info "#{id}: alias(#{log})"

  # Send through the client
  @client.alias user_id, previous_id
end
id() click to toggle source

Get the plugin ID

@return [String] plugin id

# File lib/itly/plugin/mixpanel/mixpanel.rb, line 122
def id
  'mixpanel'
end
identify(user_id:, properties: nil, options: nil) click to toggle source

Identify a user

Raise an error if the client fails

@param [String] user_id: the id of the user in your application @param [Hash] properties: the properties containing user's traits to pass to your application @param [Itly::Plugin::Mixpanel::IdentifyOptions] options: the plugin specific options

Calls superclass method
# 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: options
  @logger&.info "#{id}: identify(#{log})"

  # Send through the client
  @client.people.set user_id, properties
end
load(options:) click to toggle source

Initialize Mixpanel::Tracker client

@param [Itly::PluginOptions] options: plugin options

Calls superclass method
# File lib/itly/plugin/mixpanel/mixpanel.rb, line 33
def load(options:)
  super
  # Get options
  @logger = options.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
track(user_id:, event:, options: nil) click to toggle source

Track an event

Raise an error if the client fails

@param [String] user_id: the id of the user in your application @param [Event] event: the Event object to pass to your application @param [Itly::Plugin::Mixpanel::TrackOptions] options: the plugin specific options

Calls superclass method
# 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: options
  )
  @logger&.info "#{id}: track(#{log})"

  # Send through the client
  @client.track user_id, event.name, event.properties
end

Private Instance Methods

enabled?() click to toggle source
# File lib/itly/plugin/mixpanel/mixpanel.rb, line 128
def enabled?
  !@disabled
end