Class: Rack::Tracker::GoogleAnalytics::Send
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Rack::Tracker::GoogleAnalytics::Send
- Defined in:
- lib/rack/tracker/google_analytics/google_analytics.rb
Instance Method Summary collapse
- #attributes ⇒ Object
- #event ⇒ Object
-
#initialize(attrs = {}) ⇒ Send
constructor
A new instance of Send.
- #write ⇒ Object
Methods inherited from OpenStruct
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
#attributes ⇒ Object
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 |
#event ⇒ Object
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 |
#write ⇒ Object
11 12 13 |
# File 'lib/rack/tracker/google_analytics/google_analytics.rb', line 11 def write ['send', event].to_json.gsub(/\[|\]/, '') end |