Module: Skadi::ApplicationHelper
- Defined in:
- app/helpers/skadi/application_helper.rb
Defined Under Namespace
Classes: InvalidSkadiTagType
Instance Method Summary collapse
Instance Method Details
#skadi_tag(type = :inline) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/helpers/skadi/application_helper.rb', line 7 def skadi_tag(type = :inline) return if skadi.do_not_track? || skadi.view.nil? tag_attributes = { data: { uri: request.route_uri_pattern, endpoint: Skadi::Engine.routes.url_helpers.tracking_endpoint_path, view: skadi.view.token, }, nonce: content_security_policy_nonce, } tag_attributes[:data][:visit] = "1" if skadi.new_visit? case type when :route content_tag("script", "", { src: Skadi::Engine.routes.url_helpers.tracking_script_path(v: Skadi::VERSION), **tag_attributes, }) when :inline self.skadi_script_src ||= Engine.root.join("app", "assets", "builds", "skadi.js").read.html_safe content_tag( "script", skadi_script_src, tag_attributes, ) else raise InvalidSkadiTagType.new("Invalid type given to skadi_tag. Expecting :route, :inline, but got :#{type}.") end end |