Class: Raygun::Middleware::JavascriptExceptionTracking
- Inherits:
-
Object
- Object
- Raygun::Middleware::JavascriptExceptionTracking
- Defined in:
- lib/raygun/middleware/javascript_exception_tracking.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ JavascriptExceptionTracking
constructor
A new instance of JavascriptExceptionTracking.
- #inject_javascript_to_response(response) ⇒ Object
Constructor Details
#initialize(app) ⇒ JavascriptExceptionTracking
Returns a new instance of JavascriptExceptionTracking.
3 4 5 |
# File 'lib/raygun/middleware/javascript_exception_tracking.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/raygun/middleware/javascript_exception_tracking.rb', line 7 def call(env) status, headers, response = @app.call(env) # It's a html file, inject our JS if headers['Content-Type'] && headers['Content-Type'].include?('text/html') response = inject_javascript_to_response(response) end [status, headers, response] end |
#inject_javascript_to_response(response) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/raygun/middleware/javascript_exception_tracking.rb', line 18 def inject_javascript_to_response(response) if Raygun.configuration.js_api_key.present? if response.respond_to?('[]') response[0].gsub!('</head>', "#{js_tracker.head_html}</head>") response[0].gsub!('</body>', "#{js_tracker.body_html}</body>") end if response.respond_to?(:body) # Rack::BodyProxy body = response.body body.gsub!('</head>', "#{js_tracker.head_html}</head>") body.gsub!('</body>', "#{js_tracker.body_html}</body>") end end response end |