Merge pull request #32 from gleb-rudenko/tracking_interface

#22 / no interface needed, function _post_analytics modified
This commit is contained in:
Sergey 2017-05-04 13:14:53 +03:00 committed by GitHub
commit 7c805cd7b2
2 changed files with 15 additions and 3 deletions

View File

@ -21,6 +21,11 @@ Features
* Adds Google Analytics Event Tracking to some API calls so that usage of the * Adds Google Analytics Event Tracking to some API calls so that usage of the
API can be reported on via Google Analytics. 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, * Adds Google Analytics Event Tracking to group links on the home page,
user profile links, editing and saving user profiles, etc. user profile links, editing and saving user profiles, etc.

View File

@ -24,7 +24,8 @@ log = logging.getLogger('ckanext.googleanalytics')
def _post_analytics( 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'): if config.get('googleanalytics.id'):
data_dict = { data_dict = {
"v": 1, "v": 1,
@ -35,7 +36,7 @@ def _post_analytics(
"dh": c.environ['HTTP_HOST'], "dh": c.environ['HTTP_HOST'],
"dp": c.environ['PATH_INFO'], "dp": c.environ['PATH_INFO'],
"dr": c.environ.get('HTTP_REFERER', ''), "dr": c.environ.get('HTTP_REFERER', ''),
"ec": "CKAN Resource Download Request", "ec": event_type,
"ea": request_obj_type + request_function, "ea": request_obj_type + request_function,
"el": request_id, "el": request_id,
} }
@ -45,7 +46,13 @@ def _post_analytics(
def post_analytics_decorator(func): def post_analytics_decorator(func):
def func_wrapper(cls, id, resource_id, filename): 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) return func(cls, id, resource_id, filename)