8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RailsのAMPページにNREUM(NewRelic Enduser Monitoring)のコードが挿入されて困る

Posted at

タイトル通り。困りました。

AMPページと通常ページでcontrollerないしactionが別の場合

controllerにnewrelic_ignore_enduserを追加する。
railsのfilter(before_actionとか)みたいに、only,exceptでaction単位でフィルタリングできる。

articles_ontroller.rb
class ArticleController < ApplicationController
	newrelic_ignore_enduser only: [:amp_page]
		
	def amp_page
	end
end
	

AMPページと通常ページのactionが同一の場合

formatがampの場合、actionの中でNewRelic::Agent.ignore_enduserを呼ぶ。
respond_toとで呼ぶと便利。

articles_ontroller.rb
class ArticleController < ApplicationController
	def show
		respond_to do |format|
			format.html
			format.amp { NewRelic::Agent.ignore_enduser }
		end
	end
end
8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?