Class: Rack::Tracker::GoogleAnalytics::Send

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/rack/tracker/google_analytics/google_analytics.rb

Instance Method Summary collapse

Methods inherited from OpenStruct

#to_h

Constructor Details

#initialize(attrs = {}) ⇒ Send

Returns a new instance of Send.



6
7
8
9
# File 'lib/rack/tracker/google_analytics/google_analytics.rb', line 6

def initialize(attrs = {})
  attrs.reverse_merge!(type: 'event')
  super
end

Instance Method Details

#attributesObject



19
20
21
# File 'lib/rack/tracker/google_analytics/google_analytics.rb', line 19

def attributes
  Hash[to_h.slice(:category, :action, :label, :value).map { |k,v| [self.type.to_s + k.to_s.capitalize, v] }]
end

#eventObject



15
16
17
# File 'lib/rack/tracker/google_analytics/google_analytics.rb', line 15

def event
  { hitType: self.type }.merge(attributes.stringify_values).compact
end

#writeObject



11
12
13
# File 'lib/rack/tracker/google_analytics/google_analytics.rb', line 11

def write
  ['send', event].to_json.gsub(/\[|\]/, '')
end