diff --git a/ckanext/googleanalytics/utils.py b/ckanext/googleanalytics/utils.py index d21ce20..8f5368b 100644 --- a/ckanext/googleanalytics/utils.py +++ b/ckanext/googleanalytics/utils.py @@ -3,8 +3,7 @@ import logging import requests from six.moves.urllib.parse import urlencode -from ckan.plugins import PluginImplementations -from ckanext.googleanalytics import config, interfaces +from ckanext.googleanalytics import config log = logging.getLogger(__name__) @@ -13,10 +12,6 @@ EVENT_API = "CKAN API Request" def send_event(data): - for p in PluginImplementations(interfaces.IGoogleAnalytics): - if p.googleanalytics_skip_event(data): - return - if isinstance(data, MeasurementProtocolData): if data["event"] != EVENT_API: log.warning("Only API event supported by Measurement Protocol at the moment") diff --git a/ckanext/googleanalytics/views.py b/ckanext/googleanalytics/views.py index 9313da9..0d49f45 100644 --- a/ckanext/googleanalytics/views.py +++ b/ckanext/googleanalytics/views.py @@ -11,7 +11,9 @@ import ckan.views.api as api import ckan.views.resource as resource from ckan.common import g -from ckanext.googleanalytics import utils, config +from ckan.plugins import PluginImplementations + +from ckanext.googleanalytics import utils, config, interfaces CONFIG_HANDLER_PATH = "googleanalytics.download_handler" @@ -90,6 +92,7 @@ def _post_analytics( from ckanext.googleanalytics.plugin import GoogleAnalyticsPlugin if config.tracking_id(): + breakpoint() if config.measurement_protocol_client_id() and event_type == utils.EVENT_API: data_dict = utils.MeasurementProtocolData({ "event": event_type, @@ -112,4 +115,9 @@ def _post_analytics( "ea": request_obj_type + request_function, "el": request_id, }) + + for p in PluginImplementations(interfaces.IGoogleAnalytics): + if p.googleanalytics_skip_event(data_dict): + return + GoogleAnalyticsPlugin.analytics_queue.put(data_dict)