Skip to content

Instantly share code, notes, and snippets.

@jlntrt
Created May 26, 2020 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlntrt/badab4fa941ac40c8a6badc73b363bf9 to your computer and use it in GitHub Desktop.
Save jlntrt/badab4fa941ac40c8a6badc73b363bf9 to your computer and use it in GitHub Desktop.
Server Side Tracking with Matomo and Rails
require 'net/http'
require 'uri'
class ApplicationController < ActionController::Base
after_action :track_request
private
def track_request
uri = URI('https://<matomo_url>/piwik.php')
Net::HTTP.post_form(
uri,
'idsite': <matomo_site_id>,
'rec': 1,
'action_name': request.fullpath,
'url': request.url,
'_id': session.id,
'apiv': 1,
'rand': srand,
'urlref': request.referrer,
'ua': request.user_agent,
'cip': request.remote_ip,
'token_auth': <auth_token>
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment