From 7d2645a6d39a2fdd81a774e5dbad949c5b74f4b5 Mon Sep 17 00:00:00 2001 From: Gleb Date: Fri, 5 May 2017 14:00:19 +0300 Subject: [PATCH] #22 / readme file changes, tracking event function is renamed --- README.rst | 14 +++++++++++++- ckanext/googleanalytics/plugin.py | 8 ++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index ccb0b18..4356b8b 100644 --- a/README.rst +++ b/README.rst @@ -24,7 +24,19 @@ Features * Add Google Analytics Event Tracking function that can be used in any exstension to create your custom events tracking. - ``ckanext.googleanalytics.plugin._post_analytics`` + ``ckanext.googleanalytics.plugin.ga_event_tracking`` + + function arguments: + + - `user`: The user name. + + - `event_type`: Custom event type. For example "changed event". + + - `request_obj_type`: Custom request object type. For example "Resourse". + + - `request_function`: Custom request function. For example "Download". + + - `request_id`: Request id, can be dataset ID or resource ID for example. * 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 498a479..8cc50c4 100644 --- a/ckanext/googleanalytics/plugin.py +++ b/ckanext/googleanalytics/plugin.py @@ -23,14 +23,14 @@ log = logging.getLogger('ckanext.googleanalytics') -def _post_analytics( +def ga_event_tracking( user, event_type, request_obj_type, request_function, request_id): - + """The function allow to create custom event tracking.""" if config.get('googleanalytics.id'): data_dict = { "v": 1, "tid": config.get('googleanalytics.id'), - "cid": hashlib.md5(c.user).hexdigest(), + "cid": hashlib.md5(user).hexdigest(), # customer id should be obfuscated "t": "event", "dh": c.environ['HTTP_HOST'], @@ -46,7 +46,7 @@ def _post_analytics( def post_analytics_decorator(func): def func_wrapper(cls, id, resource_id, filename): - _post_analytics( + ga_event_tracking( c.user, "CKAN Resource Download Request", "Resource",