From 738b234645ec5aa0b7d223559b3a8cce06e15de5 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Wed, 28 Nov 2018 20:00:27 -0800 Subject: [PATCH 1/2] By default support replaying tracking requests to both piwik.php and matomo.php. --- import_logs.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/import_logs.py b/import_logs.py index 930bbc7..37d1bfc 100755 --- a/import_logs.py +++ b/import_logs.py @@ -691,9 +691,9 @@ def _create_parser(self): help="Replay piwik.php requests found in custom logs (only piwik.php requests expected). \nSee https://matomo.org/faq/how-to/faq_17033/" ) option_parser.add_option( - '--replay-tracking-expected-tracker-file', dest='replay_tracking_expected_tracker_file', default='piwik.php', - help="The expected suffix for tracking request paths. Only logs whose paths end with this will be imported. Defaults " - "to 'piwik.php' so only requests to the piwik.php file will be imported." + '--replay-tracking-expected-tracker-file', dest='replay_tracking_expected_tracker_file', default=None, + help="The expected suffix for tracking request paths. Only logs whose paths end with this will be imported. By default " + "requests to the piwik.php file or the matomo.php file will be imported." ) option_parser.add_option( '--output', dest='output', @@ -2522,7 +2522,7 @@ def filtered_line(line, reason): if config.options.replay_tracking: # we need a query string and we only consider requests with piwik.php - if not hit.query_string or not hit.path.lower().endswith(config.options.replay_tracking_expected_tracker_file): + if not hit.query_string or not self.is_hit_for_tracker(hit): invalid_line(line, 'no query string, or ' + hit.path.lower() + ' does not end with piwik.php') continue @@ -2552,6 +2552,17 @@ def filtered_line(line, reason): if len(hits) > 0: Recorder.add_hits(hits) + def is_hit_for_tracker(self, hit): + filesToCheck = ['piwik.php', 'matomo.php'] + if config.options.replay_tracking_expected_tracker_file: + filesToCheck = [config.options.replay_tracking_expected_tracker_file] + + lowerPath = hit.path.lower() + for file in filesToCheck: + if lowerPath.endswith(file): + return True + return False + def _add_custom_vars_from_regex_groups(self, hit, format, groups, is_page_var): for group_name, custom_var_name in groups.iteritems(): if group_name in format.get_all(): From ec1f9c2f0dcaf680a27a0ef2676c0d1ab45e1ae2 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Wed, 28 Nov 2018 22:34:12 -0800 Subject: [PATCH 2/2] Add --tracker-endpoint-path option to allow different tracker endpoints. --- import_logs.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/import_logs.py b/import_logs.py index 37d1bfc..267c182 100755 --- a/import_logs.py +++ b/import_logs.py @@ -518,6 +518,10 @@ def _create_parser(self): help="This URL will be used to send API requests (use it if your tracker URL differs from UI/API url), " "eg. http://other-example.com/matomo/ or http://analytics-api.example.net", ) + option_parser.add_option( + '--tracker-endpoint-path', dest='matomo_tracker_endpoint_path', default='/piwik.php', + help="The tracker endpoint path to use when tracking. Defaults to /piwik.php." + ) option_parser.add_option( '--dry-run', dest='dry_run', action='store_true', default=False, @@ -1454,7 +1458,7 @@ def _call(path, args, headers=None, url=None, data=None): if auth_user is not None: base64string = base64.encodestring('%s:%s' % (auth_user, auth_password)).replace('\n', '') - request.add_header("Authorization", "Basic %s" % base64string) + request.add_header("Authorization", "Basic %s" % base64string) # Use non-default SSL context if invalid certificates shall be # accepted. @@ -1953,7 +1957,7 @@ def _record_hits(self, hits): args['debug'] = '1' response = matomo.call( - '/piwik.php', args=args, + config.options.matomo_tracker_endpoint_path, args=args, expected_content=None, headers={'Content-type': 'application/json'}, data=data, @@ -2523,7 +2527,7 @@ def filtered_line(line, reason): if config.options.replay_tracking: # we need a query string and we only consider requests with piwik.php if not hit.query_string or not self.is_hit_for_tracker(hit): - invalid_line(line, 'no query string, or ' + hit.path.lower() + ' does not end with piwik.php') + invalid_line(line, 'no query string, or ' + hit.path.lower() + ' does not end with piwik.php/matomo.php') continue query_arguments = urlparse.parse_qs(hit.query_string)