diff --git a/src/analytics/utils.py b/src/analytics/utils.py index 1804b7e7b254..b494aad309b2 100644 --- a/src/analytics/utils.py +++ b/src/analytics/utils.py @@ -11,6 +11,7 @@ GOOGLE_ANALYTICS_BATCH_URL = GOOGLE_ANALYTICS_BASE_URL + "/batch" DEFAULT_DATA = "v=1&tid=" + settings.GOOGLE_ANALYTICS_KEY + def postpone(function): def decorator(*args, **kwargs): t = Thread(target = function, args=args, kwargs=kwargs) @@ -18,10 +19,12 @@ def decorator(*args, **kwargs): t.start() return decorator + @postpone def post_async(url, data): requests.post(GOOGLE_ANALYTICS_COLLECT_URL, data=data) + def track_request(uri): """ Utility function to track a request to the API with the specified URI @@ -31,6 +34,7 @@ def track_request(uri): data = DEFAULT_DATA + "t=pageview&dp=" + quote(uri, safe='') post_async(GOOGLE_ANALYTICS_COLLECT_URL, data=data) + def track_event(category, action, label='', value=''): data = DEFAULT_DATA + "&t=event" + \ "&ec=" + category + \ diff --git a/src/features/views.py b/src/features/views.py index 0535bdf33667..aef9803eee16 100644 --- a/src/features/views.py +++ b/src/features/views.py @@ -223,15 +223,17 @@ def get(self, request, identifier=None, *args, **kwargs): return Response(error_response, status=status.HTTP_400_BAD_REQUEST) + ga_event_category = str(environment.project.organisation.id) + "-" + environment.project.organisation.name + if identifier: - track_event(environment.project.organisation.name, "identity_flags") + track_event(ga_event_category, "identity_flags") identity, _ = Identity.objects.get_or_create( identifier=identifier, environment=environment, ) else: - track_event(environment.project.organisation.name, "flags") + track_event(ga_event_category, "flags") identity = None kwargs = {