Module: Matomo::ViewHelpers

Defined in:
lib/matomo/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#matomo_tracking_embed(opts = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/matomo/view_helpers.rb', line 3

def matomo_tracking_embed(opts = {})
  (:div, id: "anon-stats") do
    (:noscript) do
      tag(:img, src: matomo_tracking_url(opts), style: "border:0", alt: "")
    end +
    javascript_tag do
      "document.getElementById('anon-stats').innerHTML = '<img src=\"#{matomo_tracking_url(opts)}&urlref=' + encodeURIComponent(document.referrer) + '\" style=\"border:0\" alt=\"\" />';".html_safe
    end
  end
end

#matomo_tracking_url(opts = {}) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/matomo/view_helpers.rb', line 14

def matomo_tracking_url(opts = {})
  "#{Matomo.base_url}/js/?" + {
    idsite: Matomo.site_id,
    rec: 1,
    action_name: action_name_or_default(opts[:action_name]),
    url: request.original_url
  }.compact.to_param
end