Skip to content

Commit

Permalink
Generalise the analytics config keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven-Eardley committed Nov 22, 2023
1 parent 7a5cad9 commit f4cbb66
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 93 deletions.
1 change: 1 addition & 0 deletions docs/featuremap/terminals.csv
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ LCC:SourceData
OpenURL:Fragment
Plagiarism:FieldSet
PlagiarismDetection:FormField
PlausibleAnalytics:ExternalService
Privacy:Fragment
Promo:Data
PublisherSupporters:Data
Expand Down
3 changes: 2 additions & 1 deletion portality/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
57 changes: 28 additions & 29 deletions portality/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
34 changes: 17 additions & 17 deletions portality/view/api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down Expand Up @@ -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)
Expand All @@ -53,7 +53,7 @@ def create_article():

@blueprint.route("/articles/<article_id>", 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
Expand All @@ -64,7 +64,7 @@ def retrieve_article(article_id):
@blueprint.route("/articles/<article_id>", 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
Expand All @@ -75,7 +75,7 @@ def update_article(article_id):
@blueprint.route("/articles/<article_id>", 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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -108,7 +108,7 @@ def bulk_article_delete():

@blueprint.route('/journals/<journal_id>', 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)
Expand All @@ -117,30 +117,30 @@ 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)


@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)


@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/<application_id>", 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)
Expand All @@ -149,7 +149,7 @@ def retrieve_application(application_id):
@blueprint.route("/applications/<application_id>", 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)
Expand All @@ -158,22 +158,22 @@ def update_application(application_id):
@blueprint.route("/applications/<application_id>", 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)


@blueprint.route("/search/applications/<path:search_query>")
@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/<path:search_query>')
@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)
Loading

0 comments on commit f4cbb66

Please sign in to comment.