def build_parameters(self): params = Parameters() params.utmac = self.tracker.account_id params.utmhn = self.tracker.domain_name params.utmt = self.get_type() params.utmn = utils.get_32bit_random_num() ''' The "utmip" parameter is only relevant if a mobile analytics ID (MO-XXXXXX-X) was given ''' params.utmip = self.visitor.ip_address params.aip = self.tracker.config.anonimize_ip_address and 1 or None # Add override User-Agent parameter (&ua) and override IP address # parameter (&uip). Note that the override IP address parameter is # always anonymized, as if &aip were present (see # https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#uip) params.ua = self.visitor.user_agent params.uip = utils.anonymize_ip(self.visitor.ip_address) if params.aip: # If anonimization of ip enabled? then! params.utmip = utils.anonymize_ip(params.utmip) params.utmhid = self.session.session_id params.utms = self.session.track_count params = self.build_visitor_parameters(params) params = self.build_custom_variable_parameters(params) params = self.build_campaign_parameters(params) params = self.build_cookie_parameters(params) return params
def build_parameters(self): params = Parameters() params.utmac = self.tracker.account_id params.utmhn = self.tracker.domain_name params.utmt = self.get_type() params.utmn = utils.get_32bit_random_num() ''' The "utmip" parameter is only relevant if a mobile analytics ID (MO-XXXXXX-X) was given ''' params.utmip = self.visitor.ip_address params.aip = self.tracker.config.anonimize_ip_address and 1 or None if params.aip: # If anonimization of ip enabled? then! params.utmip = utils.anonymize_ip(params.utmip) params.utmhid = self.session.session_id params.utms = self.session.track_count params = self.build_visitor_parameters(params) params = self.build_custom_variable_parameters(params) params = self.build_campaign_parameters(params) params = self.build_cookie_parameters(params) return params
def test_with_valid_ip(self): self.assertEqual("1.2.3.0", utils.anonymize_ip("1.2.3.4")) self.assertEqual("192.168.137.0", utils.anonymize_ip("192.168.137.123"))
def test_with_no_ip(self): self.assertEqual("", utils.anonymize_ip(""))
def test_with_valid_ip(self): self.assertEqual("1.2.3.0", utils.anonymize_ip("1.2.3.4")) self.assertEqual( "192.168.137.0", utils.anonymize_ip("192.168.137.123"))