基于此处的示例:https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-py
我正在尝试在公共(public)图书馆目录中查找搜索结果信息。我可以通过填写正确的指标和维度来获得结果,但我不知道如何将“排序”集成到
def get_report(analytics):
"""Queries the Analytics Reporting API V4.
Args:
analytics: An authorized Analytics Reporting API V4 service object.
Returns:
The Analytics Reporting API V4 response.
"""
return analytics.reports().batchGet(
body={
'reportRequests': [
{
'viewId': VIEW_ID,
'dateRanges': [{'startDate': '1daysAgo', 'endDate': 'today'}],
'metrics': [{'expression': 'ga:avgSearchResultViews'}],
'dimensions': [{'name': 'ga:searchKeyword'}],
}]
}
).execute()
有谁知道如何在上面的代码块中集成排序和可能的 maxResults 限制器? Google 这里有关于排序的信息:https://developers.google.com/analytics/devguides/reporting/core/v3/reference#sort 。我尝试过在指标表达式中添加“-”,甚至为“排序”添加一个全新的行,但它还无法帮助我。
最佳答案
示例:
{
"reportRequests":[
{
...
"orderBys": [
{
"fieldName": "ga:users",
"sortOrder": "DESCENDING"
},{
"fieldName": "ga:source"
}],
}]
}
关于python - Google Analytics Reporting API v4 对结果进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47203801/