Exemplo n.º 1
0
    def process_response(self, request, response):
        """
        Only record when we return HTML pages. Set a cookie if not set
        """

        if 'text/html' in response.get('Content-Type', ''):

            tracked_user = None

            if 'yb_user' not in request.COOKIES:

                tracked_user = generate_new_tracking_key()

                response.set_cookie('yb_user', tracked_user)

                register_event(tracking_id=tracked_user, event_name='COOKIE_SET', request=request)

                #set javascript callback behavior to check if the user has disabled cookies
                response.set_cookie('yb_verify', tracked_user)

            else:
                tracked_user = request.COOKIES[ 'yb_user' ]


            register_event(tracking_id=tracked_user, event_name='PAGE_VISITED', request=request)


        return response
Exemplo n.º 2
0
    def process_response(self, request, response):
        """
        Only record when we return HTML pages. Set a cookie if not set
        """

        if 'text/html' in response.get('Content-Type', ''):

            tracked_user = None

            if 'yb_user' not in request.COOKIES:

                tracked_user = generate_new_tracking_key()

                response.set_cookie('yb_user', tracked_user)

                register_event(tracking_id=tracked_user,
                               event_name='COOKIE_SET',
                               request=request)

                #set javascript callback behavior to check if the user has disabled cookies
                response.set_cookie('yb_verify', tracked_user)

            else:
                tracked_user = request.COOKIES['yb_user']

            register_event(tracking_id=tracked_user,
                           event_name='PAGE_VISITED',
                           request=request)

        return response
Exemplo n.º 3
0
    def process_response(self, request, response):
        """
        Only record when we return HTML pages. Set a cookie if not set
        """

        if 'text/html' in response.get('Content-Type', ''):
            content = getattr(response, 'content', '')
            if USER_TRACKING_LOG_HTML_FRAGMENT_RESPONSE or content.find("<body") >= 0:
                url_request = request.path
                urls = [reverse('user_tracking_register_event'), reverse('user_tracking_verify')]

                found = False

                for url in urls:
                    if url_request.find(url) >= 0:
                        found = True
                        break

                if not found:
                    tracking_id = None
                    event_data = {'url': request.path_info, 'method': request.method}

                    if 'user_tracking_id' not in request.COOKIES:

                        tracking_id = generate_new_tracking_key()

                        response.set_cookie('user_tracking_id', tracking_id)

                        register_event(tracking_id=tracking_id, event_name='server_middleware_set_cookie', request=request)

                        #set javascript callback behavior to check if the user has disabled cookies
                        response.set_cookie('user_tracking_verify', tracking_id)

                    else:
                        tracking_id = request.COOKIES['user_tracking_id']

                    register_event(tracking_id=tracking_id, event_name='server_middleware_page_view',event_data=event_data, request=request)

        return response
Exemplo n.º 4
0
    def post(self, request, *args, **kwargs):

        event_name = self.request.POST.get('event_name', None)
        raw_event_data = self.request.POST.get('event_data', None)

        event_data = None

        if raw_event_data is not None:
            #truncate at 1024 character to avoid malicious content
            event_data = (raw_event_data[:202400] + '..') if len(raw_event_data) > 202400 else raw_event_data
        else:
            event_data = raw_event_data

        tracking_id = self.request.COOKIES.get('user_tracking_id', None)
        if tracking_id is None:
            tracking_id = generate_new_tracking_key()

        register_event(tracking_id=tracking_id, event_name=event_name, request=self.request, event_data=event_data)
        response = HttpResponse('OK')
        response.set_cookie('user_tracking_id', tracking_id)

        return response