Created
May 26, 2020 06:27
-
-
Save jlntrt/badab4fa941ac40c8a6badc73b363bf9 to your computer and use it in GitHub Desktop.
Server Side Tracking with Matomo and Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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