Class: Rack::GoogleAnalytics

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#appObject

Returns the value of attribute app

Returns:

  • (Object)

    the current value of app



2
3
4
# File 'lib/rack/google_analytics.rb', line 2

def app
  @app
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



2
3
4
# File 'lib/rack/google_analytics.rb', line 2

def options
  @options
end

Instance Method Details

#call(env) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rack/google_analytics.rb', line 4

def call(env)
  status, headers, response = app.call(env)

  if headers["Content-Type"] =~ /text\/html|application\/xhtml\+xml/
    body = ""
    response.each { |part| body << part }
    index = body.rindex("</body>")
    if index
      body.insert(index, tracking_code(options[:web_property_id]))
      headers["Content-Length"] = body.length.to_s
      response = [body]
    end
  end

  [status, headers, response]
end