From f4cbb66b2bc52635b0bbf8705761cd68e3f45953 Mon Sep 17 00:00:00 2001 From: Steve Eardley Date: Wed, 22 Nov 2023 16:54:48 +0000 Subject: [PATCH] Generalise the analytics config keys --- docs/featuremap/terminals.csv | 1 + portality/app.py | 3 +- portality/settings.py | 57 +++++++++++++++++------------------ portality/view/api_v1.py | 34 ++++++++++----------- portality/view/api_v2.py | 34 ++++++++++----------- portality/view/api_v3.py | 36 +++++++++++----------- portality/view/atom.py | 4 +-- portality/view/doaj.py | 12 ++++---- portality/view/oaipmh.py | 4 +-- portality/view/openurl.py | 2 +- 10 files changed, 94 insertions(+), 93 deletions(-) diff --git a/docs/featuremap/terminals.csv b/docs/featuremap/terminals.csv index adce58d86a..fdf69406d4 100644 --- a/docs/featuremap/terminals.csv +++ b/docs/featuremap/terminals.csv @@ -25,6 +25,7 @@ LCC:SourceData OpenURL:Fragment Plagiarism:FieldSet PlagiarismDetection:FormField +PlausibleAnalytics:ExternalService Privacy:Fragment Promo:Data PublisherSupporters:Data diff --git a/portality/app.py b/portality/app.py index d7947132dc..1562f379ef 100644 --- a/portality/app.py +++ b/portality/app.py @@ -108,7 +108,8 @@ def custom_static(path): return send_from_directory(os.path.dirname(target), os.path.basename(target)) abort(404) - +# Configure Analytics +# ~~-> PlausibleAnalytics:ExternalService~~ from portality.lib import plausible plausible.create_logfile(app.config.get('PLAUSIBLE_LOG_DIR', None)) diff --git a/portality/settings.py b/portality/settings.py index 9596195c15..d537c27f98 100644 --- a/portality/settings.py +++ b/portality/settings.py @@ -1218,43 +1218,51 @@ ###################################################### -# Google Analytics configuration -# specify in environment .cfg file - avoids sending live analytics -# events from test and dev environments -# ~~->GoogleAnalytics:ExternalService~~ - -# Plausible custom dimensions. These are configured in the GA interface. # legacy -PLAUSIBLE_DIMENSIONS = { - 'oai_res_id': 'dimension1', # In GA as OAI:Record +# Analytics configuration +# specify in environment .cfg file - avoids sending live analytics events from test and dev environments + +# ~~->PlausibleAnalytics:ExternalService~~ +# Plausible analytics +# root url of plausible +PLAUSIBLE_URL = "https://plausible.io" +PLAUSIBLE_JS_URL = PLAUSIBLE_URL + "/js/script.outbound-links.file-downloads.js" +PLAUSIBLE_API_URL = PLAUSIBLE_URL + "/api/event" +# site name / domain name that used to register in plausible +PLAUSIBLE_SITE_NAME = BASE_DOMAIN +PLAUSIBLE_LOG_DIR = None + +# Analytics custom dimensions. These are configured in the interface. #fixme: are these still configured since the move from GA? +ANALYTICS_DIMENSIONS = { + 'oai_res_id': 'dimension1', # In analytics as OAI:Record } # Plausible for OAI-PMH # ~~-> OAIPMH:Feature~~ -PLAUSIBLE_CATEGORY_OAI = 'OAI-PMH' +ANALYTICS_CATEGORY_OAI = 'OAI-PMH' # Plausible for Atom # ~~-> Atom:Feature~~ -PLAUSIBLE_CATEGORY_ATOM = 'Atom' -PLAUSIBLE_ACTION_ACTION = 'Feed request' +ANALYTICS_CATEGORY_ATOM = 'Atom' +ANALYTICS_ACTION_ACTION = 'Feed request' # Plausible for JournalCSV # ~~-> JournalCSV:Feature~~ -PLAUSIBLE_CATEGORY_JOURNALCSV = 'JournalCSV' -PLAUSIBLE_ACTION_JOURNALCSV = 'Download' +ANALYTICS_CATEGORY_JOURNALCSV = 'JournalCSV' +ANALYTICS_ACTION_JOURNALCSV = 'Download' # Plausible for OpenURL # ~~->OpenURL:Feature~~ -PLAUSIBLE_CATEGORY_OPENURL = 'OpenURL' +ANALYTICS_CATEGORY_OPENURL = 'OpenURL' # Plausible for PublicDataDump # ~~->PublicDataDump:Feature~~ -PLAUSIBLE_CATEGORY_PUBLICDATADUMP = 'PublicDataDump' -PLAUSIBLE_ACTION_PUBLICDATADUMP = 'Download' +ANALYTICS_CATEGORY_PUBLICDATADUMP = 'PublicDataDump' +ANALYTICS_ACTION_PUBLICDATADUMP = 'Download' # Plausible for API # ~~-> API:Feature~~ -PLAUSIBLE_CATEGORY_API = 'API Hit' -PLAUSIBLE_ACTIONS_API = { +ANALYTICS_CATEGORY_API = 'API Hit' +ANALYTICS_ACTIONS_API = { 'search_applications': 'Search applications', 'search_journals': 'Search journals', 'search_articles': 'Search articles', @@ -1276,8 +1284,8 @@ # Plausible for fixed query widget # ~~->FixedQueryWidget:Feature~~ -PLAUSIBLE_CATEGORY_FQW = 'FQW' -PLAUSIBLE_ACTION_FQW = 'Hit' +ANALYTICS_CATEGORY_FQW = 'FQW' +ANALYTICS_ACTION_FQW = 'Hit' ##################################################### # Anonymised data export (for dev) configuration @@ -1375,15 +1383,6 @@ # Editorial Dashboard - set to-do list size TODO_LIST_SIZE = 48 -####################################################### -# Plausible analytics -# root url of plausible -PLAUSIBLE_URL = "https://plausible.io" -PLAUSIBLE_JS_URL = PLAUSIBLE_URL + "/js/script.outbound-links.file-downloads.js" -PLAUSIBLE_API_URL = PLAUSIBLE_URL + "/api/event" -# site name / domain name that used to register in plausible -PLAUSIBLE_SITE_NAME = BASE_DOMAIN -PLAUSIBLE_LOG_DIR = None ######################################################### # Background tasks --- monitor_bgjobs diff --git a/portality/view/api_v1.py b/portality/view/api_v1.py index 167e913436..d230bb0be6 100644 --- a/portality/view/api_v1.py +++ b/portality/view/api_v1.py @@ -11,8 +11,8 @@ API_VERSION_NUMBER = '1.0.0' # Google Analytics category for API events -PLAUSIBLE_CATEGORY = app.config.get('PLAUSIBLE_CATEGORY_API', 'API Hit') -PLAUSIBLE_ACTIONS = app.config.get('PLAUSIBLE_ACTIONS_API', {}) +ANALYTICS_CATEGORY = app.config.get('ANALYTICS_CATEGORY_API', 'API Hit') +ANALYTICS_ACTIONS = app.config.get('ANALYTICS_ACTIONS_API', {}) API_UNSUPPORTED_ERROR = "Version 1 is no longer supported." @@ -44,7 +44,7 @@ def search_articles(search_query): @blueprint.route("/articles", methods=["POST"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('create_article', 'Create article')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('create_article', 'Create article')) def create_article(): # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664 # return redirect(url_for('api_v3.create_article', **request.args), code=301) @@ -53,7 +53,7 @@ def create_article(): @blueprint.route("/articles/", methods=["GET"]) @api_key_optional -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('retrieve_article', 'Retrieve article'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('retrieve_article', 'Retrieve article'), record_value_of_which_arg='article_id') def retrieve_article(article_id): # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664 @@ -64,7 +64,7 @@ def retrieve_article(article_id): @blueprint.route("/articles/", methods=["PUT"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('update_article', 'Update article'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('update_article', 'Update article'), record_value_of_which_arg='article_id') def update_article(article_id): # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664 @@ -75,7 +75,7 @@ def update_article(article_id): @blueprint.route("/articles/", methods=["DELETE"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('delete_article', 'Delete article'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('delete_article', 'Delete article'), record_value_of_which_arg='article_id') def delete_article(article_id): # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664 @@ -86,7 +86,7 @@ def delete_article(article_id): @blueprint.route("/bulk/articles", methods=["POST"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('bulk_article_create', 'Bulk article create')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('bulk_article_create', 'Bulk article create')) def bulk_article_create(): # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664 # return redirect(url_for('api_v3.bulk_article_create', **request.args), code=301) @@ -96,7 +96,7 @@ def bulk_article_create(): @blueprint.route("/bulk/articles", methods=["DELETE"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('bulk_article_delete', 'Bulk article delete')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('bulk_article_delete', 'Bulk article delete')) def bulk_article_delete(): # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664 # return redirect(url_for('api_v3.bulk_article_delete', **request.args), code=301) @@ -108,7 +108,7 @@ def bulk_article_delete(): @blueprint.route('/journals/', methods=['GET']) @api_key_optional -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('retrieve_journal', 'Retrieve journal'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('retrieve_journal', 'Retrieve journal'), record_value_of_which_arg='journal_id') def retrieve_journal(journal_id): raise Api400Error(API_UNSUPPORTED_ERROR) @@ -117,7 +117,7 @@ def retrieve_journal(journal_id): @blueprint.route("/bulk/applications", methods=["POST"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('bulk_application_create', 'Bulk application create')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('bulk_application_create', 'Bulk application create')) def bulk_application_create(): raise Api400Error(API_UNSUPPORTED_ERROR) @@ -125,7 +125,7 @@ def bulk_application_create(): @blueprint.route("/bulk/applications", methods=["DELETE"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('bulk_application_delete', 'Bulk application delete')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('bulk_application_delete', 'Bulk application delete')) def bulk_application_delete(): raise Api400Error(API_UNSUPPORTED_ERROR) @@ -133,14 +133,14 @@ def bulk_application_delete(): @blueprint.route("/applications", methods=["POST"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('create_application', 'Create application')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('create_application', 'Create application')) def create_application(): raise Api400Error(API_UNSUPPORTED_ERROR) @blueprint.route("/applications/", methods=["GET"]) @api_key_required -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('retrieve_application', 'Retrieve application'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('retrieve_application', 'Retrieve application'), record_value_of_which_arg='application_id') def retrieve_application(application_id): raise Api400Error(API_UNSUPPORTED_ERROR) @@ -149,7 +149,7 @@ def retrieve_application(application_id): @blueprint.route("/applications/", methods=["PUT"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('update_application', 'Update application'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('update_application', 'Update application'), record_value_of_which_arg='application_id') def update_application(application_id): raise Api400Error(API_UNSUPPORTED_ERROR) @@ -158,7 +158,7 @@ def update_application(application_id): @blueprint.route("/applications/", methods=["DELETE"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('delete_application', 'Delete application'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('delete_application', 'Delete application'), record_value_of_which_arg='application_id') def delete_application(application_id): raise Api400Error(API_UNSUPPORTED_ERROR) @@ -166,14 +166,14 @@ def delete_application(application_id): @blueprint.route("/search/applications/") @api_key_required -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('search_applications', 'Search applications'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('search_applications', 'Search applications'), record_value_of_which_arg='search_query') def search_applications(search_query): raise Api400Error(API_UNSUPPORTED_ERROR) @blueprint.route('/search/journals/') -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('search_journals', 'Search journals'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('search_journals', 'Search journals'), record_value_of_which_arg='search_query') def search_journals(search_query): raise Api400Error(API_UNSUPPORTED_ERROR) diff --git a/portality/view/api_v2.py b/portality/view/api_v2.py index b8eb2e1b6e..873e66c65c 100644 --- a/portality/view/api_v2.py +++ b/portality/view/api_v2.py @@ -11,8 +11,8 @@ API_VERSION_NUMBER = '2.0.0' # Google Analytics category for API events -PLAUSIBLE_CATEGORY = app.config.get('PLAUSIBLE_CATEGORY_API', 'API Hit') -PLAUSIBLE_ACTIONS = app.config.get('PLAUSIBLE_ACTIONS_API', {}) +ANALYTICS_CATEGORY = app.config.get('ANALYTICS_CATEGORY_API', 'API Hit') +ANALYTICS_ACTIONS = app.config.get('ANALYTICS_ACTIONS_API', {}) API_UNSUPPORTED_ERROR = "Version 2 is no longer supported." @@ -44,7 +44,7 @@ def search_articles(search_query): @blueprint.route("/articles", methods=["POST"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('create_article', 'Create article')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('create_article', 'Create article')) def create_article(): # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664 # return redirect(url_for('api_v3.create_article', **request.args), code=301) @@ -53,7 +53,7 @@ def create_article(): @blueprint.route("/articles/", methods=["GET"]) @api_key_optional -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('retrieve_article', 'Retrieve article'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('retrieve_article', 'Retrieve article'), record_value_of_which_arg='article_id') def retrieve_article(article_id): # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664 @@ -64,7 +64,7 @@ def retrieve_article(article_id): @blueprint.route("/articles/", methods=["PUT"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('update_article', 'Update article'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('update_article', 'Update article'), record_value_of_which_arg='article_id') def update_article(article_id): # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664 @@ -75,7 +75,7 @@ def update_article(article_id): @blueprint.route("/articles/", methods=["DELETE"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('delete_article', 'Delete article'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('delete_article', 'Delete article'), record_value_of_which_arg='article_id') def delete_article(article_id): # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664 @@ -86,7 +86,7 @@ def delete_article(article_id): @blueprint.route("/bulk/articles", methods=["POST"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('bulk_article_create', 'Bulk article create')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('bulk_article_create', 'Bulk article create')) def bulk_article_create(): # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664 # return redirect(url_for('api_v3.bulk_article_create', **request.args), code=301) @@ -96,7 +96,7 @@ def bulk_article_create(): @blueprint.route("/bulk/articles", methods=["DELETE"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('bulk_article_delete', 'Bulk article delete')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('bulk_article_delete', 'Bulk article delete')) def bulk_article_delete(): # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664 # return redirect(url_for('api_v3.bulk_article_delete', **request.args), code=301) @@ -108,7 +108,7 @@ def bulk_article_delete(): @blueprint.route('/journals/', methods=['GET']) @api_key_optional -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('retrieve_journal', 'Retrieve journal'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('retrieve_journal', 'Retrieve journal'), record_value_of_which_arg='journal_id') def retrieve_journal(journal_id): # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664 @@ -119,7 +119,7 @@ def retrieve_journal(journal_id): @blueprint.route("/bulk/applications", methods=["POST"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('bulk_application_create', 'Bulk application create')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('bulk_application_create', 'Bulk application create')) def bulk_application_create(): raise Api400Error(API_UNSUPPORTED_ERROR) @@ -127,7 +127,7 @@ def bulk_application_create(): @blueprint.route("/bulk/applications", methods=["DELETE"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('bulk_application_delete', 'Bulk application delete')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('bulk_application_delete', 'Bulk application delete')) def bulk_application_delete(): raise Api400Error(API_UNSUPPORTED_ERROR) @@ -135,14 +135,14 @@ def bulk_application_delete(): @blueprint.route("/applications", methods=["POST"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('create_application', 'Create application')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('create_application', 'Create application')) def create_application(): raise Api400Error(API_UNSUPPORTED_ERROR) @blueprint.route("/applications/", methods=["GET"]) @api_key_required -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('retrieve_application', 'Retrieve application'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('retrieve_application', 'Retrieve application'), record_value_of_which_arg='application_id') def retrieve_application(application_id): raise Api400Error(API_UNSUPPORTED_ERROR) @@ -151,7 +151,7 @@ def retrieve_application(application_id): @blueprint.route("/applications/", methods=["PUT"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('update_application', 'Update application'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('update_application', 'Update application'), record_value_of_which_arg='application_id') def update_application(application_id): raise Api400Error(API_UNSUPPORTED_ERROR) @@ -160,7 +160,7 @@ def update_application(application_id): @blueprint.route("/applications/", methods=["DELETE"]) @api_key_required @write_required(api=True) -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('delete_application', 'Delete application'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('delete_application', 'Delete application'), record_value_of_which_arg='application_id') def delete_application(application_id): raise Api400Error(API_UNSUPPORTED_ERROR) @@ -168,7 +168,7 @@ def delete_application(application_id): @blueprint.route("/search/applications/") @api_key_required -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('search_applications', 'Search applications'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('search_applications', 'Search applications'), record_value_of_which_arg='search_query') def search_applications(search_query): # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664 @@ -177,7 +177,7 @@ def search_applications(search_query): @blueprint.route('/search/journals/') -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('search_journals', 'Search journals'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('search_journals', 'Search journals'), record_value_of_which_arg='search_query') def search_journals(search_query): # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664 diff --git a/portality/view/api_v3.py b/portality/view/api_v3.py index 7ab4780250..adfaa4fb15 100644 --- a/portality/view/api_v3.py +++ b/portality/view/api_v3.py @@ -18,8 +18,8 @@ API_VERSION_NUMBER = '3.0.1' # OA start added 2022-03-21 # Google Analytics category for API events -PLAUSIBLE_CATEGORY = app.config.get('PLAUSIBLE_CATEGORY_API', 'API Hit') -PLAUSIBLE_ACTIONS = app.config.get('PLAUSIBLE_ACTIONS_API', {}) +ANALYTICS_CATEGORY = app.config.get('ANALYTICS_CATEGORY_API', 'API Hit') +ANALYTICS_ACTIONS = app.config.get('ANALYTICS_ACTIONS_API', {}) @blueprint.route('/') @@ -63,7 +63,7 @@ def missing_resource(invalid_path): swag_spec=DiscoveryApi.get_application_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. @blueprint.route("/search/applications/") @api_key_required -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('search_applications', 'Search applications'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('search_applications', 'Search applications'), record_value_of_which_arg='search_query') def search_applications(search_query): # get the values for the 2 other bits of search info: the page number and the page size @@ -94,7 +94,7 @@ def search_applications(search_query): @swag(swag_summary='Search journals', swag_spec=DiscoveryApi.get_journal_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. @blueprint.route('/search/journals/') -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('search_journals', 'Search journals'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('search_journals', 'Search journals'), record_value_of_which_arg='search_query') def search_journals(search_query): # get the values for the 2 other bits of search info: the page number and the page size @@ -125,7 +125,7 @@ def search_journals(search_query): @swag(swag_summary='Search articles', swag_spec=DiscoveryApi.get_article_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. @blueprint.route('/search/articles/') -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('search_articles', 'Search articles'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('search_articles', 'Search articles'), record_value_of_which_arg='search_query') def search_articles(search_query): # get the values for the 2 other bits of search info: the page number and the page size @@ -162,7 +162,7 @@ def search_articles(search_query): @write_required(api=True) @swag(swag_summary='Create an application [Authenticated, not public]', swag_spec=ApplicationsCrudApi.create_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('create_application', 'Create application')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('create_application', 'Create application')) def create_application(): # get the data from the request try: @@ -181,7 +181,7 @@ def create_application(): @api_key_required @swag(swag_summary='Retrieve an application [Authenticated, not public]', swag_spec=ApplicationsCrudApi.retrieve_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('retrieve_application', 'Retrieve application'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('retrieve_application', 'Retrieve application'), record_value_of_which_arg='application_id') def retrieve_application(application_id): a = ApplicationsCrudApi.retrieve(application_id, current_user) @@ -193,7 +193,7 @@ def retrieve_application(application_id): @write_required(api=True) @swag(swag_summary='Update an application [Authenticated, not public]', swag_spec=ApplicationsCrudApi.update_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('update_application', 'Update application'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('update_application', 'Update application'), record_value_of_which_arg='application_id') def update_application(application_id): # get the data from the request @@ -214,7 +214,7 @@ def update_application(application_id): @write_required(api=True) @swag(swag_summary='Delete an application [Authenticated, not public]', swag_spec=ApplicationsCrudApi.delete_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('delete_application', 'Delete application'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('delete_application', 'Delete application'), record_value_of_which_arg='application_id') def delete_application(application_id): ApplicationsCrudApi.delete(application_id, current_user._get_current_object()) @@ -229,7 +229,7 @@ def delete_application(application_id): @write_required(api=True) @swag(swag_summary='Create an article [Authenticated, not public]', swag_spec=ArticlesCrudApi.create_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('create_article', 'Create article')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('create_article', 'Create article')) def create_article(): # get the data from the request try: @@ -248,7 +248,7 @@ def create_article(): @api_key_optional @swag(swag_summary='Retrieve an article', swag_spec=ArticlesCrudApi.retrieve_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('retrieve_article', 'Retrieve article'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('retrieve_article', 'Retrieve article'), record_value_of_which_arg='article_id') def retrieve_article(article_id): a = ArticlesCrudApi.retrieve(article_id, current_user) @@ -260,7 +260,7 @@ def retrieve_article(article_id): @write_required(api=True) @swag(swag_summary='Update an article [Authenticated, not public]', swag_spec=ArticlesCrudApi.update_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('update_article', 'Update article'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('update_article', 'Update article'), record_value_of_which_arg='article_id') def update_article(article_id): # get the data from the request @@ -281,7 +281,7 @@ def update_article(article_id): @write_required(api=True) @swag(swag_summary='Delete an article [Authenticated, not public]', swag_spec=ArticlesCrudApi.delete_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('delete_article', 'Delete article'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('delete_article', 'Delete article'), record_value_of_which_arg='article_id') def delete_article(article_id): ArticlesCrudApi.delete(article_id, current_user) @@ -295,7 +295,7 @@ def delete_article(article_id): @api_key_optional @swag(swag_summary='Retrieve a journal by ID', swag_spec=JournalsCrudApi.retrieve_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('retrieve_journal', 'Retrieve journal'), +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('retrieve_journal', 'Retrieve journal'), record_value_of_which_arg='journal_id') def retrieve_journal(journal_id): return jsonify_data_object(JournalsCrudApi.retrieve(journal_id, current_user)) @@ -309,7 +309,7 @@ def retrieve_journal(journal_id): @write_required(api=True) @swag(swag_summary='Create applications in bulk [Authenticated, not public]', swag_spec=ApplicationsBulkApi.create_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('bulk_application_create', 'Bulk application create')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('bulk_application_create', 'Bulk application create')) def bulk_application_create(): # get the data from the request try: @@ -334,7 +334,7 @@ def bulk_application_create(): @write_required(api=True) @swag(swag_summary='Delete applications in bulk [Authenticated, not public]', swag_spec=ApplicationsBulkApi.delete_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('bulk_application_delete', 'Bulk application delete')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('bulk_application_delete', 'Bulk application delete')) def bulk_application_delete(): # get the data from the request try: @@ -355,7 +355,7 @@ def bulk_application_delete(): @write_required(api=True) @swag(swag_summary='Bulk article creation [Authenticated, not public]', swag_spec=ArticlesBulkApi.create_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('bulk_article_create', 'Bulk article create')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('bulk_article_create', 'Bulk article create')) def bulk_article_create(): # get the data from the request try: @@ -380,7 +380,7 @@ def bulk_article_create(): @write_required(api=True) @swag(swag_summary='Bulk article delete [Authenticated, not public]', swag_spec=ArticlesBulkApi.delete_swag()) # must be applied after @api_key_(optional|required) decorators. They don't preserve func attributes. -@plausible.pa_event(PLAUSIBLE_CATEGORY, action=PLAUSIBLE_ACTIONS.get('bulk_article_delete', 'Bulk article delete')) +@plausible.pa_event(ANALYTICS_CATEGORY, action=ANALYTICS_ACTIONS.get('bulk_article_delete', 'Bulk article delete')) def bulk_article_delete(): # get the data from the request try: diff --git a/portality/view/atom.py b/portality/view/atom.py index 83c8e68765..1046b3620a 100644 --- a/portality/view/atom.py +++ b/portality/view/atom.py @@ -14,8 +14,8 @@ @blueprint.route('/feed') -@plausible.pa_event(app.config.get('PLAUSIBLE_CATEGORY_ATOM', 'Atom'), - action=app.config.get('PLAUSIBLE_ACTION_ACTION', 'Feed Request')) +@plausible.pa_event(app.config.get('ANALYTICS_CATEGORY_ATOM', 'Atom'), + action=app.config.get('ANALYTICS_ACTION_ACTION', 'Feed Request')) def feed(): # get the feed for this base_url (which is just used to set the metadata of # the feed, but we want to do this outside of a request context so it diff --git a/portality/view/doaj.py b/portality/view/doaj.py index 91f0f5f4b7..e0cfb48ef5 100644 --- a/portality/view/doaj.py +++ b/portality/view/doaj.py @@ -68,8 +68,8 @@ def news(): def fqw_hit(): page = request.form.get('embedding_page') if page is not None: - plausible.send_event(app.config.get('PLAUSIBLE_CATEGORY_FQW', 'FQW'), - action=app.config.get('PLAUSIBLE_ACTION_FQW', 'hit'), + plausible.send_event(app.config.get('ANALYTICS_CATEGORY_FQW', 'FQW'), + action=app.config.get('ANALYTICS_ACTION_FQW', 'hit'), label=request.form.get('embedding_page')) # No content response, whether data there or not. @@ -166,8 +166,8 @@ def journal_readonly(journal_id): @blueprint.route("/csv") -@plausible.pa_event(app.config.get('PLAUSIBLE_CATEGORY_JOURNALCSV', 'JournalCSV'), - action=app.config.get('PLAUSIBLE_ACTION_JOURNALCSV', 'Download')) +@plausible.pa_event(app.config.get('ANALYTICS_CATEGORY_JOURNALCSV', 'JournalCSV'), + action=app.config.get('ANALYTICS_ACTION_JOURNALCSV', 'Download')) def csv_data(): csv_info = models.Cache.get_latest_csv() if csv_info is None: @@ -192,8 +192,8 @@ def sitemap(): @blueprint.route("/public-data-dump/") @api_key_required -@plausible.pa_event(app.config.get('PLAUSIBLE_CATEGORY_PUBLICDATADUMP', 'PublicDataDump'), - action=app.config.get('PLAUSIBLE_ACTION_PUBLICDATADUMP', 'Download')) +@plausible.pa_event(app.config.get('ANALYTICS_CATEGORY_PUBLICDATADUMP', 'PublicDataDump'), + action=app.config.get('ANALYTICS_ACTION_PUBLICDATADUMP', 'Download')) def public_data_dump_redirect(record_type): if not current_user.has_role(constants.ROLE_PUBLIC_DATA_DUMP): abort(404) diff --git a/portality/view/oaipmh.py b/portality/view/oaipmh.py index 640cd325bb..17367af6c2 100644 --- a/portality/view/oaipmh.py +++ b/portality/view/oaipmh.py @@ -32,14 +32,14 @@ def oaipmh(specified=None): # Add the identifier to the event if there is one ident = request.values.get('identifier', None) if ident is not None: - event_payload[app.config.get('PLAUSIBLE_DIMENSIONS')['oai_res_id']] = ident + event_payload[app.config.get('ANALYTICS_DIMENSIONS')['oai_res_id']] = ident # work out the verb and associated parameters verb = request.values.get("verb") event_payload['action'] = verb # Now we have enough information about the request to send to analytics. - plausible.send_event(app.config.get('PLAUSIBLE_CATEGORY_OAI', 'OAI-PMH'), + plausible.send_event(app.config.get('ANALYTICS_CATEGORY_OAI', 'OAI-PMH'), **event_payload) # call the appropriate protocol operation: diff --git a/portality/view/openurl.py b/portality/view/openurl.py index 8be5a3277a..00f5a322d4 100644 --- a/portality/view/openurl.py +++ b/portality/view/openurl.py @@ -29,7 +29,7 @@ def openurl(): return redirect(parser_response, 301) # Log this request to analytics - plausible.send_event(app.config.get('PLAUSIBLE_CATEGORY_OPENURL', 'OpenURL'), + plausible.send_event(app.config.get('ANALYTICS_CATEGORY_OPENURL', 'OpenURL'), action=parser_response.genre, label=qs)