From e49e8bbac768ed68470146b37c051b45e6e03358 Mon Sep 17 00:00:00 2001 From: Gleb Date: Mon, 27 Mar 2017 15:43:39 +0300 Subject: [PATCH] #22 / no interface needed, function _post_analytics modified --- README.rst | 5 +++++ ckanext/googleanalytics/plugin.py | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index d7bc1d4..ccb0b18 100644 --- a/README.rst +++ b/README.rst @@ -21,6 +21,11 @@ Features * Adds Google Analytics Event Tracking to some API calls so that usage of the API can be reported on via Google Analytics. +* Add Google Analytics Event Tracking function that can be used in any exstension + to create your custom events tracking. + + ``ckanext.googleanalytics.plugin._post_analytics`` + * Adds Google Analytics Event Tracking to group links on the home page, user profile links, editing and saving user profiles, etc. diff --git a/ckanext/googleanalytics/plugin.py b/ckanext/googleanalytics/plugin.py index 82e7e1e..498a479 100644 --- a/ckanext/googleanalytics/plugin.py +++ b/ckanext/googleanalytics/plugin.py @@ -24,7 +24,8 @@ log = logging.getLogger('ckanext.googleanalytics') def _post_analytics( - user, request_obj_type, request_function, request_id): + user, event_type, request_obj_type, request_function, request_id): + if config.get('googleanalytics.id'): data_dict = { "v": 1, @@ -35,7 +36,7 @@ def _post_analytics( "dh": c.environ['HTTP_HOST'], "dp": c.environ['PATH_INFO'], "dr": c.environ.get('HTTP_REFERER', ''), - "ec": "CKAN Resource Download Request", + "ec": event_type, "ea": request_obj_type + request_function, "el": request_id, } @@ -45,7 +46,13 @@ def _post_analytics( def post_analytics_decorator(func): def func_wrapper(cls, id, resource_id, filename): - _post_analytics(c.user, "Resource", "Download", resource_id) + _post_analytics( + c.user, + "CKAN Resource Download Request", + "Resource", + "Download", + resource_id + ) return func(cls, id, resource_id, filename)