Revert "Added custom dimensions"
This commit is contained in:
parent
1f096549d2
commit
59cff2f0b1
12
README.rst
12
README.rst
|
@ -186,18 +186,6 @@ giving permission in the browser::
|
|||
$ 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
|
||||
-------
|
||||
|
|
|
@ -16,10 +16,6 @@ from paste.util.multidict import MultiDict
|
|||
|
||||
from ckan.controllers.api import ApiController
|
||||
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')
|
||||
|
||||
|
@ -125,10 +121,8 @@ class GAApiController(ApiController):
|
|||
class GAResourceController(PackageController):
|
||||
# intercept API calls to record via google analytics
|
||||
def _post_analytics(
|
||||
self, user, request_obj_type, request_function, request_id,
|
||||
package_id=None):
|
||||
self, user, request_obj_type, request_function, request_id):
|
||||
if config.get('googleanalytics.id'):
|
||||
|
||||
data_dict = {
|
||||
"v": 1,
|
||||
"tid": config.get('googleanalytics.id'),
|
||||
|
@ -142,23 +136,9 @@ class GAResourceController(PackageController):
|
|||
"ea": request_obj_type+request_function,
|
||||
"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)
|
||||
|
||||
def resource_download(self, id, resource_id, filename=None):
|
||||
self._post_analytics(c.user, "Resource", "Download", resource_id, id)
|
||||
|
||||
if is_using_cloudstorage:
|
||||
use_controller = StorageController
|
||||
use_class = StorageController()
|
||||
else:
|
||||
use_controller = PackageController
|
||||
use_class = PackageController()
|
||||
|
||||
return use_controller.resource_download(use_class,id, resource_id,
|
||||
self._post_analytics(c.user, "Resource", "Download", resource_id)
|
||||
return PackageController.resource_download(self, id, resource_id,
|
||||
filename)
|
||||
|
|
|
@ -9,9 +9,6 @@ import ckan.lib.helpers as h
|
|||
import ckan.plugins as p
|
||||
import gasnippet
|
||||
from routes.mapper import SubMapper, Mapper as _Mapper
|
||||
from operator import attrgetter
|
||||
from ckan.common import c
|
||||
import ckan.model as model
|
||||
|
||||
import urllib2
|
||||
|
||||
|
@ -108,17 +105,6 @@ class GoogleAnalyticsPlugin(p.SingletonPlugin):
|
|||
else:
|
||||
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):
|
||||
'''Add new routes that this extension's controllers handle.
|
||||
|
||||
|
@ -273,29 +259,7 @@ class GoogleAnalyticsPlugin(p.SingletonPlugin):
|
|||
See ITemplateHelpers.
|
||||
|
||||
'''
|
||||
return {
|
||||
'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
|
||||
return {'googleanalytics_header': self.googleanalytics_header}
|
||||
|
||||
def googleanalytics_header(self):
|
||||
'''Render the googleanalytics_header snippet for CKAN 2.0 templates.
|
||||
|
|
|
@ -6,9 +6,5 @@
|
|||
|
||||
ga('create', '{{googleanalytics_id}}', '{{googleanalytics_domain}}');
|
||||
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');
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue