Skip to content

Commit

Permalink
add org id to ga event category
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewelwell committed May 10, 2019
1 parent 27da6f6 commit 64a3b56
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/analytics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@
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)
t.daemon = True
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
Expand All @@ -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 + \
Expand Down
6 changes: 4 additions & 2 deletions src/features/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 64a3b56

Please sign in to comment.