<s> from ga import send_request_to_google_analytics , get_random_number , get_visitor_id , get_ip , VERSION , COOKIE_NAME , COOKIE_PATH , COOKIE_USER_PERSISTENCE , GIF_DATA <EOL> import httplib2 <EOL> import time <EOL> from urllib import unquote , quote <EOL> from urllib import unquote , quote <EOL> from django . http import HttpResponse <EOL> def track ( request ) : <EOL> """<STR_LIT>""" <EOL> response = HttpResponse ( ) <EOL> time_tup = time . localtime ( time . time ( ) + COOKIE_USER_PERSISTENCE ) <EOL> x_utmac = request . GET . get ( '<STR_LIT>' , None ) <EOL> domain = request . META . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> document_referer = request . GET . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if not document_referer or document_referer == "<STR_LIT:0>" : <EOL> document_referer = "<STR_LIT:->" <EOL> else : <EOL> document_referer = unquote ( document_referer ) <EOL> document_path = request . GET . get ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> if document_path : <EOL> document_path = unquote ( document_path ) <EOL> account = request . GET . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> user_agent = request . META . get ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> cookie = request . COOKIES . get ( COOKIE_NAME , None ) <EOL> visitor_id = get_visitor_id ( request . META . get ( "<STR_LIT>" , '<STR_LIT>' ) , account , user_agent , cookie ) <EOL> utm_gif_location = "<STR_LIT>" <EOL> for utmac in [ account , x_utmac ] : <EOL> if not utmac : <EOL> continue <EOL> utm_url = utm_gif_location + "<STR_LIT:?>" + "<STR_LIT>" + VERSION + "<STR_LIT>" + get_random_number ( ) + "<STR_LIT>" + quote ( domain ) + "<STR_LIT>" + request . GET . get ( '<STR_LIT>' , '<STR_LIT>' ) + "<STR_LIT>" + request . GET . get ( '<STR_LIT>' , '<STR_LIT>' ) + "<STR_LIT>" + quote ( document_referer ) + "<STR_LIT>" + quote ( document_path ) + "<STR_LIT>" + utmac + "<STR_LIT>" + "<STR_LIT>" + visitor_id + "<STR_LIT>" + get_ip ( request . META . get ( "<STR_LIT>" , '<STR_LIT>' ) ) <EOL> send_request_to_google_analytics ( utm_url , request . META ) <EOL> response . set_cookie ( COOKIE_NAME , value = visitor_id , path = COOKIE_PATH ) <EOL> if request . GET . get ( '<STR_LIT>' , False ) : <EOL> response [ '<STR_LIT>' ] = utm_url <EOL> response_headers = [ ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> for header in response_headers : <EOL> key , value = header <EOL> response [ key ] = value <EOL> response . content = GIF_DATA <EOL> return response </s>
