Esempio n. 1
0
def google_analytics_request(request, response, path=None, event=None):
    # get the account id
    account = request.GET.get('tracking_code')

    params = build_ga_params(request, account, event=event)

    set_cookie(params, response)

    utm_url = params.get('utm_url')
    user_agent = params.get('user_agent')
    language = params.get('language')

    # send the request
    resp = requests.get(
        utm_url,
        headers={
            'User-Agent': user_agent,
            'Accepts-Language': language
        }
    )
    # send debug headers if debug mode is set
    if request.GET.get('utmdebug', False):
        response['X-GA-MOBILE-URL'] = utm_url
        response['X-GA-RESPONSE'] = resp

    # return the augmented response
    return response
def google_analytics_request(request, response, path=None, event=None):
    # get the account id
    account = request.GET.get('tracking_code')

    params = build_ga_params(request, account, event=event)

    set_cookie(params, response)

    utm_url = params.get('utm_url')
    user_agent = params.get('user_agent')
    language = params.get('language')

    # send the request
    resp = requests.get(utm_url,
                        headers={
                            'User-Agent': user_agent,
                            'Accepts-Language': language
                        })
    # send debug headers if debug mode is set
    if request.GET.get('utmdebug', False):
        response['X-GA-MOBILE-URL'] = utm_url
        response['X-GA-RESPONSE'] = resp

    # return the augmented response
    return response
Esempio n. 3
0
def google_analytics_request(request, response, path=None, event=None):
    params = build_ga_params(request, event=event)

    set_cookie(params, response)

    utm_url = params.get('utm_url')
    user_agent = params.get('user_agent')
    language = params.get('language')

    # send the request
    http = httplib2.Http()
    try:
        resp, content = http.request(utm_url,
                                     'GET',
                                     headers={
                                         'User-Agent': user_agent,
                                         'Accepts-Language:': language
                                     })
        # send debug headers if debug mode is set
        if request.GET.get('utmdebug', False):
            response['X-GA-MOBILE-URL'] = utm_url
            response['X-GA-RESPONSE'] = resp

        # return the augmented response
        return response
    except httplib2.HttpLib2Error:
        raise Exception("Error opening: %s" % utm_url)
Esempio n. 4
0
def google_analytics_request(request, response, path=None, event=None):
    params = build_ga_params(request, event=event)

    set_cookie(params, response)

    utm_url = params.get('utm_url')
    user_agent = params.get('user_agent')
    language = params.get('language')

    # send the request
    http = httplib2.Http()
    try:
        resp, content = http.request(
            utm_url, 'GET',
            headers={
                'User-Agent': user_agent,
                'Accept-Language:': language
            }
        )
        # send debug headers if debug mode is set
        if request.GET.get('utmdebug', False):
            response['X-GA-MOBILE-URL'] = utm_url
            response['X-GA-RESPONSE'] = resp

        # return the augmented response
        return response
    except httplib2.HttpLib2Error:
        raise Exception("Error opening: %s" % utm_url)
Esempio n. 5
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
    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
Esempio n. 7
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
Esempio n. 8
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
Esempio n. 9
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
Esempio n. 10
0
def google_analytics_request(request, response, path=None, event=None):
    params = build_ga_params(request, event=event)

    set_cookie(params, response)

    utm_url = params.get("utm_url")
    user_agent = params.get("user_agent")
    language = params.get("language")

    # send the request
    http = httplib2.Http()
    try:
        resp, content = http.request(utm_url, "GET", headers={"User-Agent": user_agent, "Accepts-Language:": language})
        # send debug headers if debug mode is set
        if request.GET.get("utmdebug", False):
            response["X-GA-MOBILE-URL"] = utm_url
            response["X-GA-RESPONSE"] = resp

        # return the augmented response
        return response
    except httplib2.HttpLib2Error:
        raise Exception("Error opening: %s" % utm_url)
Esempio n. 11
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