Class: Itly::Plugin::Snowplow
- Inherits:
-
Itly::Plugin
- Object
- Itly::Plugin
- Itly::Plugin::Snowplow
- Defined in:
- lib/itly/plugin/snowplow/snowplow.rb,
lib/itly/plugin/snowplow/context.rb,
lib/itly/plugin/snowplow/options.rb,
lib/itly/plugin/snowplow/version.rb,
lib/itly/plugin/snowplow/call_options.rb
Overview
Snowplow plugin class for Itly SDK
Defined Under Namespace
Classes: CallOptions, Context, Options, PageOptions, TrackOptions
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.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#vendor ⇒ Object
readonly
Returns the value of attribute vendor.
Instance Method Summary collapse
-
#id ⇒ String
Get the plugin ID.
-
#identify(user_id:, properties: nil, options: nil) ⇒ Object
Identify a user.
-
#initialize(vendor:, options:) ⇒ Snowplow
constructor
Instantiate a new Plugin::Snowplow.
-
#load(options:) ⇒ Object
Initialize Snowplow plugin.
-
#name ⇒ Object
Snowplow specific plugin options class for calls to plugin methods.
-
#page(user_id:, category: nil, name: nil, properties: nil, options: nil) ⇒ Object
Record page views.
-
#track(user_id:, event:, options: nil) ⇒ Object
Track an event.
Constructor Details
#initialize(vendor:, options:) ⇒ Snowplow
Instantiate a new Plugin::Snowplow
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/itly/plugin/snowplow/snowplow.rb', line 20 def initialize(vendor:, options:) super() @vendor = vendor @disabled = .disabled emitter = SnowplowTracker::Emitter.new \ endpoint: .endpoint, options: { protocol: .protocol, method: .method, buffer_size: .buffer_size } @client = SnowplowTracker::Tracker.new emitters: emitter end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
12 13 14 |
# File 'lib/itly/plugin/snowplow/snowplow.rb', line 12 def client @client end |
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
12 13 14 |
# File 'lib/itly/plugin/snowplow/snowplow.rb', line 12 def disabled @disabled end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/itly/plugin/snowplow/snowplow.rb', line 12 def logger @logger end |
#vendor ⇒ Object (readonly)
Returns the value of attribute vendor.
12 13 14 |
# File 'lib/itly/plugin/snowplow/snowplow.rb', line 12 def vendor @vendor end |
Instance Method Details
#id ⇒ String
Get the plugin ID
145 146 147 |
# File 'lib/itly/plugin/snowplow/snowplow.rb', line 145 def id 'snowplow' end |
#identify(user_id:, properties: nil, options: nil) ⇒ Object
Identify a user
Raise an error if the client fails
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/itly/plugin/snowplow/snowplow.rb', line 57 def identify(user_id:, properties: nil, options: nil) super return unless enabled? # Log log = Itly::Loggers.vars_to_log user_id: user_id, options: logger&.info "#{id}: identify(#{log})" # Send through the client client.set_user_id user_id end |
#load(options:) ⇒ Object
Initialize Snowplow plugin
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/itly/plugin/snowplow/snowplow.rb', line 37 def load(options:) super # Get options @logger = .logger # Log logger&.info "#{id}: load()" logger&.info "#{id}: plugin is disabled!" if @disabled end |
#name ⇒ Object
Snowplow specific plugin options class for calls to plugin methods
54 55 56 57 58 59 60 61 |
# File 'lib/itly/plugin/snowplow/call_options.rb', line 54 %w[Identify Group Alias].each do |name| class_eval( <<-EVAL, __FILE__, __LINE__ + 1 class #{name}Options < CallOptions # class IdentifyOptions < CallOptions end # end EVAL ) end |
#page(user_id:, category: nil, name: nil, properties: nil, options: nil) ⇒ Object
Record page views
Raise an error if the client fails
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/itly/plugin/snowplow/snowplow.rb', line 80 def page(user_id:, category: nil, name: nil, properties: nil, options: nil) super return unless enabled? # Log log = Itly::Loggers.vars_to_log( user_id: user_id, category: category, name: name, properties: properties, options: ) logger&.info "#{id}: page(#{log})" # Identify the user client.set_user_id user_id # Send through the client contexts = nil if &.contexts.is_a?(Array) && .contexts.any? contexts = .contexts.collect(&:to_self_describing_json) end client.track_screen_view name: name, context: contexts end |
#track(user_id:, event:, options: nil) ⇒ Object
Track an event
Raise an error if the client fails
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/itly/plugin/snowplow/snowplow.rb', line 111 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, version: event&.version, properties: event&.properties, options: ) logger&.info "#{id}: track(#{log})" # Identify the user client.set_user_id user_id # Send through the client schema_version = event.version&.gsub(/\./, '-') schema = "iglu:#{vendor}/#{event.name}/jsonschema/#{schema_version}" event_json = SnowplowTracker::SelfDescribingJson.new( schema, event.properties ) contexts = nil if &.contexts.is_a?(Array) && .contexts.any? contexts = .contexts.collect(&:to_self_describing_json) end client.track_self_describing_event event_json: event_json, context: contexts end |