Class: AmplitudeAnalytics::AmplitudeDestinationPlugin

Inherits:
DestinationPlugin show all
Defined in:
lib/amplitude/plugin.rb

Overview

AmplitudeDestinationPlugin

Instance Attribute Summary collapse

Attributes inherited from DestinationPlugin

#timeline

Attributes inherited from Plugin

#plugin_type

Instance Method Summary collapse

Methods inherited from DestinationPlugin

#add, #remove

Methods inherited from EventPlugin

#track

Constructor Details

#initializeAmplitudeDestinationPlugin



68
69
70
71
72
73
# File 'lib/amplitude/plugin.rb', line 68

def initialize
  super
  @workers = Workers.new
  @storage = nil
  @configuration = nil
end

Instance Attribute Details

#workersObject (readonly)

Returns the value of attribute workers.



66
67
68
# File 'lib/amplitude/plugin.rb', line 66

def workers
  @workers
end

Instance Method Details

#execute(event) ⇒ Object

Raises:



88
89
90
91
92
93
# File 'lib/amplitude/plugin.rb', line 88

def execute(event)
  event = @timeline.process(event)
  raise InvalidEventError, 'Invalid event.' unless verify_event(event)

  @storage.push(event)
end

#flushObject



95
96
97
# File 'lib/amplitude/plugin.rb', line 95

def flush
  @workers.flush
end

#setup(client) ⇒ Object



75
76
77
78
79
80
# File 'lib/amplitude/plugin.rb', line 75

def setup(client)
  @configuration = client.configuration
  @storage = client.configuration.storage
  @workers.setup(client.configuration, @storage)
  @storage.setup(client.configuration, @workers)
end

#shutdownObject



99
100
101
102
# File 'lib/amplitude/plugin.rb', line 99

def shutdown
  @timeline.shutdown
  @workers.stop
end

#verify_event(event) ⇒ Object



82
83
84
85
86
# File 'lib/amplitude/plugin.rb', line 82

def verify_event(event)
  return false unless event.is_a?(BaseEvent) && event.event_type && (event.user_id || event.device_id)

  true
end