def test_by_path(): pv1_generator = pageview('/my-page/') assert list(pv1_generator) == [{'t': 'pageview', 'dp': '/my-page/'}] pv2_generator = pageview('/my-page/', host_name='example.com') assert list(pv2_generator) == [ {'t': 'pageview', 'dp': '/my-page/', 'dh': 'example.com'}]
def test_by_path(): pv1_generator = pageview('/my-page/') assert list(pv1_generator) == [{'t': 'pageview', 'dp': '/my-page/'}] pv2_generator = pageview('/my-page/', host_name='example.com') assert list(pv2_generator) == [{ 't': 'pageview', 'dp': '/my-page/', 'dh': 'example.com' }]
def get_view_payloads(path, language, headers): host_name = headers.get("HTTP_HOST", None) referrer = headers.get("HTTP_REFERER", None) return ga.pageview(path, host_name=host_name, referrer=referrer, language=language)
def test_extra_params(): generator = pageview('/my-page/', ex='extra') assert list(generator) == [{ 't': 'pageview', 'dp': '/my-page/', 'ex': 'extra' }]
def test_optional_params(): generator = pageview('/', title='title', referrer='referrer') assert list(generator) == [{ 't': 'pageview', 'dp': '/', 'dr': 'referrer', 'dt': 'title' }]
def dispatch(self, data: Dict): ''' Figures out the right handler to use for reporting and calls it with event data. Returns False if sending any request failed, otherwise True. ''' if data['handler'] == 'ga': if not self.UA: raise ValueError('missing UA') # report offset between now and when we got the event (ms) data['args']['qt'] = str(self.get_ts() - data['ts']) if data['etype'] == 'event': payload = google_measurement_protocol.event(**data['args']) elif data['etype'] == 'pageview': payload = google_measurement_protocol.pageview(**data['args']) else: raise ValueError('unknown etype') # GA appears to ignore its own 'ua' override. # this is silly, but is the recommended solution. user_agent = data['args'].get('ua') if user_agent: extra_headers = {'user-agent': user_agent} else: extra_headers = {} # LOG.debug('payload: {}'.format(list(payload))) # send data (res is list of requests objs) res = google_measurement_protocol.report( self.UA, data['clientid'], payload, extra_headers=extra_headers) if not res: raise ValueError('nothing to send') for req in res: req.raise_for_status() return True else: raise ValueError('unknown handler')
def test_extra_params(): generator = pageview('/my-page/', ex='extra') assert list(generator) == [ {'t': 'pageview', 'dp': '/my-page/', 'ex': 'extra'}]
def test_optional_params(): generator = pageview('/', title='title', referrer='referrer') assert list(generator) == [ {'t': 'pageview', 'dp': '/', 'dr': 'referrer', 'dt': 'title'}]
def test_by_location(): generator = pageview(location='http://example.com/my-page/') assert list(generator) == [ {'t': 'pageview', 'dl': 'http://example.com/my-page/'}]
def get_view_payloads(path, language, headers): host_name = headers.get('HTTP_HOST', None) referrer = headers.get('HTTP_REFERER', None) return ga.pageview( path, host_name=host_name, referrer=referrer, language=language)
def test_by_location(): generator = pageview(location='http://example.com/my-page/') assert list(generator) == [{ 't': 'pageview', 'dl': 'http://example.com/my-page/' }]