Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: option to provide a static url->title mapping for the "Page titles" report #234

Open
wants to merge 2 commits into
base: 3.x-dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions import_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,11 @@ def _create_parser(self):
"changed General.action_title_category_delimiter in your Matomo configuration, you need to set this "
"option to the same value in order to get a pretty page titles report."
)
option_parser.add_option(
'--page-titles-from', dest='page_titles_from', default=None,
help="Loads a mapping of URLs to page titles from a given file so that titles can be displayed "
"in the page titles report."
)
option_parser.add_option(
'--dump-log-regex', dest='dump_log_regex', action='store_true', default=False,
help="Prints out the regex string used to parse log lines and exists. Can be useful for using formats "
Expand Down Expand Up @@ -927,6 +932,15 @@ def _parse_args(self, option_parser):
else:
logging.debug('Accepted hostnames: all')

self.page_titles_map = {}

if self.options.page_titles_from:
for line in open(self.options.page_titles_from).readlines():
separator = line.index('=')
url = line[0:separator].strip()
title = line[separator+1:-1].strip()
self.page_titles_map[url] = title

if self.options.log_format_regex:
self.format = RegexFormat('custom', self.options.log_format_regex, self.options.log_date_format)
elif self.options.log_format_name:
Expand Down Expand Up @@ -1912,6 +1926,11 @@ def _get_hit_args(self, hit):
urllib.quote(args['urlref'], '')
) if args['urlref'] != '' else '')
)
else:
url_without_query = re.sub(r'\?.*', '', args['url'])
page_title = config.page_titles_map.get(args['url']) or config.page_titles_map.get(url_without_query)
if page_title:
args['action_name'] = page_title

if hit.generation_time_milli > 0:
args['gt_ms'] = int(hit.generation_time_milli)
Expand Down