Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.