Exemplo n.º 1
0
    def submit_tracking(self, account, request, response, custom_params={}):
        try:
            title = BeautifulSoup(
                response.content, "html.parser"
            ).html.head.title.text.encode('utf-8')
        except:
            title = None

        path = request.get_full_path()
        custom_params['cd10'] = get_language_from_request(request)
        referer = request.META.get('HTTP_REFERER', '')
        if hasattr(request, 'user') and hasattr(request.user, 'profile')\
                and request.user.profile.uuid:
            uuid = request.user.profile.uuid
            params = build_ga_params(
                request, account, path=path,
                referer=referer, title=title,
                user_id=uuid, custom_params=custom_params)
        else:
            params = build_ga_params(
                request, account, path=path, referer=referer,
                title=title, custom_params=custom_params)

        # send user unique id after cookie's been set
        response = set_cookie(params, response)

        send_ga_tracking.delay(params)
        return response
Exemplo n.º 2
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

        # get the account id
        try:
            account = settings.GOOGLE_ANALYTICS['google_analytics_id']
        except (KeyError, TypeError):
            raise Exception("No Google Analytics ID configured")

        try:
            title = BeautifulSoup(
                response.content, "html.parser").html.head.title.text
        except AttributeError:
            title = None

        path = request.path
        referer = request.META.get('HTTP_REFERER', '')
        params = build_ga_params(
            request, account, path=path, referer=referer, title=title)
        response = set_cookie(params, response)
        send_ga_tracking.delay(params)
        return response
Exemplo n.º 3
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

        # get the account id
        try:
            account = settings.GOOGLE_ANALYTICS['google_analytics_id']
        except:
            raise Exception("No Google Analytics ID configured")

        try:
            title = BeautifulSoup(
                response.content, "html.parser").html.head.title.text
        except:
            title = None

        path = request.path
        referer = request.META.get('HTTP_REFERER', '')
        params = build_ga_params(
            request, account, path=path, referer=referer, title=title)
        response = set_cookie(params, response)
        send_ga_tracking.delay(params)
        return response
Exemplo n.º 4
0
    def submit_tracking(self, account, request, response, custom_params={}):
        try:
            title = BeautifulSoup(
                response.content, "html.parser"
            ).html.head.title.text.encode('utf-8')
        except:
            title = None

        path = request.get_full_path()
        referer = request.META.get('HTTP_REFERER', '')
        params = build_ga_params(
            request, account, path=path, referer=referer, title=title)
        response = set_cookie(params, response)

        # send user unique id after cookie's been set
        if hasattr(request, 'user') and hasattr(request.user, 'profile')\
                and request.user.profile.uuid:
            uuid = request.user.profile.uuid
            params = build_ga_params(
                request, account, path=path,
                referer=referer, title=title,
                user_id=uuid, custom_params=custom_params)

        send_ga_tracking.delay(params)
        return response
Exemplo n.º 5
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
Exemplo n.º 6
0
    def submit_tracking(self, account, request, response):
        try:
            title = BeautifulSoup(
                response.content,
                "html.parser").html.head.title.text.encode('utf-8')
        except Exception:
            title = None

        path = request.get_full_path()
        referer = request.META.get('HTTP_REFERER', '')
        params = build_ga_params(request,
                                 account,
                                 path=path,
                                 referer=referer,
                                 title=title)
        response = set_cookie(params, response)

        def calculate_age(dob):
            today = get_today()
            return (today.year - dob.year - ((today.month, today.day) <
                                             (dob.month, dob.day)))

        # send user unique id and details after cookie's been set
        if hasattr(request, 'user') and hasattr(request.user, 'profile'):
            profile = request.user.profile

            custom_params = {}
            if profile.gender:
                gender_key = settings.GOOGLE_ANALYTICS_GENDER_KEY
                custom_params[gender_key] = profile.gender
            if profile.date_of_birth:
                age_key = settings.GOOGLE_ANALYTICS_AGE_KEY
                custom_params[age_key] = calculate_age(profile.date_of_birth)

            params = build_ga_params(request,
                                     account,
                                     path=path,
                                     referer=referer,
                                     title=title,
                                     custom_params=custom_params)

        send_ga_tracking.delay(params)
        return response