Example #1
0
    def process_response(self, request, response):
        if hasattr(settings, 'GOOGLE_ANALYTICS_IGNORE_PATH'):
            exclude = [p for p in settings.GOOGLE_ANALYTICS_IGNORE_PATH\
                        if request.path.startswith(p)]
            if any(exclude):
                return response

        path = request.path
        referer = request.META.get('HTTP_REFERER', '')
        params = build_ga_params(request, path=path, referer=referer)
        response = set_cookie(params, response)
        send_ga_tracking.delay(params)
        return response
def google_analytics(request):
    """Image that sends data to Google Analytics."""

    response = HttpResponse('', 'image/gif', 200)
    response.write(GIF_DATA)

    if hasattr(settings, 'GOOGLE_ANALYTICS_IGNORE_PATH'):
        exclude = [p for p in settings.GOOGLE_ANALYTICS_IGNORE_PATH\
                    if request.path.startswith(p)]
        if any(exclude):
            return response

    event = request.GET.get('event', None)
    if event:
        event = event.split(',')
    path = request.path
    referer = request.META.get('HTTP_REFERER', '')
    params = build_ga_params(request, path, event, referer)
    send_ga_tracking.delay(params)

    set_cookie(params, response)
    return response