Merge pull request #24 from ckan/revert-23-master
Revert "Added custom dimensions"
This commit is contained in:
commit
e7a8219456
12
README.rst
12
README.rst
|
@ -186,18 +186,6 @@ giving permission in the browser::
|
||||||
$ paster getauthtoken --config=../ckan/development.ini
|
$ paster getauthtoken --config=../ckan/development.ini
|
||||||
|
|
||||||
|
|
||||||
Custom Dimensions
|
|
||||||
-----------------
|
|
||||||
|
|
||||||
Custom GA dimensions can be configured as below (value is a name of Package object property)::
|
|
||||||
googleanalytics.custom_dimension.{dimension} = {value}
|
|
||||||
|
|
||||||
Examples::
|
|
||||||
; set value of package_id
|
|
||||||
googleanalytics.custom_dimension.dimension1 = id
|
|
||||||
; set value of Package's description
|
|
||||||
googleanalytics.custom_dimension.dimension4 = notes
|
|
||||||
|
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
-------
|
-------
|
||||||
|
|
|
@ -16,10 +16,6 @@ from paste.util.multidict import MultiDict
|
||||||
|
|
||||||
from ckan.controllers.api import ApiController
|
from ckan.controllers.api import ApiController
|
||||||
from ckan.controllers.package import PackageController
|
from ckan.controllers.package import PackageController
|
||||||
from ckan.common import g
|
|
||||||
if 'cloudstorage' in g.plugins:
|
|
||||||
is_using_cloudstorage = True
|
|
||||||
from ckanext.cloudstorage.controller import StorageController
|
|
||||||
|
|
||||||
log = logging.getLogger('ckanext.googleanalytics')
|
log = logging.getLogger('ckanext.googleanalytics')
|
||||||
|
|
||||||
|
@ -125,10 +121,8 @@ class GAApiController(ApiController):
|
||||||
class GAResourceController(PackageController):
|
class GAResourceController(PackageController):
|
||||||
# intercept API calls to record via google analytics
|
# intercept API calls to record via google analytics
|
||||||
def _post_analytics(
|
def _post_analytics(
|
||||||
self, user, request_obj_type, request_function, request_id,
|
self, user, request_obj_type, request_function, request_id):
|
||||||
package_id=None):
|
|
||||||
if config.get('googleanalytics.id'):
|
if config.get('googleanalytics.id'):
|
||||||
|
|
||||||
data_dict = {
|
data_dict = {
|
||||||
"v": 1,
|
"v": 1,
|
||||||
"tid": config.get('googleanalytics.id'),
|
"tid": config.get('googleanalytics.id'),
|
||||||
|
@ -142,23 +136,9 @@ class GAResourceController(PackageController):
|
||||||
"ea": request_obj_type+request_function,
|
"ea": request_obj_type+request_function,
|
||||||
"el": request_id,
|
"el": request_id,
|
||||||
}
|
}
|
||||||
if package_id:
|
|
||||||
get_dimensions = config['pylons.h'].get_ga_custom_dimensions
|
|
||||||
dimensions = get_dimensions(package_id)
|
|
||||||
|
|
||||||
for (key, value) in dimensions:
|
|
||||||
data_dict[key.replace('dimension', 'cd')] = value
|
|
||||||
plugin.GoogleAnalyticsPlugin.analytics_queue.put(data_dict)
|
plugin.GoogleAnalyticsPlugin.analytics_queue.put(data_dict)
|
||||||
|
|
||||||
def resource_download(self, id, resource_id, filename=None):
|
def resource_download(self, id, resource_id, filename=None):
|
||||||
self._post_analytics(c.user, "Resource", "Download", resource_id, id)
|
self._post_analytics(c.user, "Resource", "Download", resource_id)
|
||||||
|
return PackageController.resource_download(self, id, resource_id,
|
||||||
if is_using_cloudstorage:
|
filename)
|
||||||
use_controller = StorageController
|
|
||||||
use_class = StorageController()
|
|
||||||
else:
|
|
||||||
use_controller = PackageController
|
|
||||||
use_class = PackageController()
|
|
||||||
|
|
||||||
return use_controller.resource_download(use_class,id, resource_id,
|
|
||||||
filename)
|
|
||||||
|
|
|
@ -9,9 +9,6 @@ import ckan.lib.helpers as h
|
||||||
import ckan.plugins as p
|
import ckan.plugins as p
|
||||||
import gasnippet
|
import gasnippet
|
||||||
from routes.mapper import SubMapper, Mapper as _Mapper
|
from routes.mapper import SubMapper, Mapper as _Mapper
|
||||||
from operator import attrgetter
|
|
||||||
from ckan.common import c
|
|
||||||
import ckan.model as model
|
|
||||||
|
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
|
@ -108,17 +105,6 @@ class GoogleAnalyticsPlugin(p.SingletonPlugin):
|
||||||
else:
|
else:
|
||||||
p.toolkit.add_template_directory(config, 'templates')
|
p.toolkit.add_template_directory(config, 'templates')
|
||||||
|
|
||||||
custom_dimension_prefix = 'googleanalytics.custom_dimension'
|
|
||||||
self.ga_dimensions = map(
|
|
||||||
lambda i: (i[0][len(custom_dimension_prefix) + 1:], i[1]),
|
|
||||||
filter(
|
|
||||||
lambda x: x[0].startswith(custom_dimension_prefix),
|
|
||||||
config.items()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def before_map(self, map):
|
def before_map(self, map):
|
||||||
'''Add new routes that this extension's controllers handle.
|
'''Add new routes that this extension's controllers handle.
|
||||||
|
|
||||||
|
@ -273,29 +259,7 @@ class GoogleAnalyticsPlugin(p.SingletonPlugin):
|
||||||
See ITemplateHelpers.
|
See ITemplateHelpers.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
return {
|
return {'googleanalytics_header': self.googleanalytics_header}
|
||||||
'googleanalytics_header': self.googleanalytics_header,
|
|
||||||
'get_ga_custom_dimensions': self.get_ga_custom_dimensions,
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_ga_custom_dimensions(self, pkg_id):
|
|
||||||
dimensions = []
|
|
||||||
if len(self.ga_dimensions):
|
|
||||||
getter = attrgetter(*map(lambda d: d[1], self.ga_dimensions))
|
|
||||||
package = model.Package.get(pkg_id)
|
|
||||||
if package is None:
|
|
||||||
return dimensions
|
|
||||||
try:
|
|
||||||
data = getter(package)
|
|
||||||
except Exception as e:
|
|
||||||
log.debug('Cannot obtain ga dimensions from package: {0}'.format(e))
|
|
||||||
return dimensions
|
|
||||||
|
|
||||||
if not isinstance(data, tuple):
|
|
||||||
data = (data, )
|
|
||||||
dimensions = zip(map(lambda d: d[0], self.ga_dimensions), data)
|
|
||||||
|
|
||||||
return dimensions
|
|
||||||
|
|
||||||
def googleanalytics_header(self):
|
def googleanalytics_header(self):
|
||||||
'''Render the googleanalytics_header snippet for CKAN 2.0 templates.
|
'''Render the googleanalytics_header snippet for CKAN 2.0 templates.
|
||||||
|
|
|
@ -6,9 +6,5 @@
|
||||||
|
|
||||||
ga('create', '{{googleanalytics_id}}', '{{googleanalytics_domain}}');
|
ga('create', '{{googleanalytics_id}}', '{{googleanalytics_domain}}');
|
||||||
ga('set', 'anonymizeIp', true);
|
ga('set', 'anonymizeIp', true);
|
||||||
|
|
||||||
{% for dimension in h.get_ga_custom_dimensions((c.pkg or c.pkg_dict).id or '') -%}
|
|
||||||
ga('set', '{{ dimension[0] }}', '{{ dimension[1] }}');
|
|
||||||
{% endfor -%}
|
|
||||||
ga('send', 'pageview');
|
ga('send', 'pageview');
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue