Cannot find condition::perUser::ga:sessions>10 among the available type
I have the following code:
profile = ga.authenticate(**credentials)
report = profile.core.query.segment('condition::perUser::ga:sessions>10').metrics('users').range('2015-01-01', '2015-01-31', precision='HIGHER_PRECISION').get()
However, it throws KeyError:
Traceback (most recent call last):
File "/Users/ged/dev/py-ga/foobar.py", line 47, in <module>
report = profile.core.query.segment('condition::perUser::ga:sessions>10').metrics('users').range('2015-01-01', '2015-01-31', precision='HIGHER_PRECISION').get()
File "/Users/ged/dev/py-ga/googleanalytics/utils/functional.py", line 52, in wrapped_method
method(obj, *vargs, **kwargs)
File "/Users/ged/dev/py-ga/googleanalytics/query.py", line 893, in segment
value = [self.api.segments.serialize(value)]
File "/Users/ged/dev/py-ga/googleanalytics/utils/functional.py", line 38, in vectorized_method
results = [fn(self, value, *vargs, **kwargs) for value in values]
File "/Users/ged/dev/py-ga/googleanalytics/columns.py", line 249, in serialize
value = self.normalize(value)
File "/Users/ged/dev/py-ga/googleanalytics/utils/functional.py", line 38, in vectorized_method
results = [fn(self, value, *vargs, **kwargs) for value in values]
File "/Users/ged/dev/py-ga/googleanalytics/columns.py", line 234, in normalize
return self[value]
File "build/bdist.macosx-10.10-x86_64/egg/addressable/__init__.py", line 127, in __getitem__
KeyError: 'Cannot find condition::perUser::ga:sessions>10 among the available type.'
Process finished with exit code 1
I tried running profile.core.query.segment('condition::perUser::ga:sessions>10', type='users') as specified in the docs here https://github.com/debrouwere/google-analytics/blob/master/googleanalytics/query.py#L831 however, then I get
File "/Users/ged/dev/py-ga/googleanalytics/query.py", line 891, in segment
raise ValueError("Cannot specify a filter string and a filter keyword selection at the same time.")
ValueError: Cannot specify a filter string and a filter keyword selection at the same time.
Any idea what am I doing wrong? I don't do bug reports often, so please let me know if I missed something in here :)
Hmm, that particular docstring is a bit out of date. Thanks for reporting, I will improve the documentation.
To fix your particular query, try
profile.core.query.users(sessions__gt=10, metric_scope='users')
which is a shortcut for
profile.core.query.segment(sessions__gt=10, scope='users', metric_scope='users')
and I think probably the metric_scope argument is superfluous, users will be the default.
Tip: to see whether you're getting the query you wanted
>>> profile.core.query.users(sessions__gt=10).build()
{'metrics': '', 'segment': 'users::condition::perUser::ga:sessions>10', 'dimensions': None, 'ids': '...'}
>>> profile.core.query.users(sessions__gt=10).build()
{'metrics': '', 'segment': 'users::condition::ga:sessions>10', 'dimensions': None, 'ids': '...'}